-
Notifications
You must be signed in to change notification settings - Fork 0
/
Structures.h
149 lines (123 loc) · 3.68 KB
/
Structures.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifndef STRUCTURES_H
#define STRUCTURES_H
#define MAX_PAG_W 8
#define MIN_PAG_W 4
#define MAX_MOV_W 6
#define MOV_RANGE 8
#define MOV_LEFT -1
#define MOV_RIGHT 1
#define DP_TYPES 4 // types of disappearing platforms
#define DP_LINE 0
#define DP_STAIR 1
#define DP_CLINE 2
#define DP_CSTAIR 3
#define DP_SIZE 2 // size of disappearing platform
#define LINE_LEN 14
#define LINE_HEI 1
#define STAIR_LEN 4
#define STAIR_HEI 7
#define CLINE_LEN 10
#define CLINE_HEI 5
#define CSTAIR_LEN 6
#define CSTAIR_HEI 9
#define DP_ALERT 400 // it emits a small alert, before disappearing
#define CAN_RANGE 8
#define MAX_CANONS 3
#define CAN_PLAT_LEN 2
#define CAN_SUB_HEI 3
#define MAX_SUBS 3
#include "Arduino.h"
#include "World.h"
#include "SoundsManager.h"
enum StructureTypes {PagodaStruct, MovingPlatformStruct, DisappearingStruct, CanonStruct};
struct BoundingBox;
class World;
class Player;
// abstract class
class BaseStructure {
protected:
int8_t ey, ex; // where it's supposed to reach, i.e. anchor point determined in the world class
StructureTypes type;
public:
BaseStructure(int8_t ey, int8_t ex, StructureTypes type);
virtual ~BaseStructure() {}
virtual void draw(World* world) = 0;
virtual void activate(Player* player) = 0;
virtual Pos getPos() const = 0;
virtual void setPos(Pos pos) = 0;
virtual BoundingBox getBoundingBox() = 0;
};
class Pagoda : public BaseStructure {
int8_t top, left, width, height;
public:
Pagoda(int8_t ey, int8_t ex);
~Pagoda() {}
void draw(World* world);
void activate(Player* player) { }
Pos getPos() const { return Pos(this->top, this->left);}
void setPos(Pos pos) { this->top = pos.i; this->left = pos.j;}
BoundingBox getBoundingBox();
};
class MovingPlatform : public BaseStructure {
private:
int8_t length, crx, moveDirection;
long lastMoved;
public:
static const int moveInterval;
MovingPlatform(int8_t ey, int8_t ex);
~MovingPlatform() {}
void draw(World* world);
void activate(Player* player);
Pos getPos() const { return Pos(this->ey, this->crx);}
void setPos(Pos pos) { this->ey = pos.i; this->ex -= (this->crx - pos.j); this->crx = pos.j;}
BoundingBox getBoundingBox();
};
/**
* @brief
* Disappearing platforms will be spawned with different unique types, representing what pattern they will follow.
*/
class DisappearingPlatform : public BaseStructure {
private:
int8_t dtype, top, left, state;
long lastSwitch;
bool playedSound;
public:
static const int switchInterval;
DisappearingPlatform(int8_t ey, int8_t ex);
~DisappearingPlatform() {}
void draw(World* world);
void activate(Player* player);
Pos getPos() const { return Pos(this->top, this->left);};
void setPos(Pos pos);
BoundingBox getBoundingBox();
};
/**
* @brief
* Canons will be at most 3 layered substructures consisting of a platform of length 2, a canon and at the end another platform the player has
* to jump to (or the final platform).
*/
class Canon : public BaseStructure {
private:
byte can_no;
int8_t x[MAX_SUBS + 1];
int8_t b[MAX_SUBS]; // bullet positions on the map
long lastMoved, lastShot;
bool isShooting;
int8_t translateBulletPos(int8_t x);
int8_t translatePlatPos(int8_t x) const;
public:
static const int moveInterval, shootInterval;
Canon(int8_t ey, int8_t ex, byte can_no);
~Canon() {}
void draw(World* world);
void activate(Player* player);
Pos getPos() const;
void setPos(Pos pos);
BoundingBox getBoundingBox();
};
struct StructNode {
BaseStructure* structure;
StructNode* next;
StructNode(BaseStructure* structure, StructNode* node) : structure(structure), next(node) {}
};
#endif