World.cpp 1.1 KB

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