-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectile.cpp
More file actions
41 lines (38 loc) · 1.23 KB
/
Projectile.cpp
File metadata and controls
41 lines (38 loc) · 1.23 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
40
41
#include "Projectile.hpp"
Projectile::Projectile() {
rect.setSize(sf::Vector2f(15, 15));
rect.setPosition(0, 0);
rect.setFillColor(sf::Color::Black);
}
void Projectile::update() {
switch(direction) {
case 1: //Up
rect.move(0,-movementSpeed);
sprite.setTextureRect(sf::IntRect(animationCounter*32,3*32,32,32));
sprite.setPosition(rect.getPosition());
break;
case 2: //Down
rect.move(0,movementSpeed);
sprite.setTextureRect(sf::IntRect(animationCounter*32,0*32,32,32));
sprite.setPosition(rect.getPosition());
break;
case 3: //Left
rect.move(-movementSpeed,0);
sprite.setTextureRect(sf::IntRect(animationCounter*32,1*32,32,32));
sprite.setPosition(rect.getPosition());
break;
case 4: //Right
rect.move(movementSpeed, 0);
sprite.setTextureRect(sf::IntRect(animationCounter*32,2*32,32,32));
sprite.setPosition(rect.getPosition());
break;
}
animationCounter++;
if(animationCounter > 2) {
animationCounter = 0;
}
lifeCounter++;
if(lifeCounter >= lifeTime) {
destroy = true;
}
}