World.cpp 922 B

1234567891011121314151617181920212223242526272829303132
  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) : blockRegistry(blockRegistry), blocks(7, 7) {
  5. Block stone = blockRegistry.getBlock("stone");
  6. HighMap map(blocks.getSize(), blocks.getHeight());
  7. for(int x = 0; x < blocks.getSize(); x++) {
  8. for(int z = 0; z < blocks.getSize(); z++) {
  9. int height = map.getHeight(x, z);
  10. for(int y = 0; y < height; y++) {
  11. setBlock(x, y, z, stone);
  12. }
  13. }
  14. }
  15. }
  16. void World::setBlock(int x, int y, int z, const Block& block) {
  17. blocks.set(x, y, z, block.getId());
  18. }
  19. const Block& World::getBlock(int x, int y, int z) const {
  20. return blockRegistry.getBlock(blocks.get(x, y, z));
  21. }
  22. int World::getSize() const {
  23. return blocks.getSize();
  24. }
  25. int World::getHeight() const {
  26. return blocks.getHeight();
  27. }