Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include "Player.hpp"
  2.  
  3.  
  4.  
  5. Player::Player(sf::Color playerColor, sf::Vector2f startPosition)
  6.     :   radius(20.f),
  7.         player(radius)
  8. {
  9.     player.setFillColor(playerColor);
  10.     player.setPosition(startPosition);
  11. }
  12.  
  13. bool Player::isAttacking()
  14. {
  15.     if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
  16.         return true;
  17.     return false;
  18. }
  19.  
  20. void Player::move(float dt)
  21. {
  22.     const float speed = 400;
  23.  
  24.     if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
  25.         player.move(0, -dt * speed);
  26.    
  27.     else if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
  28.         player.move(0, dt * speed);
  29.  
  30.     if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
  31.         player.move(dt * speed, 0);
  32.  
  33.     else if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
  34.         player.move(-dt * speed, 0);
  35. }
  36.  
  37. void Player::update(float dt)
  38. {
  39.     move(dt);
  40. }
  41.  
  42. void Player::draw(sf::RenderTexture &gameTexture)
  43. {
  44.     gameTexture.draw(player);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement