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.

Tile.h 758B

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. #include <stdint.h>
  3. #include <string>
  4. #include <optional>
  5. #include <memory>
  6. #include "Item.h"
  7. #include "Resource.h"
  8. namespace Swan {
  9. class Tile {
  10. public:
  11. using ID = uint16_t;
  12. struct Builder {
  13. std::string name;
  14. std::string image;
  15. bool is_solid = true;
  16. std::optional<std::string> dropped_item = std::nullopt;
  17. };
  18. Tile(const ImageResource &image, const std::string &mod, const Builder &builder):
  19. name_(mod+"::"+builder.name), image_(image),
  20. is_solid_(builder.is_solid), dropped_item_(builder.dropped_item) {}
  21. const std::string name_;
  22. const ImageResource &image_;
  23. const bool is_solid_;
  24. const std::optional<std::string> dropped_item_;
  25. static std::unique_ptr<Tile> createInvalid(Context &ctx);
  26. static ID INVALID_ID;
  27. };
  28. }