Created
October 6, 2016 04:13
-
-
Save anonymous/856f2644d08995822392412eeaebf70f to your computer and use it in GitHub Desktop.
terrain generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generate a random offset | |
float offset = ((float) rand() / (100000)); | |
this->width = width; | |
this->height = height; | |
// Initilize the array | |
this->blockArray = new Block**[width]; | |
for(int i = 0; i < width; ++i) | |
{ | |
this->blockArray[i] = new Block*[height]; | |
} | |
// Now generate terrain | |
for(int x = 0; x < width; x++) | |
{ | |
float ph = SimplexNoise::noise((float)x + offset); | |
std::cout << ph << std::endl; | |
int bh = ph * height; | |
for(int y = 0; y < height; y++) | |
{ | |
if(y > bh) | |
{ | |
this->blockArray[x][y] = new Block(1); | |
}else | |
{ | |
this->blockArray[x][y] = new Block(0); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment