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.cc 499B

1234567891011121314151617181920212223242526272829
  1. #include "Body.h"
  2. namespace Swan {
  3. void Body::friction(float coef) {
  4. force_ += -vel_ * coef;
  5. }
  6. void Body::gravity(Vec2 g) {
  7. force_ += g * mass_;
  8. }
  9. void Body::outline(Win &win) {
  10. win.setPos(pos_);
  11. sf::RectangleShape rect(size_);
  12. rect.setFillColor(sf::Color::Transparent);
  13. rect.setOutlineColor(sf::Color(128, 128, 128));
  14. rect.setOutlineThickness(2 / UNIT_SIZE);
  15. win.draw(rect);
  16. }
  17. void Body::update(float dt) {
  18. vel_ += (force_ / mass_) * dt;
  19. pos_ += vel_ * dt;
  20. force_ = { 0, 0 };
  21. }
  22. }