|
@@ -26,6 +26,28 @@
|
26
|
26
|
|
27
|
27
|
#include "game.h"
|
28
|
28
|
|
|
29
|
+#define CANNON_W 11
|
|
30
|
+#define CANNON_H 8
|
|
31
|
+#define CANNON_VEL 4
|
|
32
|
+#define CANNON_Y (LCD_PIXEL_HEIGHT - 1 - CANNON_H)
|
|
33
|
+
|
|
34
|
+#define INVADER_VEL 3
|
|
35
|
+
|
|
36
|
+#define INVADER_TOP MENU_FONT_ASCENT
|
|
37
|
+#define INVADERS_WIDE ((INVADER_COL_W) * (INVADER_COLS))
|
|
38
|
+#define INVADERS_HIGH ((INVADER_ROW_H) * (INVADER_ROWS))
|
|
39
|
+
|
|
40
|
+#define UFO_H 5
|
|
41
|
+#define UFO_W 13
|
|
42
|
+
|
|
43
|
+#define LASER_H 4
|
|
44
|
+#define SHOT_H 3
|
|
45
|
+#define EXPL_W 11
|
|
46
|
+#define LIFE_W 8
|
|
47
|
+#define LIFE_H 5
|
|
48
|
+
|
|
49
|
+#define INVADER_RIGHT ((INVADER_COLS) * (INVADER_COL_W))
|
|
50
|
+
|
29
|
51
|
// 11x8
|
30
|
52
|
const unsigned char invader[3][2][16] PROGMEM = {
|
31
|
53
|
{ { B00000110,B00000000,
|
|
@@ -120,20 +142,6 @@ const unsigned char ufo[] PROGMEM = {
|
120
|
142
|
B01111111,B11110000
|
121
|
143
|
};
|
122
|
144
|
|
123
|
|
-#define INVASION_SIZE 3
|
124
|
|
-
|
125
|
|
-#if INVASION_SIZE == 3
|
126
|
|
- #define INVADER_COLS 5
|
127
|
|
-#elif INVASION_SIZE == 4
|
128
|
|
- #define INVADER_COLS 6
|
129
|
|
-#else
|
130
|
|
- #define INVADER_COLS 8
|
131
|
|
- #undef INVASION_SIZE
|
132
|
|
- #define INVASION_SIZE 5
|
133
|
|
-#endif
|
134
|
|
-
|
135
|
|
-#define INVADER_ROWS INVASION_SIZE
|
136
|
|
-
|
137
|
145
|
constexpr uint8_t inv_type[] = {
|
138
|
146
|
#if INVADER_ROWS == 5
|
139
|
147
|
0, 1, 1, 2, 2
|
|
@@ -146,107 +154,74 @@ constexpr uint8_t inv_type[] = {
|
146
|
154
|
#endif
|
147
|
155
|
};
|
148
|
156
|
|
149
|
|
-#define INVADER_RIGHT ((INVADER_COLS) * (COL_W))
|
|
157
|
+invaders_data_t &idat = marlin_game_data.invaders;
|
150
|
158
|
|
151
|
|
-#define CANNON_W 11
|
152
|
|
-#define CANNON_H 8
|
153
|
|
-#define CANNON_VEL 4
|
154
|
|
-#define CANNON_Y (LCD_PIXEL_HEIGHT - 1 - CANNON_H)
|
155
|
|
-
|
156
|
|
-#define COL_W 14
|
157
|
|
-#define INVADER_H 8
|
158
|
|
-#define ROW_H (INVADER_H + 2)
|
159
|
|
-#define INVADER_VEL 3
|
160
|
|
-
|
161
|
|
-#define INVADER_TOP MENU_FONT_ASCENT
|
162
|
|
-#define INVADERS_WIDE ((COL_W) * (INVADER_COLS))
|
163
|
|
-#define INVADERS_HIGH ((ROW_H) * (INVADER_ROWS))
|
164
|
|
-
|
165
|
|
-#define UFO_H 5
|
166
|
|
-#define UFO_W 13
|
167
|
|
-
|
168
|
|
-#define LASER_H 4
|
169
|
|
-#define SHOT_H 3
|
170
|
|
-#define EXPL_W 11
|
171
|
|
-#define LIFE_W 8
|
172
|
|
-#define LIFE_H 5
|
173
|
|
-
|
174
|
|
-#define INVADER_COL(X) ((X - invaders_x) / (COL_W))
|
175
|
|
-#define INVADER_ROW(Y) ((Y - invaders_y + 2) / (ROW_H))
|
176
|
|
-
|
177
|
|
-#define INV_X_LEFT(C,T) (invaders_x + (C) * (COL_W) + inv_off[T])
|
|
159
|
+#define INV_X_LEFT(C,T) (idat.pos.x + (C) * (INVADER_COL_W) + inv_off[T])
|
178
|
160
|
#define INV_X_CTR(C,T) (INV_X_LEFT(C,T) + inv_wide[T] / 2)
|
179
|
|
-#define INV_Y_BOT(R) (invaders_y + (R + 1) * (ROW_H) - 2)
|
180
|
|
-
|
181
|
|
-typedef struct { int8_t x, y, v; } laser_t;
|
|
161
|
+#define INV_Y_BOT(R) (idat.pos.y + (R + 1) * (INVADER_ROW_H) - 2)
|
182
|
162
|
|
183
|
|
-uint8_t cannons_left;
|
184
|
|
-int8_t cannon_x;
|
185
|
|
-laser_t explod, laser, bullet[10];
|
186
|
163
|
constexpr uint8_t inv_off[] = { 2, 1, 0 }, inv_wide[] = { 8, 11, 12 };
|
187
|
|
-int8_t invaders_x, invaders_y, invaders_dir, leftmost, rightmost, botmost;
|
188
|
|
-uint8_t invader_count, quit_count, bugs[INVADER_ROWS], shooters[(INVADER_ROWS) * (INVADER_COLS)];
|
189
|
164
|
|
190
|
165
|
inline void update_invader_data() {
|
191
|
166
|
uint8_t inv_mask = 0;
|
192
|
167
|
// Get a list of all active invaders
|
193
|
168
|
uint8_t sc = 0;
|
194
|
169
|
LOOP_L_N(y, INVADER_ROWS) {
|
195
|
|
- uint8_t m = bugs[y];
|
196
|
|
- if (m) botmost = y + 1;
|
|
170
|
+ uint8_t m = idat.bugs[y];
|
|
171
|
+ if (m) idat.botmost = y + 1;
|
197
|
172
|
inv_mask |= m;
|
198
|
173
|
for (uint8_t x = 0; x < INVADER_COLS; ++x)
|
199
|
|
- if (TEST(m, x)) shooters[sc++] = (y << 4) | x;
|
|
174
|
+ if (TEST(m, x)) idat.shooters[sc++] = (y << 4) | x;
|
200
|
175
|
}
|
201
|
|
- leftmost = 0;
|
202
|
|
- LOOP_L_N(i, INVADER_COLS) { if (TEST(inv_mask, i)) break; leftmost -= COL_W; }
|
203
|
|
- rightmost = LCD_PIXEL_WIDTH - (INVADERS_WIDE);
|
204
|
|
- for (uint8_t i = INVADER_COLS; i--;) { if (TEST(inv_mask, i)) break; rightmost += COL_W; }
|
205
|
|
- if (invader_count == 2) invaders_dir = invaders_dir > 0 ? INVADER_VEL + 1 : -(INVADER_VEL + 1);
|
|
176
|
+ idat.leftmost = 0;
|
|
177
|
+ LOOP_L_N(i, INVADER_COLS) { if (TEST(inv_mask, i)) break; idat.leftmost -= INVADER_COL_W; }
|
|
178
|
+ idat.rightmost = LCD_PIXEL_WIDTH - (INVADERS_WIDE);
|
|
179
|
+ for (uint8_t i = INVADER_COLS; i--;) { if (TEST(inv_mask, i)) break; idat.rightmost += INVADER_COL_W; }
|
|
180
|
+ if (idat.count == 2) idat.dir = idat.dir > 0 ? INVADER_VEL + 1 : -(INVADER_VEL + 1);
|
206
|
181
|
}
|
207
|
182
|
|
208
|
183
|
inline void reset_bullets() {
|
209
|
|
- LOOP_L_N(i, COUNT(bullet)) bullet[i].v = 0;
|
|
184
|
+ LOOP_L_N(i, COUNT(idat.bullet)) idat.bullet[i].v = 0;
|
210
|
185
|
}
|
211
|
186
|
|
212
|
187
|
inline void reset_invaders() {
|
213
|
|
- invaders_x = 0; invaders_y = INVADER_TOP;
|
214
|
|
- invaders_dir = INVADER_VEL;
|
215
|
|
- invader_count = (INVADER_COLS) * (INVADER_ROWS);
|
216
|
|
- LOOP_L_N(i, INVADER_ROWS) bugs[i] = _BV(INVADER_COLS) - 1;
|
|
188
|
+ idat.pos.x = 0; idat.pos.y = INVADER_TOP;
|
|
189
|
+ idat.dir = INVADER_VEL;
|
|
190
|
+ idat.count = (INVADER_COLS) * (INVADER_ROWS);
|
|
191
|
+ LOOP_L_N(i, INVADER_ROWS) idat.bugs[i] = _BV(INVADER_COLS) - 1;
|
217
|
192
|
update_invader_data();
|
218
|
193
|
reset_bullets();
|
219
|
194
|
}
|
220
|
195
|
|
221
|
|
-int8_t ufox, ufov;
|
|
196
|
+
|
222
|
197
|
inline void spawn_ufo() {
|
223
|
|
- ufov = random(0, 2) ? 1 : -1;
|
224
|
|
- ufox = ufov > 0 ? -(UFO_W) : LCD_PIXEL_WIDTH - 1;
|
|
198
|
+ idat.ufov = random(0, 2) ? 1 : -1;
|
|
199
|
+ idat.ufox = idat.ufov > 0 ? -(UFO_W) : LCD_PIXEL_WIDTH - 1;
|
225
|
200
|
}
|
226
|
201
|
|
227
|
202
|
inline void reset_player() {
|
228
|
|
- cannon_x = 0;
|
|
203
|
+ idat.cannon_x = 0;
|
229
|
204
|
ui.encoderPosition = 0;
|
230
|
205
|
}
|
231
|
206
|
|
232
|
207
|
inline void fire_cannon() {
|
233
|
|
- laser.x = cannon_x + CANNON_W / 2;
|
234
|
|
- laser.y = LCD_PIXEL_HEIGHT - CANNON_H - (LASER_H);
|
235
|
|
- laser.v = -(LASER_H);
|
|
208
|
+ idat.laser.x = idat.cannon_x + CANNON_W / 2;
|
|
209
|
+ idat.laser.y = LCD_PIXEL_HEIGHT - CANNON_H - (LASER_H);
|
|
210
|
+ idat.laser.v = -(LASER_H);
|
236
|
211
|
}
|
237
|
212
|
|
238
|
213
|
inline void explode(const int8_t x, const int8_t y, const int8_t v=4) {
|
239
|
|
- explod.x = x - (EXPL_W) / 2;
|
240
|
|
- explod.y = y;
|
241
|
|
- explod.v = v;
|
|
214
|
+ idat.explod.x = x - (EXPL_W) / 2;
|
|
215
|
+ idat.explod.y = y;
|
|
216
|
+ idat.explod.v = v;
|
242
|
217
|
}
|
243
|
218
|
|
244
|
219
|
inline void kill_cannon(uint8_t &game_state, const uint8_t st) {
|
245
|
220
|
reset_bullets();
|
246
|
|
- explode(cannon_x + (CANNON_W) / 2, CANNON_Y, 6);
|
|
221
|
+ explode(idat.cannon_x + (CANNON_W) / 2, CANNON_Y, 6);
|
247
|
222
|
_BUZZ(1000, 10);
|
248
|
|
- if (--cannons_left) {
|
249
|
|
- laser.v = 0;
|
|
223
|
+ if (--idat.cannons_left) {
|
|
224
|
+ idat.laser.v = 0;
|
250
|
225
|
game_state = st;
|
251
|
226
|
reset_player();
|
252
|
227
|
}
|
|
@@ -255,8 +230,6 @@ inline void kill_cannon(uint8_t &game_state, const uint8_t st) {
|
255
|
230
|
}
|
256
|
231
|
|
257
|
232
|
void InvadersGame::game_screen() {
|
258
|
|
- static bool game_blink;
|
259
|
|
-
|
260
|
233
|
ui.refresh(LCDVIEW_CALL_NO_REDRAW); // Call as often as possible
|
261
|
234
|
|
262
|
235
|
// Run game logic once per full screen
|
|
@@ -267,46 +240,45 @@ void InvadersGame::game_screen() {
|
267
|
240
|
ui.encoderPosition = ep;
|
268
|
241
|
|
269
|
242
|
ep *= (CANNON_VEL);
|
270
|
|
- if (ep > cannon_x) { cannon_x += CANNON_VEL - 1; if (ep - cannon_x < 2) cannon_x = ep; }
|
271
|
|
- if (ep < cannon_x) { cannon_x -= CANNON_VEL - 1; if (cannon_x - ep < 2) cannon_x = ep; }
|
|
243
|
+ if (ep > idat.cannon_x) { idat.cannon_x += CANNON_VEL - 1; if (ep - idat.cannon_x < 2) idat.cannon_x = ep; }
|
|
244
|
+ if (ep < idat.cannon_x) { idat.cannon_x -= CANNON_VEL - 1; if (idat.cannon_x - ep < 2) idat.cannon_x = ep; }
|
272
|
245
|
|
273
|
246
|
// Run the game logic
|
274
|
247
|
if (game_state) do {
|
275
|
248
|
|
276
|
249
|
// Move the UFO, if any
|
277
|
|
- if (ufov) { ufox += ufov; if (!WITHIN(ufox, -(UFO_W), LCD_PIXEL_WIDTH - 1)) ufov = 0; }
|
|
250
|
+ if (idat.ufov) { idat.ufox += idat.ufov; if (!WITHIN(idat.ufox, -(UFO_W), LCD_PIXEL_WIDTH - 1)) idat.ufov = 0; }
|
278
|
251
|
|
279
|
252
|
if (game_state > 1) { if (--game_state == 2) { reset_invaders(); } else if (game_state == 100) { game_state = 1; } break; }
|
280
|
253
|
|
281
|
|
- static uint8_t blink_count;
|
282
|
|
- const bool did_blink = (++blink_count > invader_count >> 1);
|
|
254
|
+ const bool did_blink = (++idat.blink_count > idat.count >> 1);
|
283
|
255
|
if (did_blink) {
|
284
|
|
- game_blink = !game_blink;
|
285
|
|
- blink_count = 0;
|
|
256
|
+ idat.game_blink = !idat.game_blink;
|
|
257
|
+ idat.blink_count = 0;
|
286
|
258
|
}
|
287
|
259
|
|
288
|
|
- if (invader_count && did_blink) {
|
289
|
|
- const int8_t newx = invaders_x + invaders_dir;
|
290
|
|
- if (!WITHIN(newx, leftmost, rightmost)) { // Invaders reached the edge?
|
291
|
|
- invaders_dir *= -1; // Invaders change direction
|
292
|
|
- invaders_y += (ROW_H) / 2; // Invaders move down
|
293
|
|
- invaders_x -= invaders_dir; // ...and only move down this time.
|
294
|
|
- if (invaders_y + botmost * (ROW_H) - 2 >= CANNON_Y) // Invaders reached the bottom?
|
295
|
|
- kill_cannon(game_state, 20); // Kill the cannon. Reset invaders.
|
|
260
|
+ if (idat.count && did_blink) {
|
|
261
|
+ const int8_t newx = idat.pos.x + idat.dir;
|
|
262
|
+ if (!WITHIN(newx, idat.leftmost, idat.rightmost)) { // Invaders reached the edge?
|
|
263
|
+ idat.dir *= -1; // Invaders change direction
|
|
264
|
+ idat.pos.y += (INVADER_ROW_H) / 2; // Invaders move down
|
|
265
|
+ idat.pos.x -= idat.dir; // ...and only move down this time.
|
|
266
|
+ if (idat.pos.y + idat.botmost * (INVADER_ROW_H) - 2 >= CANNON_Y) // Invaders reached the bottom?
|
|
267
|
+ kill_cannon(game_state, 20); // Kill the cannon. Reset invaders.
|
296
|
268
|
}
|
297
|
269
|
|
298
|
|
- invaders_x += invaders_dir; // Invaders take one step left/right
|
|
270
|
+ idat.pos.x += idat.dir; // Invaders take one step left/right
|
299
|
271
|
|
300
|
272
|
// Randomly shoot if invaders are listed
|
301
|
|
- if (invader_count && !random(0, 20)) {
|
|
273
|
+ if (idat.count && !random(0, 20)) {
|
302
|
274
|
|
303
|
275
|
// Find a free bullet
|
304
|
276
|
laser_t *b = nullptr;
|
305
|
|
- LOOP_L_N(i, COUNT(bullet)) if (!bullet[i].v) { b = &bullet[i]; break; }
|
|
277
|
+ LOOP_L_N(i, COUNT(idat.bullet)) if (!idat.bullet[i].v) { b = &idat.bullet[i]; break; }
|
306
|
278
|
if (b) {
|
307
|
279
|
// Pick a random shooter and update the bullet
|
308
|
280
|
//SERIAL_ECHOLNPGM("free bullet found");
|
309
|
|
- const uint8_t inv = shooters[random(0, invader_count + 1)], col = inv & 0x0F, row = inv >> 4, type = inv_type[row];
|
|
281
|
+ const uint8_t inv = idat.shooters[random(0, idat.count + 1)], col = inv & 0x0F, row = inv >> 4, type = inv_type[row];
|
310
|
282
|
b->x = INV_X_CTR(col, type);
|
311
|
283
|
b->y = INV_Y_BOT(row);
|
312
|
284
|
b->v = 2 + random(0, 2);
|
|
@@ -315,34 +287,34 @@ void InvadersGame::game_screen() {
|
315
|
287
|
}
|
316
|
288
|
|
317
|
289
|
// Update the laser position
|
318
|
|
- if (laser.v) {
|
319
|
|
- laser.y += laser.v;
|
320
|
|
- if (laser.y < 0) laser.v = 0;
|
|
290
|
+ if (idat.laser.v) {
|
|
291
|
+ idat.laser.y += idat.laser.v;
|
|
292
|
+ if (idat.laser.y < 0) idat.laser.v = 0;
|
321
|
293
|
}
|
322
|
294
|
|
323
|
295
|
// Did the laser collide with an invader?
|
324
|
|
- if (laser.v && WITHIN(laser.y, invaders_y, invaders_y + INVADERS_HIGH - 1)) {
|
325
|
|
- const int8_t col = INVADER_COL(laser.x);
|
|
296
|
+ if (idat.laser.v && WITHIN(idat.laser.y, idat.pos.y, idat.pos.y + INVADERS_HIGH - 1)) {
|
|
297
|
+ const int8_t col = idat.laser_col();
|
326
|
298
|
if (WITHIN(col, 0, INVADER_COLS - 1)) {
|
327
|
|
- const int8_t row = INVADER_ROW(laser.y);
|
|
299
|
+ const int8_t row = idat.laser_row();
|
328
|
300
|
if (WITHIN(row, 0, INVADER_ROWS - 1)) {
|
329
|
301
|
const uint8_t mask = _BV(col);
|
330
|
|
- if (bugs[row] & mask) {
|
|
302
|
+ if (idat.bugs[row] & mask) {
|
331
|
303
|
const uint8_t type = inv_type[row];
|
332
|
304
|
const int8_t invx = INV_X_LEFT(col, type);
|
333
|
|
- if (WITHIN(laser.x, invx, invx + inv_wide[type] - 1)) {
|
|
305
|
+ if (WITHIN(idat.laser.x, invx, invx + inv_wide[type] - 1)) {
|
334
|
306
|
// Turn off laser
|
335
|
|
- laser.v = 0;
|
|
307
|
+ idat.laser.v = 0;
|
336
|
308
|
// Remove the invader!
|
337
|
|
- bugs[row] &= ~mask;
|
|
309
|
+ idat.bugs[row] &= ~mask;
|
338
|
310
|
// Score!
|
339
|
311
|
score += INVADER_ROWS - row;
|
340
|
312
|
// Explode sound!
|
341
|
313
|
_BUZZ(40, 10);
|
342
|
314
|
// Explosion bitmap!
|
343
|
|
- explode(invx + inv_wide[type] / 2, invaders_y + row * (ROW_H));
|
|
315
|
+ explode(invx + inv_wide[type] / 2, idat.pos.y + row * (INVADER_ROW_H));
|
344
|
316
|
// If invaders are gone, go to reset invaders state
|
345
|
|
- if (--invader_count) update_invader_data(); else { game_state = 20; reset_bullets(); }
|
|
317
|
+ if (--idat.count) update_invader_data(); else { game_state = 20; reset_bullets(); }
|
346
|
318
|
} // laser x hit
|
347
|
319
|
} // invader exists
|
348
|
320
|
} // good row
|
|
@@ -350,31 +322,31 @@ void InvadersGame::game_screen() {
|
350
|
322
|
} // laser in invader zone
|
351
|
323
|
|
352
|
324
|
// Handle alien bullets
|
353
|
|
- LOOP_L_N(s, COUNT(bullet)) {
|
354
|
|
- laser_t *b = &bullet[s];
|
|
325
|
+ LOOP_L_N(s, COUNT(idat.bullet)) {
|
|
326
|
+ laser_t *b = &idat.bullet[s];
|
355
|
327
|
if (b->v) {
|
356
|
328
|
// Update alien bullet position
|
357
|
329
|
b->y += b->v;
|
358
|
330
|
if (b->y >= LCD_PIXEL_HEIGHT)
|
359
|
331
|
b->v = 0; // Offscreen
|
360
|
|
- else if (b->y >= CANNON_Y && WITHIN(b->x, cannon_x, cannon_x + CANNON_W - 1))
|
|
332
|
+ else if (b->y >= CANNON_Y && WITHIN(b->x, idat.cannon_x, idat.cannon_x + CANNON_W - 1))
|
361
|
333
|
kill_cannon(game_state, 120); // Hit the cannon
|
362
|
334
|
}
|
363
|
335
|
}
|
364
|
336
|
|
365
|
337
|
// Randomly spawn a UFO
|
366
|
|
- if (!ufov && !random(0,500)) spawn_ufo();
|
|
338
|
+ if (!idat.ufov && !random(0,500)) spawn_ufo();
|
367
|
339
|
|
368
|
340
|
// Did the laser hit a ufo?
|
369
|
|
- if (laser.v && ufov && laser.y < UFO_H + 2 && WITHIN(laser.x, ufox, ufox + UFO_W - 1)) {
|
|
341
|
+ if (idat.laser.v && idat.ufov && idat.laser.y < UFO_H + 2 && WITHIN(idat.laser.x, idat.ufox, idat.ufox + UFO_W - 1)) {
|
370
|
342
|
// Turn off laser and UFO
|
371
|
|
- laser.v = ufov = 0;
|
|
343
|
+ idat.laser.v = idat.ufov = 0;
|
372
|
344
|
// Score!
|
373
|
345
|
score += 10;
|
374
|
346
|
// Explode!
|
375
|
347
|
_BUZZ(40, 10);
|
376
|
348
|
// Explosion bitmap
|
377
|
|
- explode(ufox + (UFO_W) / 2, 1);
|
|
349
|
+ explode(idat.ufox + (UFO_W) / 2, 1);
|
378
|
350
|
}
|
379
|
351
|
|
380
|
352
|
} while (false);
|
|
@@ -382,59 +354,59 @@ void InvadersGame::game_screen() {
|
382
|
354
|
}
|
383
|
355
|
|
384
|
356
|
// Click-and-hold to abort
|
385
|
|
- if (ui.button_pressed()) --quit_count; else quit_count = 10;
|
|
357
|
+ if (ui.button_pressed()) --idat.quit_count; else idat.quit_count = 10;
|
386
|
358
|
|
387
|
359
|
// Click to fire or exit
|
388
|
360
|
if (ui.use_click()) {
|
389
|
361
|
if (!game_state)
|
390
|
|
- quit_count = 0;
|
391
|
|
- else if (game_state == 1 && !laser.v)
|
|
362
|
+ idat.quit_count = 0;
|
|
363
|
+ else if (game_state == 1 && !idat.laser.v)
|
392
|
364
|
fire_cannon();
|
393
|
365
|
}
|
394
|
366
|
|
395
|
|
- if (!quit_count) exit_game();
|
|
367
|
+ if (!idat.quit_count) exit_game();
|
396
|
368
|
|
397
|
369
|
u8g.setColorIndex(1);
|
398
|
370
|
|
399
|
371
|
// Draw invaders
|
400
|
|
- if (PAGE_CONTAINS(invaders_y, invaders_y + botmost * (ROW_H) - 2 - 1)) {
|
401
|
|
- int8_t yy = invaders_y;
|
|
372
|
+ if (PAGE_CONTAINS(idat.pos.y, idat.pos.y + idat.botmost * (INVADER_ROW_H) - 2 - 1)) {
|
|
373
|
+ int8_t yy = idat.pos.y;
|
402
|
374
|
for (uint8_t y = 0; y < INVADER_ROWS; ++y) {
|
403
|
375
|
const uint8_t type = inv_type[y];
|
404
|
376
|
if (PAGE_CONTAINS(yy, yy + INVADER_H - 1)) {
|
405
|
|
- int8_t xx = invaders_x;
|
|
377
|
+ int8_t xx = idat.pos.x;
|
406
|
378
|
for (uint8_t x = 0; x < INVADER_COLS; ++x) {
|
407
|
|
- if (TEST(bugs[y], x))
|
408
|
|
- u8g.drawBitmapP(xx, yy, 2, INVADER_H, invader[type][game_blink]);
|
409
|
|
- xx += COL_W;
|
|
379
|
+ if (TEST(idat.bugs[y], x))
|
|
380
|
+ u8g.drawBitmapP(xx, yy, 2, INVADER_H, invader[type][idat.game_blink]);
|
|
381
|
+ xx += INVADER_COL_W;
|
410
|
382
|
}
|
411
|
383
|
}
|
412
|
|
- yy += ROW_H;
|
|
384
|
+ yy += INVADER_ROW_H;
|
413
|
385
|
}
|
414
|
386
|
}
|
415
|
387
|
|
416
|
388
|
// Draw UFO
|
417
|
|
- if (ufov && PAGE_UNDER(UFO_H + 2))
|
418
|
|
- u8g.drawBitmapP(ufox, 2, 2, UFO_H, ufo);
|
|
389
|
+ if (idat.ufov && PAGE_UNDER(UFO_H + 2))
|
|
390
|
+ u8g.drawBitmapP(idat.ufox, 2, 2, UFO_H, ufo);
|
419
|
391
|
|
420
|
392
|
// Draw cannon
|
421
|
393
|
if (game_state && PAGE_CONTAINS(CANNON_Y, CANNON_Y + CANNON_H - 1) && (game_state < 2 || (game_state & 0x02)))
|
422
|
|
- u8g.drawBitmapP(cannon_x, CANNON_Y, 2, CANNON_H, cannon);
|
|
394
|
+ u8g.drawBitmapP(idat.cannon_x, CANNON_Y, 2, CANNON_H, cannon);
|
423
|
395
|
|
424
|
396
|
// Draw laser
|
425
|
|
- if (laser.v && PAGE_CONTAINS(laser.y, laser.y + LASER_H - 1))
|
426
|
|
- u8g.drawVLine(laser.x, laser.y, LASER_H);
|
|
397
|
+ if (idat.laser.v && PAGE_CONTAINS(idat.laser.y, idat.laser.y + LASER_H - 1))
|
|
398
|
+ u8g.drawVLine(idat.laser.x, idat.laser.y, LASER_H);
|
427
|
399
|
|
428
|
400
|
// Draw invader bullets
|
429
|
|
- LOOP_L_N (i, COUNT(bullet)) {
|
430
|
|
- if (bullet[i].v && PAGE_CONTAINS(bullet[i].y - (SHOT_H - 1), bullet[i].y))
|
431
|
|
- u8g.drawVLine(bullet[i].x, bullet[i].y - (SHOT_H - 1), SHOT_H);
|
|
401
|
+ LOOP_L_N (i, COUNT(idat.bullet)) {
|
|
402
|
+ if (idat.bullet[i].v && PAGE_CONTAINS(idat.bullet[i].y - (SHOT_H - 1), idat.bullet[i].y))
|
|
403
|
+ u8g.drawVLine(idat.bullet[i].x, idat.bullet[i].y - (SHOT_H - 1), SHOT_H);
|
432
|
404
|
}
|
433
|
405
|
|
434
|
406
|
// Draw explosion
|
435
|
|
- if (explod.v && PAGE_CONTAINS(explod.y, explod.y + 7 - 1)) {
|
436
|
|
- u8g.drawBitmapP(explod.x, explod.y, 2, 7, explosion);
|
437
|
|
- --explod.v;
|
|
407
|
+ if (idat.explod.v && PAGE_CONTAINS(idat.explod.y, idat.explod.y + 7 - 1)) {
|
|
408
|
+ u8g.drawBitmapP(idat.explod.x, idat.explod.y, 2, 7, explosion);
|
|
409
|
+ --idat.explod.v;
|
438
|
410
|
}
|
439
|
411
|
|
440
|
412
|
// Blink GAME OVER when game is over
|
|
@@ -448,8 +420,8 @@ void InvadersGame::game_screen() {
|
448
|
420
|
lcd_put_int(score);
|
449
|
421
|
|
450
|
422
|
// Draw lives
|
451
|
|
- if (cannons_left)
|
452
|
|
- for (uint8_t i = 1; i <= cannons_left; ++i)
|
|
423
|
+ if (idat.cannons_left)
|
|
424
|
+ for (uint8_t i = 1; i <= idat.cannons_left; ++i)
|
453
|
425
|
u8g.drawBitmapP(LCD_PIXEL_WIDTH - i * (LIFE_W), 6 - (LIFE_H), 1, LIFE_H, life);
|
454
|
426
|
}
|
455
|
427
|
|
|
@@ -457,9 +429,9 @@ void InvadersGame::game_screen() {
|
457
|
429
|
|
458
|
430
|
void InvadersGame::enter_game() {
|
459
|
431
|
init_game(20, game_screen); // countdown to reset invaders
|
460
|
|
- cannons_left = 3;
|
461
|
|
- quit_count = 10;
|
462
|
|
- laser.v = 0;
|
|
432
|
+ idat.cannons_left = 3;
|
|
433
|
+ idat.quit_count = 10;
|
|
434
|
+ idat.laser.v = 0;
|
463
|
435
|
reset_invaders();
|
464
|
436
|
reset_player();
|
465
|
437
|
}
|