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.

BodyTrait.h 909B

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. #include "../common.h"
  3. namespace Swan {
  4. struct BodyTrait {
  5. struct Tag {};
  6. struct Body final {
  7. Vec2 pos{};
  8. Vec2 size{};
  9. float left() { return pos.x; }
  10. float right() { return pos.x + size.x; }
  11. float midX() { return pos.x + size.x / 2; }
  12. float top() { return pos.y; }
  13. float bottom() { return pos.y + size.y; }
  14. float midY() { return pos.y + size.y / 2; }
  15. Vec2 topLeft() { return { left(), top() }; }
  16. Vec2 midLeft() { return { left(), midY() }; }
  17. Vec2 bottomLeft() { return { left(), bottom() }; }
  18. Vec2 topMid() { return { midX(), top() }; }
  19. Vec2 center() { return { midX(), midY() }; }
  20. Vec2 bottomMid() { return { midX(), bottom() }; }
  21. Vec2 topRight() { return { right(), top() }; }
  22. Vec2 midRight() { return { right(), midY() }; }
  23. Vec2 bottomRight() { return { right(), bottom() }; }
  24. };
  25. virtual ~BodyTrait() = default;
  26. virtual Body &get(Tag) = 0;
  27. };
  28. }