Random Tile Generation Using Arrays
 Posted: Thu May 16, 2013 9:53 pm
Posted: Thu May 16, 2013 9:53 pmIs there any examples around on doing random tile generation using arrays in Game-Editor?
			Game Editor discussion board
http://game-editor.com/forum/
 Posted: Thu May 16, 2013 9:53 pm
Posted: Thu May 16, 2013 9:53 pm Posted: Thu May 16, 2013 10:20 pm
Posted: Thu May 16, 2013 10:20 pmint 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]
} Posted: Thu May 16, 2013 11:36 pm
Posted: Thu May 16, 2013 11:36 pm Posted: Fri May 17, 2013 1:39 am
Posted: Fri May 17, 2013 1:39 amskydereign 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]
}
 Posted: Fri May 17, 2013 5:08 am
Posted: Fri May 17, 2013 5:08 am//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.
 Posted: Fri May 17, 2013 3:28 pm
Posted: Fri May 17, 2013 3:28 pm Posted: Fri May 17, 2013 6:36 pm
Posted: Fri May 17, 2013 6:36 pmDragonRift wrote:how am I going to loop the east/west ends of the world to "appear" to be seamless.
 Posted: Fri May 17, 2013 7:03 pm
Posted: Fri May 17, 2013 7:03 pmskydereign 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.
 Posted: Fri May 17, 2013 7:13 pm
Posted: Fri May 17, 2013 7:13 pmDragonRift wrote:I am likely going to have to change my entire game design because this just will not work for me.
 Posted: Fri May 17, 2013 7:23 pm
Posted: Fri May 17, 2013 7:23 pm But then again, 10000 tiles is a poop load of tiles. and I had air tiles so that could also have been an issue
 But then again, 10000 tiles is a poop load of tiles. and I had air tiles so that could also have been an issue Posted: Fri May 17, 2013 7:29 pm
Posted: Fri May 17, 2013 7:29 pmHblade 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 worldBut 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);
         }
    } Posted: Fri May 17, 2013 9:03 pm
Posted: Fri May 17, 2013 9:03 pmfloat 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]; Posted: Fri May 17, 2013 9:11 pm
Posted: Fri May 17, 2013 9:11 pmfloat Amplitudes[10]; Posted: Fri May 17, 2013 9:13 pm
Posted: Fri May 17, 2013 9:13 pmfloat 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.
    } Posted: Fri May 17, 2013 9:49 pm
Posted: Fri May 17, 2013 9:49 pmDragonRift 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];