-
Notifications
You must be signed in to change notification settings - Fork 0
/
Projectile.h
63 lines (47 loc) · 1.54 KB
/
Projectile.h
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
#ifndef PROJECTILE_H
#define PROJECTILE_H
#include "Player.h"
class Projectile : public ILevelObject, public ICollidable
{
sf::RectangleShape rect;
sf::Vector2f direction;
sf::Vector2f oldPosition;
bool phasing, oldPhasing;
public:
static const sf::Mouse::Button BUTTON;
Projectile(Player* player, const sf::Vector2f& dir);
void update(Level& level, sf::Time delta) override;
const sf::Vector2f& getPosition() const override {
return rect.getPosition();
}
void setPosition(const sf::Vector2f& pos) override {
rect.setPosition(pos);
}
const sf::Vector2f& getOldPosition() const {
return oldPosition;
}
sf::FloatRect getCollisionBox() const override {
return rect.getGlobalBounds();
}
const sf::Color& getColor() const override {
return rect.getFillColor();
}
bool isPhasing() const {
return phasing;
}
bool wasPhasing() const {
return oldPhasing;
}
bool isCollidingWith(ICollidable& other) override {
if (!destroyed && getCollisionBox().intersects(other.getCollisionBox())) {
if (getColor() != other.getColor())
return true;
phasing = true;
}
return false;
}
void draw(sf::RenderTarget& target, sf::RenderStates states) const override {
target.draw(rect);
};
};
#endif // PROJECTILE_H