1234567891011121314151617181920212223242526272829303132 |
- #include "common/world/World.h"
- #include "common/world/HighMap.h"
- #include "gaming-core/utils/Random.h"
- World::World(const BlockRegistry& blockRegistry) : blockRegistry(blockRegistry), blocks(7, 7) {
- Block stone = blockRegistry.getBlock("stone");
- HighMap map(blocks.getSize(), blocks.getHeight());
- for(int x = 0; x < blocks.getSize(); x++) {
- for(int z = 0; z < blocks.getSize(); z++) {
- int height = map.getHeight(x, z);
- for(int y = 0; y < height; y++) {
- setBlock(x, y, z, stone);
- }
- }
- }
- }
- void World::setBlock(int x, int y, int z, const Block& block) {
- blocks.set(x, y, z, block.getId());
- }
- const Block& World::getBlock(int x, int y, int z) const {
- return blockRegistry.getBlock(blocks.get(x, y, z));
- }
- int World::getSize() const {
- return blocks.getSize();
- }
- int World::getHeight() const {
- return blocks.getHeight();
- }
|