-
Notifications
You must be signed in to change notification settings - Fork 1
/
Soldier.cpp
51 lines (41 loc) · 1.08 KB
/
Soldier.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
#include "Soldier.h"
#include "Plane.h"
Soldier::Soldier(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));
body.setPosition(0.0f, 610.0f);
body.setTexture(texture);
}
Soldier::~Soldier()
{
}
void Soldier::updateMoveLeft(float deltaTime)
{
sf::Vector2f movement(0.0f, 0.0f);
row = 2;
if (body.getPosition().x <= -100.0f)body.setPosition(1340, 610.0f);
movement.x -= speed * deltaTime;
faceRight = false;
animation.Update(row, deltaTime, faceRight);
body.setTextureRect(animation.uvRect);
body.move(movement);
}
void Soldier::updateMoveRight(float deltaTime)
{
sf::Vector2f movement(0.0f, 0.0f);
row = 2;
if (body.getPosition().x >= 1280.0f)body.setPosition(-90.0f, 610.0f);
movement.x += speed * deltaTime;
faceRight = true;
animation.Update(row, deltaTime, faceRight);
body.setTextureRect(animation.uvRect);
body.move(movement);
}
void Soldier::Draw(sf::RenderWindow& window)
{
window.draw(body);
}