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.

TileMap.h 496B

12345678910111213141516171819202122232425262728293031
  1. #pragma once
  2. #include <memory>
  3. #include "Tile.h"
  4. namespace Swan {
  5. class TileMap {
  6. public:
  7. std::vector<std::shared_ptr<Tile>> tiles_;
  8. std::map<std::string, Tile::ID> id_map_;
  9. Tile::ID getID(const std::string &name) {
  10. return id_map_[name];
  11. }
  12. Tile &get(Tile::ID id) {
  13. if (id >= tiles_.size())
  14. return Tile::invalid_tile;
  15. return *tiles_[id];
  16. }
  17. void registerTile(std::shared_ptr<Tile> t) {
  18. Tile::ID id = tiles_.size();
  19. tiles_.push_back(t);
  20. id_map_[t->name_] = id;
  21. }
  22. };
  23. }