-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeapon.cpp
More file actions
63 lines (54 loc) · 1.51 KB
/
Weapon.cpp
File metadata and controls
63 lines (54 loc) · 1.51 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 "Weapon.hpp"
#include "Prop.hpp"
#include "Player.hpp"
#include "Fairy.hpp"
Weapon::Weapon(Map* map, sf::Vector2f pos, directions dir) :
Collisionable(pos),
_map(map),
_dir(dir) {
_dead = false;
_damage = 0;
}
Weapon::~Weapon() {}
void Weapon::update(float deltaTime) {
sf::Vector2f movement, initial;
initial = _sprite.getPosition();
movement.x = (_dir == directions::left ? -_speed.x : (_dir == directions::right ? _speed.x : (_dir == directions::none ? _speed.x : 0)));
movement.y = (_dir == directions::up ? -_speed.y : (_dir == directions::down ? _speed.y : (_dir == directions::none ? _speed.y : 0)));
sf::Vector2f maxMovement = _map->getMaxMovement(initial,movement*deltaTime,_bounds, _collisionMask, true);
if (movement*deltaTime != maxMovement) hit();
cmove(maxMovement);
}
float Weapon::getDamage() {
return _damage;
}
bool Weapon::isAlive() {
return !_dead;
}
void Weapon::hit() {
}
directions Weapon::getDirection() {
return _dir;
}
void Weapon::intersectsWith(Collisionable* c) {
Prop* prop = dynamic_cast<Prop*>(c);
if (prop != nullptr) {
hit();
return;
}
Player* player = dynamic_cast<Player*>(c);
if (player != nullptr) {
hit();
return;
}
Fairy* fairy = dynamic_cast<Fairy*>(c);
if (fairy != nullptr) {
hit();
return;
}
DungeonDoor* door = dynamic_cast<DungeonDoor*>(c);
if (door != nullptr) {
if (!door->isOpened()) hit();
return;
}
}