Skip to content

Instantly share code, notes, and snippets.

Created October 6, 2016 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/856f2644d08995822392412eeaebf70f to your computer and use it in GitHub Desktop.
Save anonymous/856f2644d08995822392412eeaebf70f to your computer and use it in GitHub Desktop.
terrain generator
// 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