-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tank.cpp
67 lines (50 loc) · 1.21 KB
/
Tank.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
#include "Tank.h"
#include "TankAnimation.h"
Tank::Tank(sf::Texture* texture, sf::Vector2u imageCount, float switchTime, float speed):
animation(texture, imageCount, switchTime)
{
this->speed = speed;
row = 0;
faceRight = true;
body.setSize(sf::Vector2f(300.0f, 200.0f));
//shape.setFillColor(sf::Color::Green);
body.setPosition(1300.0f, 560.0f);
//sf::Texture playertexture;
//playertexture.loadFromFile("sprite.png");
body.setTexture(texture);
}
Tank::~Tank()
{
}
void Tank::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 <= -300.0f)body.setPosition(1390.0f, 560.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 = 0;
}
else
{
row = 3;
if (movement.x > 0.0f)
faceRight = true;
else faceRight = false;
}
animation.Update(row, deltaTime, faceRight);
body.setTextureRect(animation.uvRect);
body.move(movement);
}
void Tank::Draw(sf::RenderWindow& window)
{
window.draw(body);
}