-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayer.cpp
62 lines (49 loc) · 1.19 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
#include "Player.h"
Player::Player(sf::Texture* texture, sf::Vector2u imageCount, float switchTime, float speed):
animation(texture,imageCount,switchTime)
{
this->speed = speed;
row = 3;
faceRight = true;
body.setSize(sf::Vector2f(110.0f, 110.0f));
//shape.setFillColor(sf::Color::Green);
body.setPosition(0.0f,610.0f);
//sf::Texture playertexture;
//playertexture.loadFromFile("sprite.png");
body.setTexture(texture);
}
Player::~Player()
{
}
void Player::Update(float deltaTime)
{
sf::Vector2f movement(0.0f, 0.0f);
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Left))
//movement.x -= speed * deltaTime;
//float x;
//x = body.getPosition().x;
if(body.getPosition().x>=1280.0f)body.setPosition(-90.0f, 610.0f);
//if (body.getPosition().x == 600.0f)
//{
//}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Right))
movement.x += speed * deltaTime;
if (movement.x == 0.0f)
{
row = 2;
}
else
{
row = 2;
if (movement.x > 0.0f)
faceRight = true;
else faceRight = false;
}
animation.Update(row, deltaTime, faceRight);
body.setTextureRect(animation.uvRect);
body.move(movement);
}
void Player::Draw(sf::RenderWindow& window)
{
window.draw(body);
}