-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
83 lines (65 loc) · 1.53 KB
/
Player.cpp
File metadata and controls
83 lines (65 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "Player.hpp"
Player::Player() {
setTexture(Resources::penguin);
setScale(sf::Vector2f(0.0723589,0.0723589));
setPosition(30,30);
_bounds = sf::FloatRect(0,0,50,20);
_velocity = sf::Vector2f(0,0);
_mass = 40;
}
Player::~Player(){
}
void Player::setTexture(const sf::Texture &texture){
Sprite::setTexture(texture, true);
//_bounds = getGlobalBounds();
}
void Player::update(float deltatime){
// _velocity *= 0.95f;
_velocity += _acceleration * deltatime;
}
bool Player::jumping() const{
return _jumping;
}
void Player::setJumping(bool jumping){
if (!jumping) _velocity.y =0;
_jumping = jumping;
}
sf::Vector2f Player::velocity() const{
return _velocity;
}
void Player::setVelocity(const sf::Vector2f &velocity){
_velocity = velocity;
}
sf::Vector2f Player::acceleration() const{
return _acceleration;
}
void Player::setAcceleration(const sf::Vector2f &acceleration){
_acceleration = acceleration;
}
float Player::mass() const
{
return _mass;
}
void Player::setMass(float mass)
{
_mass = mass;
}
sf::FloatRect Player::getMGlobalBounds() {
return sf::FloatRect(getPosition().x + _bounds.left, getPosition().y + _bounds.top, _bounds.width, _bounds.height);
}
sf::FloatRect Player::getMBounds() {
return _bounds;
}
sf::Vector2f Player::move(float deltaTime) {
_lastPosition = getPosition();
sf::Sprite::move(_velocity*deltaTime);
return getPosition()-_lastPosition;
}
float Player::boost() const
{
return _boost;
}
void Player::setBoost(float boost)
{
_boost = boost;
}