forked from GianlucaBotteri/CPPVideogame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectile.cpp
More file actions
39 lines (34 loc) · 1.14 KB
/
Projectile.cpp
File metadata and controls
39 lines (34 loc) · 1.14 KB
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
#include "Projectile.h"
Projectile::Projectile() {
rect.setSize(sf::Vector2f(32, 32));
rect.setPosition(0, 0);
sprite.setTextureRect(sf::IntRect(0, 0, 32, 32));
}
void Projectile::update() {
if (direction == Character::Direction::Up) {
rect.move(0, -movementSpeed);
sprite.setTextureRect(sf::IntRect(counterAnimation * 32, 3 * 32, 32, 32));
}
if (direction == Character::Direction::Down) {
rect.move(0, movementSpeed);
sprite.setTextureRect(sf::IntRect(counterAnimation * 32, 0, 32, 32));
}
if (direction == Character::Direction::Left) {
rect.move(-movementSpeed, 0);
sprite.setTextureRect(sf::IntRect(counterAnimation * 32, 1 * 32, 32, 32));
}
if (direction == Character::Direction::Right) {
rect.move(movementSpeed, 0);
sprite.setTextureRect(sf::IntRect(counterAnimation * 32, 2 * 32, 32, 32));
}
counterLifetime++;
if (counterLifetime >= lifeTime) {
destroy = true;
}
counterAnimation++;
if (counterAnimation >= 2) {
counterAnimation = 0;
}
// Sprite set at Rect
sprite.setPosition(rect.getPosition());
}