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.

Player.cc 839B

12345678910111213141516171819202122232425262728293031
  1. #include "Player.h"
  2. namespace Swan {
  3. const float Player::force = 600;
  4. const float Player::friction = 100;
  5. const float Player::mass = 80;
  6. const Vec2 Player::size = Vec2(1, 2);
  7. using Keyboard = sf::Keyboard;
  8. void Player::draw(Win &win) {
  9. body_.outline(win);
  10. }
  11. void Player::update(float dt) {
  12. if (Keyboard::isKeyPressed(Keyboard::W) || Keyboard::isKeyPressed(Keyboard::Up))
  13. body_.force_ += Vec2(0, -force);
  14. if (Keyboard::isKeyPressed(Keyboard::S) || Keyboard::isKeyPressed(Keyboard::Down))
  15. body_.force_ += Vec2(0, force);
  16. if (Keyboard::isKeyPressed(Keyboard::A) || Keyboard::isKeyPressed(Keyboard::Left))
  17. body_.force_ += Vec2(-force, 0);
  18. if (Keyboard::isKeyPressed(Keyboard::D) || Keyboard::isKeyPressed(Keyboard::Right))
  19. body_.force_ += Vec2(force, 0);
  20. body_.friction(friction);
  21. body_.gravity();
  22. body_.update(dt);
  23. }
  24. }