Random Tile Generation Using Arrays
Posted: Thu May 16, 2013 9:53 pm
Is there any examples around on doing random tile generation using arrays in Game-Editor?
Game Editor discussion board
http://game-editor.com/forum/
int array[10];
for(int i=0; i<10; i++)
{
array[i] = rand(5); // fills array with random numbers 0-4
// could also create actual tile actors here, and set their animpos to array[i]
}
skydereign wrote:Do you actually mean random? If so, here is an example, though not very useful.
- Code: Select all
int array[10];
for(int i=0; i<10; i++)
{
array[i] = rand(5); // fills array with random numbers 0-4
// could also create actual tile actors here, and set their animpos to array[i]
}
//Step 1: Create array
int tilegen[100][10];
for(w=0; w<100; w++) //Initiate for loop for width
{
for(d=0; d<10; d++) //initiate for loop for depth
{
if(tilegen[w][d]>0)
{
CreateActor("Dirt_Tile", "DirtTile", "(none)", "(none)", w*32, d*32, true);
}
else
CreateActor("Stone_Tile", "StoneTile", "(none)", "(none)", w*32, d*32, true);
//finalcount++; this is a test to determine loop is run.
}
}
//sprintf(text, "%d", finalcount); This is an output loop test result.
DragonRift wrote:how am I going to loop the east/west ends of the world to "appear" to be seamless.
skydereign wrote:DragonRift wrote:how am I going to loop the east/west ends of the world to "appear" to be seamless.
You would have to create enough overlap on both sides of the level, so that they can move half a screen to the right or left of the limits. When they do, warp them to the other side of the level.
DragonRift wrote:I am likely going to have to change my entire game design because this just will not work for me.
Hblade wrote:Dragon, your going to run into massive slowdown unless you come up with a way to store the locations somehow and delete the tiles, then recreate them. Even if they're off screen and visually set to 0(disabled) this could cause atomic slowdown. 100x100 (10,000 tiles) causes massive slowdown by 30FPS (60 to 32 ish), much less infinite world But then again, 10000 tiles is a poop load of tiles. and I had air tiles so that could also have been an issue
/* Define these variables at the top before you begin
numberOfWaves - Float // Number of waves you wish to add to the terrain
Amplitudes - Float[] // Array of Amplitudes of each wave.
Frequencies - Float[] // Array of Amplitudes of each wave.
PhaseDifferences - Float[] // Array of Amplitudes of each wave.
baseHeight - float // the height of terrain to begin with before adding sine waves.
terrainHeight - Float[] // stores the height of terrain at each value of X
i = 0 // used to run through for loops, just a temp variable.
j = 0 // same as i.
blockPrefab - transform // holds the prefab of the block that will be created when generating the level.
*/
// First we start by generating a random array of amplitudes frequencies and phase differences to randomize a set number of waves.
Amplitudes = new float[numberOfWaves];
Frequencies = new float[numberOfWaves];
PhaseDifferences = new float[numberOfWaves];
for(i = 0; i<numberOfWaves; i+=1)
{
// now we set random values in set ranges. These ranges can cause really bumpy terrain if not chosen carefully.
Amplitude[i] = Random.Range(minAmplitude, maxAmplitude);
Frequencies[i] = Random.Range(minFrequency, maxFrequency);
PhaseDifferences = Random.Range(minDifference, masDifference);
// true minimum phase difference is 0, and max is 2*Mathf.PI, Due to the nature of the Sine Wave.
}
for(i=0; i<maxWidth; i+=1)
{
terrainHeight[i] = baseHeight;
// first set the base height of the terrain
for(j=0; j<numberofWaves; j+=1)
{
// Now we add on each wave height in turn.
terrainHeight[i] += Amplitude[j]*Mathf.Sin(Frequency[j] + PhaseDifference[j]);
}
for(j = terrainHeight[i]; j > 0; j-=1)
{
// Create Block, or modify terrain mesh here...
// so for creating blocks we would do:
Instantiate(blockPrefab, Vector3(i, j, 0), Quaternion.identity);
}
}
float NumberOfWaves;
float Amplitudes[];
float Frequencies[];
float PhaseDifferences[];
float BaseHeight;
float TerrainHeight[];
int i = 0;
int j = 0;
float NumberOfWaves;
float Amplitudes[];
float Frequencies[];
float PhaseDifferences[];
float BaseHeight;
float TerrainHeight[];
int i = 0;
int j = 0;
Amplitudes[NumberOfWaves];
float *NumberOfWaves;
float Amplitudes[];
float Frequencies[];
float PhaseDifferences[];
float BaseHeight;
float TerrainHeight[];t;
int i = 0;
int j = 0;
Amplitudes[NumberOfWaves];
float Amplitudes[10];
float NumberOfWaves;
float Amplitudes[0];
float Frequencies[0];
float PhaseDifferences[0];
float BaseHeight;
float TerrainHeight[0];
int i = 0;
int j = 0;
Amplitudes[NumberOfWaves];
int NumberOfWaves;
int Amplitude[0];
int Frequencies[0];
int PhaseDifferences[0];
int BaseHeight;
int TerrainHeight[0];
int i = 0;
int j = 0;
Amplitude[NumberOfWaves];
Frequencies[NumberOfWaves];
PhaseDifferences[NumberOfWaves];
for(i = 0; i<NumberOfWaves; i+=1)
{
// now we set random values in set ranges. These ranges can cause really bumpy terrain if not chosen carefully.
Amplitude[i] = random.range(minAmplitude, maxAmplitude);
Frequencies[i] = random.range(minFrequency, maxFrequency);
PhaseDifferences[i] = random.range(minDifference, masDifference);
// true minimum phase difference is 0, and max is 2*Mathf.PI, Due to the nature of the Sine Wave.
}
int NumberOfWaves;
int Amplitude[0];
int Frequencies[0];
int PhaseDifferences[0];
int BaseHeight;
int TerrainHeight[0];
int i = 0;
int j = 0;
Amplitude[NumberOfWaves];
Frequencies[NumberOfWaves];
PhaseDifferences[NumberOfWaves];
for(i = 0; i<NumberOfWaves; i+=1)
{
// now we set random values in set ranges. These ranges can cause really bumpy terrain if not chosen carefully.
Amplitude[i] = rand(10);
Frequencies[i] = rand(10);
PhaseDifferences[i] = rand(10);
// true minimum phase difference is 0, and max is 2*Mathf.PI, Due to the nature of the Sine Wave.
}
DragonRift wrote:This says incompatible Type, but if I change it to int it works. However I think I am going to have to use a floating point variable to do that code I am porting... am I not correct
const int size = 10;
int array[size];