-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayer.cpp
72 lines (53 loc) · 1.54 KB
/
Player.cpp
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
#include "Player.h"
Player::Player() :
_position(sf::Vector2f(300,15)),
_animateRight({ 0,0,36,61,5, ResourceDispatcher::rDispatcherTexture.get(0) }),
_animateIdle({ 0,61,36,61,2, ResourceDispatcher::rDispatcherTexture.get(0) }),
_animateLeft({ 0,122,36,61,5, ResourceDispatcher::rDispatcherTexture.get(0) })
{
//auto sf(ResourceDispatcher::rDispatcherTexture.get(0));
_character.setPosition(_position);
/*sf::Texture texture;
if (!texture.loadFromFile("assets/images/billyanim.png")) {
return;
}*/
//_character.setTexture(ResourceDispatcher::rDispatcherTexture.get(0));
//_character.setPosition(_position);
//_character.setColor(sf::Color(255, 255, 255, 200));
}
void Player::processEvents( float sec)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
_position.x -= 50.0f * sec;
_character.setPosition(_position);
_animateLeft.Update(sec);
_animateLeft.ApplyToSprite(_character);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
_position.x += 50.0f * sec;
_character.setPosition(_position);
_animateRight.Update(sec);
_animateRight.ApplyToSprite(_character);
}
else {
_animateIdle.Update(sec);
_animateIdle.ApplyToSprite(_character);
}
}
void Player::update(sf::Time deltaTime)
{
float seconds = deltaTime.asSeconds();
processEvents(seconds );
}
void Player::moveLeft(float mvt)
{
_position.x -= mvt;
_character.setPosition(_position);
}
void Player::animatePlayer()
{
}
void Player::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
target.draw(_character, states);
}