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

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #pragma once
  2. #include <stdint.h>
  3. #include <string>
  4. #include <optional>
  5. #include "common.h"
  6. namespace Swan {
  7. struct Tile {
  8. public:
  9. using ID = uint16_t;
  10. struct Builder {
  11. std::string name;
  12. std::string image;
  13. bool isSolid = true;
  14. bool isOpaque = isSolid;
  15. float lightLevel = 0;
  16. std::optional<std::string> droppedItem = std::nullopt;
  17. void (*onSpawn)(const Context &ctx, TilePos pos) = nullptr;
  18. };
  19. const ID id;
  20. const std::string name;
  21. const bool isSolid;
  22. const bool isOpaque;
  23. const float lightLevel;
  24. const std::optional<std::string> droppedItem;
  25. void (*const onSpawn)(const Context &ctx, TilePos pos);
  26. Tile(ID id, std::string name, const Builder &builder):
  27. id(id), name(name),
  28. isSolid(builder.isSolid), isOpaque(builder.isOpaque),
  29. lightLevel(builder.lightLevel),
  30. droppedItem(builder.droppedItem), onSpawn(builder.onSpawn) {}
  31. };
  32. }