A 2D tile-based sandbox game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WorldPlane.cc 852B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "WorldPlane.h"
  2. #include "World.h"
  3. namespace Swan {
  4. Chunk &WorldPlane::getChunk(int x, int y) {
  5. auto coord = Coord(x / CHUNK_WIDTH, y / CHUNK_HEIGHT);
  6. auto it = chunks_.find(coord);
  7. if (it == chunks_.end()) {
  8. it = chunks_.emplace(coord, Chunk(coord.first, coord.second)).first;
  9. gen_->genChunk(it->second, coord.first, coord.second);
  10. it->second.redraw(world_->tile_map_);
  11. }
  12. return it->second;
  13. }
  14. void WorldPlane::setTileID(int x, int y, Tile::ID id) {
  15. getChunk(x, y).setTileID(world_->tile_map_, x % CHUNK_WIDTH, y % CHUNK_HEIGHT, id);
  16. }
  17. Tile &WorldPlane::getTile(int x, int y) {
  18. return getChunk(x, y).getTile(world_->tile_map_, x % CHUNK_WIDTH, y % CHUNK_HEIGHT);
  19. }
  20. void WorldPlane::draw(Win &win) {
  21. for (auto &p: chunks_) {
  22. p.second.draw(win);
  23. }
  24. }
  25. void WorldPlane::update(float dt) {
  26. }
  27. void WorldPlane::tick() {
  28. }
  29. }