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

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. // TODO: Switch to struct
  10. class Tile {
  11. public:
  12. using ID = uint16_t;
  13. struct Builder {
  14. std::string name;
  15. std::string image;
  16. bool isSolid = true;
  17. float lightLevel = 0;
  18. std::optional<std::string> droppedItem = std::nullopt;
  19. };
  20. Tile(const ResourceManager &resources, const Builder &builder):
  21. name_(builder.name), image_(resources.getImage(builder.image)),
  22. isSolid_(builder.isSolid), lightLevel_(builder.lightLevel),
  23. droppedItem_(builder.droppedItem) {}
  24. const std::string name_;
  25. const ImageResource &image_;
  26. const bool isSolid_;
  27. const float lightLevel_;
  28. const std::optional<std::string> droppedItem_;
  29. static std::unique_ptr<Tile> createInvalid(const ResourceManager &ctx);
  30. static std::unique_ptr<Tile> createAir(const ResourceManager &ctx);
  31. static ID INVALID_ID;
  32. };
  33. }