-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plane.cpp
90 lines (72 loc) · 1.81 KB
/
Plane.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "Plane.h"
//#include "Animation.h"
Plane::Plane(sf::Texture* texture, sf::Vector2u imageCount, float switchTime, float speed) :
animation(texture, imageCount, switchTime)
{
this->speed = speed;
row = 1;
faceRight = true;
planeBody.setSize(sf::Vector2f(250.75f, 112.5f));
planeBody.setPosition(0.0f, 10.0f);
planeBody.setTexture(texture);
}
Plane::~Plane()
{
}
void Plane::Update(float deltaTime)
{
sf::Vector2f movement(0.0f, 0.0f);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Left)&&planeBody.getPosition().x>-5)
movement.x -= speed * deltaTime;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Right)&&planeBody.getPosition().x < 1030)
movement.x += speed * deltaTime;
if (movement.x == 0.0f)
{
row = 1;
}
else
{
row = 1;
if (movement.x > 0.0f)
faceRight = true;
else
faceRight = false;
}
animation.UpdateMove(row, deltaTime, faceRight);
planeBody.setTextureRect(animation.uvRect);
planeBody.move(movement);
}
void Plane::UpdateDead(float deltaTime)
{
sf::Vector2f movement(0.0f, 0.0f);
animation.UpdateDead(row, deltaTime, faceRight);
planeBody.setTextureRect(animation.uvRect);
planeBody.move(movement);
}
void Plane::UpdateHit(float deltaTime)
{
sf::Vector2f movement(0.0f, 0.0f);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Left) && planeBody.getPosition().x > -5)
movement.x -= speed * deltaTime;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Right) && planeBody.getPosition().x < 1030)
movement.x += speed * deltaTime;
if (movement.x == 0.0f)
{
row = 3;
}
else
{
row = 3;
if (movement.x > 0.0f)
faceRight = true;
else
faceRight = false;
}
animation.UpdateHit(row, deltaTime, faceRight);
planeBody.setTextureRect(animation.uvRect);
planeBody.move(movement);
}
void Plane::Draw(sf::RenderWindow& window)
{
window.draw(planeBody);
}