-
Notifications
You must be signed in to change notification settings - Fork 1
/
Event.h
70 lines (57 loc) · 1.64 KB
/
Event.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
64
65
66
67
68
69
70
#ifndef SUPERMARIOBROS_EVENT_H
#define SUPERMARIOBROS_EVENT_H
#include <Entity.h>
#include <variant>
enum class EventType
{
POINTS_EARNED,
ITEM_SPAWNED,
BLOCK_SHATTERED,
ANIMATION_COMPLETED,
FIREBALL_SPAWNED,
};
class Event
{
public:
EventType type;
static Event constructPointsEarned(const sf::Vector2f& position, int points);
static Event constructItemSpawned(EntityType type,
const sf::Vector2f& position,
float blockBottom);
static Event constructBlockShattered(const sf::Vector2f& position);
static Event constructAnimationCompleted(const std::string& animationType);
static Event constructFireball(const sf::Vector2f& position, int direction);
struct PointsEarned
{
sf::Vector2f position;
int points;
};
struct ItemSpawned
{
sf::Vector2f position;
EntityType type;
float blockTop;
};
struct BlockShattered
{
sf::Vector2f position;
};
struct AnimationCompleted
{
std::string animationType;
};
struct FireballSpawned
{
sf::Vector2f position;
int direction;
};
[[nodiscard]] PointsEarned asPointsEarned() const;
[[nodiscard]] ItemSpawned asItemSpawned() const;
[[nodiscard]] BlockShattered asBlockShattered() const;
[[nodiscard]] AnimationCompleted asAnimationCompleted() const;
[[nodiscard]] FireballSpawned asFireballSpawned() const;
private:
std::variant<PointsEarned, ItemSpawned, BlockShattered, AnimationCompleted, FireballSpawned>
eventData;
};
#endif // SUPERMARIOBROS_EVENT_H