-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectile.cpp
More file actions
63 lines (53 loc) · 1.85 KB
/
Projectile.cpp
File metadata and controls
63 lines (53 loc) · 1.85 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "Projectile.hpp"
Projectile::Projectile() {
deltaToDespawn = timeToDespawn;
_sprite.setTexture(Resources::linkSet);
_sprite.setTextureRect(Resources::descriptions[swordDescriptions][swordtypes::first][0]);
std::vector<sf::Texture*> textures(9);
textures[directions::none] = &Resources::linkSet;
textures[directions::up] = &Resources::linkSetT;
textures[directions::left] = &Resources::linkSetL;
textures[directions::down] = &Resources::linkSetB;
textures[directions::right] = &Resources::linkSetR;
textures[directions::topLeft] = &Resources::linkSetTL;
textures[directions::botLeft] = &Resources::linkSetBL;
textures[directions::topRight] = &Resources::linkSetTR;
textures[directions::botRight] = &Resources::linkSetBR;
_lightSprite = LightSprite(Resources::descriptions[swordDescriptions], textures);
_bounds = sf::IntRect(0,0,7,16);
}
Projectile::~Projectile() {}
void Projectile::init(directions dir, sf::Vector2f pos) {
_lightSprite.update(pos,0,0,0);
_sprite.setPosition(pos);
switch(dir){
case directions::down:
_lightSprite.setRotation(0);
break;
case directions::up:
_lightSprite.setRotation(180);
break;
case directions::right:
_lightSprite.setRotation(270);
break;
case directions::left:
_lightSprite.setRotation(90);
break;
default:
break;
}
}
void Projectile::update(float deltaTime) {
_sprite.move(_speed*deltaTime);
deltaToDespawn -= timeToDespawn;
}
void Projectile::draw(sf::RenderTarget* w) {
_lightSprite.draw(w);
}
void Projectile::setPosition(sf::Vector2f pos) {
_sprite.setPosition(pos);
_lightSprite.setPosition(pos);
}
void Projectile::setLight(Light* light) {
_lightSprite.setLight(light);
}