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.h 852B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #include <vector>
  3. #include <utility>
  4. #include <memory>
  5. #include "common.h"
  6. #include "Chunk.h"
  7. #include "Tile.h"
  8. #include "TileMap.h"
  9. #include "WorldGen.h"
  10. #include "Entity.h"
  11. namespace Swan {
  12. class World;
  13. class WorldPlane {
  14. public:
  15. using ID = uint16_t;
  16. WorldPlane(ID id, World *world, std::shared_ptr<WorldGen> gen):
  17. id_(id), world_(world), gen_(gen) {}
  18. Entity &spawnEntity(const std::string &name, const Vec2 &pos);
  19. bool hasChunk(ChunkPos pos);
  20. Chunk &getChunk(ChunkPos pos);
  21. void setTileID(TilePos pos, Tile::ID id);
  22. Tile &getTile(TilePos pos);
  23. Entity &spawnPlayer();
  24. void draw(Win &win);
  25. void update(float dt);
  26. void tick();
  27. ID id_;
  28. World *world_;
  29. std::shared_ptr<WorldGen> gen_;
  30. private:
  31. std::map<std::pair<int, int>, std::unique_ptr<Chunk>> chunks_;
  32. std::vector<std::unique_ptr<Entity>> entities_;
  33. };
  34. }