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

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