-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStage.h
More file actions
273 lines (232 loc) · 5.67 KB
/
Stage.h
File metadata and controls
273 lines (232 loc) · 5.67 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#ifndef __STAGE_H__
#define __STAGE_H__
#include "Arduboy.h"
#include "Scene.h"
#include "Rocket.h"
#include "Laser.h"
#include "Stone.h"
#include "Global.h"
#include <math.h>
extern int16_t score;
class Stage : public Scene
{
private:
static const int16_t LIFE_MAX = 3;
static const int16_t PLANET_LIFE_MAX = 100;
static const int16_t STONE_MAX = 10;
static const int16_t STONE_LAUNCH_COUNT = 100;
Stone* stone[STONE_MAX];
Rocket* rocket;
int level;
int remaining_stone;
bool isPause;
bool isPausePushed;
bool isContinue;
int life;
int planet_life;
int stone_launch_count;
char text[16];
public:
Stage(Arduboy* _arduboy);
~Stage();
void init();
void initLevel(int _level);
void clearLevel();
void reset();
void HitCheck();
bool HitCheck_Laser_Stone(Laser* l, Stone* s);
bool HitCheck_Rocket_Stone(Rocket* r, Stone* s);
bool run();
void draw();
};
Stage::Stage(Arduboy* _arduboy)
{
arduboy = _arduboy;
init();
}
Stage::~Stage()
{
}
void Stage::init()
{
life = Stage::LIFE_MAX;
planet_life = Stage::PLANET_LIFE_MAX;
for (int i = 0; i < STONE_MAX; i++) {
stone[i] = new Stone(arduboy);
}
rocket = new Rocket(arduboy);
score = 0;
stone_launch_count = 10;
isPause = false;
isPausePushed = false;
isContinue = true;
initLevel(1);
}
void Stage::initLevel(int _level)
{
level = _level;
remaining_stone = 30;
}
void Stage::clearLevel()
{
delay(500);
reset();
initLevel(level + 1);
}
void Stage::reset()
{
for (int i = 0; i < STONE_MAX; i++) {
stone[i]->reset();
}
rocket->reset();
}
void Stage::HitCheck()
{
int i = 0;
for (i = 0; i < STONE_MAX; i++) {
HitCheck_Laser_Stone(rocket->getLaser(), stone[i]);
HitCheck_Rocket_Stone(rocket, stone[i]);
}
}
bool Stage::HitCheck_Laser_Stone(Laser* l, Stone* s)
{
bool flag = false;
if (s->getStatus() == Stone::STONE_STATUS::LAUNCHED
&& l->getStatus() == Laser::LASER_STATUS::EMITTED
&& l->getLeft() <= s->getRight()
&& l->getTop() <= s->getBottom()
&& l->getRight() >= s->getLeft()
&& l->getBottom() >= s->getTop()) {
l->hit();
Stone::HIT_STATUS status = s->hit();
if (status == Stone::HIT_STATUS::SPLIT) {
// splitting
for (int i = 0; i < STONE_MAX; i++) {
if (stone[i]->getStatus() == Stone::STONE_STATUS::NOT_LAUNCHED) {
s->split(stone[i]);
break;
}
}
score += 10;
if (music) {
arduboy->tunes.tone(250, 150);
}
}
else if (status == Stone::HIT_STATUS::BREAK){
score += 10;
remaining_stone--;
if (music) {
arduboy->tunes.tone(250, 150);
}
}
flag = true;
}
return flag;
}
bool Stage::HitCheck_Rocket_Stone(Rocket* r, Stone* s)
{
bool flag = false;
if (s->getStatus() == Stone::STONE_STATUS::LAUNCHED
&& r->getLeft() <= s->getRight()
&& r->getTop() <= s->getBottom()
&& r->getRight() >= s->getLeft()
&& r->getBottom() >= s->getTop()) {
r->crash();
if (--life < 0) {
isContinue = false;
}
reset();
}
return flag;
}
bool Stage::run()
{
if(arduboy->pressed(UP_BUTTON + A_BUTTON)
|| arduboy->pressed(UP_BUTTON + B_BUTTON)
|| arduboy->pressed(DOWN_BUTTON + A_BUTTON)
|| arduboy->pressed(DOWN_BUTTON + B_BUTTON)) {
if (!isPausePushed) {
isPause = !isPause;
isPausePushed = true;
}
}
else {
isPausePushed = false;
}
if (isPause) {
return isContinue;
}
if (remaining_stone < 0) {
clearLevel();
}
HitCheck();
bool isLaunch = false;
stone_launch_count--;
if (stone_launch_count < 0) {
isLaunch = true;
stone_launch_count = STONE_LAUNCH_COUNT;
}
for (int i = 0; i < STONE_MAX; i++) {
if (stone[i]->getStatus() != Stone::STONE_STATUS::NOT_LAUNCHED) {
if (stone[i]->move()) {
planet_life -= 5;
if (music) {
arduboy->tunes.tone(200, 100);
}
if (planet_life < 0) {
planet_life = 0;
isContinue = false;
}
}
}
else if (stone[i]->getStatus() == Stone::STONE_STATUS::NOT_LAUNCHED) {
if (isLaunch) {
stone[i]->launch();
isLaunch = false;
}
}
}
rocket->move();
return isContinue;
}
void Stage::draw()
{
int i = 0;
// Drawing Lines for Separating AREA
arduboy->drawLine(GAME_PANEL_X, 0, GAME_PANEL_X, SCREEN_HEIGHT, 1);
arduboy->drawLine(STAGE_INFO_PANEL_X, 0, STAGE_INFO_PANEL_X, SCREEN_HEIGHT, 1);
// Drawing ROCKET AREA
//Drawing Level
arduboy->drawBitmap(1 + ROCKET_INFO_PANEL_X, 3, bitmap_level, 8, 5, 1);
arduboy->drawBitmap(9 + ROCKET_INFO_PANEL_X, 3, bitmap_digit[level / 10], 3, 5, 1);
arduboy->drawBitmap(13 + ROCKET_INFO_PANEL_X, 3, bitmap_digit[level % 10], 3, 5, 1);
//Drawing life
arduboy->drawBitmap(1 + ROCKET_INFO_PANEL_X, 12, bitmap_icon, 5, 5, 1);
arduboy->drawBitmap(10 + ROCKET_INFO_PANEL_X, 12, bitmap_digit[life], 3, 5, 1);
//Drawing Score
int tmp = score;
for (i = 0; i < 4; i++) {
arduboy->drawBitmap(12 - i * 4 + ROCKET_INFO_PANEL_X, 22, bitmap_digit[tmp % 10], 3, 5, 1);
tmp /= 10;
}
// Drawing STAGE AREA
for (i = 0; i < remaining_stone / 10; i++) {
arduboy->drawCircle(3 + STAGE_INFO_PANEL_X, 2 + i * 4, 1, 1);
}
for (i = 0; i < remaining_stone % 10; i++) {
arduboy->drawPixel(7 + STAGE_INFO_PANEL_X, 2 + i * 2, 1);
}
arduboy->drawRect(3 + STAGE_INFO_PANEL_X, 23, 7, 40, 1);
arduboy->fillRect(3 + STAGE_INFO_PANEL_X, 23 + 40.0 * (float)(Stage::PLANET_LIFE_MAX - planet_life) / (float)PLANET_LIFE_MAX,
7, ceil(40.0 * (float)planet_life / (float)PLANET_LIFE_MAX), 1);
// Drawing GAME AREA
for (i = 0; i < STONE_MAX; i++) {
stone[i]->draw();
}
rocket->draw();
if (isPause) {
arduboy->setCursor(50, 20);
arduboy->print("PAUSE");
}
}
#endif