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

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