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

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