1234567891011121314151617181920212223242526272829303132333435363738 |
- #include "common/world/World.h"
- #include "common/world/HighMap.h"
- #include "gaming-core/utils/Random.h"
- World::World(const BlockRegistry& blockRegistry) : blockRegistry(blockRegistry), blocks(5, 5) {
- Block air = blockRegistry.getBlock("air");
- Block stone = blockRegistry.getBlock("stone");
- Block dirt = blockRegistry.getBlock("dirt");
- HighMap<32, 32> map;
- for(int x = 0; x < 32; x++) {
- for(int z = 0; z < 32; z++) {
- int height = map.getHeight(x, z, 32);
- for(int y = 0; y < height; y++) {
- setBlock(x, y, z, stone);
- }
- setBlock(x, height - 1, z, dirt);
- for(int y = height; y < 32; y++) {
- setBlock(x, y, z, air);
- }
- }
- }
- }
- 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();
- }
|