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.

Body.h 734B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #include <SFML/Graphics.hpp>
  3. #include "common.h"
  4. #include "BoundingBox.h"
  5. namespace Swan {
  6. class WorldPlane;
  7. class Body {
  8. public:
  9. Body(Vec2 size, float mass, Vec2 pos = Vec2::ZERO):
  10. size_(size), mass_(mass), pos_(pos) {};
  11. void friction(Vec2 coef = Vec2(400, 50));
  12. void gravity(Vec2 g = Vec2(0, 20));
  13. void outline(Win &win);
  14. void update(WorldPlane &plane, float dt);
  15. void updateWithoutCollision(float dt);
  16. BoundingBox getBounds() { return { pos_, size_ }; }
  17. Vec2 force_ = { 0, 0 };
  18. Vec2 vel_ = { 0, 0 };
  19. bool on_ground_ = false;
  20. Vec2 size_;
  21. float mass_;
  22. Vec2 pos_;
  23. float bounciness_ = 0;
  24. float mushyness_ = 2;
  25. private:
  26. void collideX(WorldPlane &plane);
  27. void collideY(WorldPlane &plane);
  28. };
  29. }