World.cpp 933 B

123456789101112131415161718192021222324252627282930313233
  1. #include "common/world/World.h"
  2. #include "common/world/HighMap.h"
  3. #include "gaming-core/utils/Random.h"
  4. World::World(const BlockRegistry& blockRegistry)
  5. : blockRegistry(blockRegistry), blocks(7, 7) {
  6. const Block& stone = blockRegistry.getBlock("stone");
  7. HighMap map(blocks.getSize(), blocks.getHeight());
  8. for(int x = 0; x < blocks.getSize(); x++) {
  9. for(int z = 0; z < blocks.getSize(); z++) {
  10. int height = map.getHeight(x, z);
  11. for(int y = 0; y < height; y++) {
  12. setBlock(x, y, z, stone);
  13. }
  14. }
  15. }
  16. }
  17. void World::setBlock(int x, int y, int z, const Block& block) {
  18. blocks.set(x, y, z, block.getId());
  19. }
  20. const Block& World::getBlock(int x, int y, int z) const {
  21. return blockRegistry.getBlock(blocks.get(x, y, z));
  22. }
  23. int World::getSize() const {
  24. return blocks.getSize();
  25. }
  26. int World::getHeight() const {
  27. return blocks.getHeight();
  28. }