-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorld.cpp
44 lines (41 loc) · 1018 Bytes
/
World.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "World.h"
#include <random>
World::World(int width, int height) :
_grassTerrain(1, false, 0),
_hillTerrain(3, false, 0),
_riverTerrain(2, true, 0) {
this->_width = width;
this->_height = height;
this->_tiles = new Tile**[this->_width];
for (int x = 0; x < this->_width; x++)
{
this->_tiles[x] = new Tile*[this->_height];
}
}
void World::generateTerrain()
{
// Fill the ground with grass.
for (int x = 0; x < _width; x++)
{
for (int y = 0; y < _height; y++)
{
// Sprinkle some hills.
if (rand() % 15 == 0)
{
_tiles[x][y] = &_hillTerrain;
}
else
{
_tiles[x][y] = &_grassTerrain;
}
}
}
// Lay a river.
int x = rand() % _width;
for (int y = 0; y < _height; y++) {
_tiles[x][y] = &_riverTerrain;
}
}
const Tile& World::get_tile(int x, int y) {
return *_tiles[x][y];
}