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 693B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "WorldPlane.h"
  2. #include "World.h"
  3. namespace Swan {
  4. void WorldPlane::setTile(int x, int y, Tile::TileID id) {
  5. int chx = x / CHUNK_WIDTH;
  6. int chy = y / CHUNK_HEIGHT;
  7. int rx = x % CHUNK_WIDTH;
  8. int ry = y % CHUNK_HEIGHT;
  9. Chunk *chunk = NULL;
  10. for (auto &ch: chunks_) {
  11. if (ch.x_ == chx && ch.y_ == chy) {
  12. chunk = &ch;
  13. break;
  14. }
  15. }
  16. if (chunk == NULL) {
  17. chunks_.push_back(Chunk(chx, chy));
  18. chunk = &chunks_.back();
  19. chunk->fill(world_->tile_map_, 0);
  20. }
  21. chunk->setTile(world_->tile_map_, rx, ry, id);
  22. }
  23. void WorldPlane::draw(Win &win) {
  24. for (auto &chunk: chunks_) {
  25. chunk.draw(win);
  26. }
  27. }
  28. void WorldPlane::update(float dt) {
  29. }
  30. void WorldPlane::tick() {
  31. }
  32. }