-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
61 lines (39 loc) · 1023 Bytes
/
Player.cpp
File metadata and controls
61 lines (39 loc) · 1023 Bytes
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
#include "Player.h"
Player :: Player (Texture *texture, Vector2u imageCount, float switchTime, float speed) : game(texture,imageCount,switchTime)
{
this->speed = speed;
row = 0;
faceRight = true;
body.setSize(Vector2f(100.0f, 150.0f));
body.setOrigin(body.getSize()/2.0f);
body.setPosition(206.0f, 206.0f);
body.setTexture(texture);
}
void Player :: Update (float deltaTime) {
Vector2f movement(0.0f,0.0f);
if(Keyboard ::isKeyPressed(Keyboard::Key::A)){
movement.x -= speed * deltaTime;
}
if(Keyboard ::isKeyPressed(Keyboard::Key::D)){
movement.x += speed * deltaTime;
}
if(movement.x==0.0f){
row = 0;
}
else {
row = 1;
if(movement.x>0.0f)
{
faceRight = true;
}
else{
faceRight = false;
}
}
game.update((int)row,deltaTime,faceRight);
body.setTextureRect(game.uvRect);
body.move(movement);
}
void Player ::draw(RenderWindow &window) {
window.draw(body);
}