Browse Source

Click-hold to exit Invaders, fix Brickout compile

Scott Lahteine 6 years ago
parent
commit
83e214478e

+ 3
- 3
Marlin/src/lcd/menu/game/brickout.cpp View File

@@ -65,7 +65,7 @@ void reset_ball() {
65 65
 }
66 66
 
67 67
 void BrickoutGame::game_screen() {
68
-  if (game_frame()) do {     // Run logic twice for finer resolution
68
+  if (game_frame()) {     // Run logic twice for finer resolution
69 69
     // Update Paddle Position
70 70
     paddle_x = (int8_t)ui.encoderPosition;
71 71
     paddle_x = constrain(paddle_x, 0, (LCD_PIXEL_WIDTH - (PADDLE_W)) / (PADDLE_VEL));
@@ -75,7 +75,7 @@ void BrickoutGame::game_screen() {
75 75
     // Run the ball logic
76 76
     if (game_state) do {
77 77
 
78
-      // Provisionally update the position
78
+      // Provisionally update the ball position
79 79
       const fixed_t newx = ballx + ballh, newy = bally + ballv;  // current next position
80 80
       if (!WITHIN(newx, 0, BTOF(LCD_PIXEL_WIDTH - 1))) {    // out in x?
81 81
         ballh = -ballh; _BUZZ(5, 220);                      // bounce x
@@ -197,7 +197,7 @@ void BrickoutGame::game_screen() {
197 197
   }
198 198
 
199 199
   // A click always exits this game
200
-  if (ui.use_click()) ui.goto_previous_screen();
200
+  if (ui.use_click()) exit_game();
201 201
 }
202 202
 
203 203
 void BrickoutGame::enter_game() {

+ 4
- 1
Marlin/src/lcd/menu/game/game.cpp View File

@@ -61,6 +61,9 @@ void MarlinGame::init_game(const uint8_t init_state, const screenFunc_t screen)
61 61
   ui.defer_status_screen();
62 62
 }
63 63
 
64
-//void MarlinGame::exit_game() { ui.goto_previous_screen(); }
64
+void MarlinGame::exit_game() {
65
+  ui.goto_previous_screen();
66
+  ui.defer_status_screen(false);
67
+}
65 68
 
66 69
 #endif // HAS_GAMES

+ 1
- 1
Marlin/src/lcd/menu/game/game.h View File

@@ -55,8 +55,8 @@ protected:
55 55
 
56 56
   static bool game_frame();
57 57
   static void draw_game_over();
58
+  static void exit_game();
58 59
 public:
59
-  MarlinGame() {}
60 60
   static void init_game(const uint8_t init_state, const screenFunc_t screen);
61 61
 };
62 62
 

+ 8
- 2
Marlin/src/lcd/menu/game/invaders.cpp View File

@@ -185,7 +185,7 @@ int8_t cannon_x;
185 185
 laser_t laser, expl, bullet[10];
186 186
 constexpr uint8_t inv_off[] = { 2, 1, 0 }, inv_wide[] = { 8, 11, 12 };
187 187
 int8_t invaders_x, invaders_y, invaders_dir, leftmost, rightmost, botmost;
188
-uint8_t invader_count, bugs[INVADER_ROWS], shooters[(INVADER_ROWS) * (INVADER_COLS)];
188
+uint8_t invader_count, quit_count, bugs[INVADER_ROWS], shooters[(INVADER_ROWS) * (INVADER_COLS)];
189 189
 
190 190
 inline void update_invader_data() {
191 191
   uint8_t inv_mask = 0;
@@ -380,14 +380,19 @@ void InvadersGame::game_screen() {
380 380
 
381 381
   }
382 382
 
383
+  // Click-and-hold to abort
384
+  if (ui.button_pressed()) --quit_count; else quit_count = 10;
385
+
383 386
   // Click to fire or exit
384 387
   if (ui.use_click()) {
385 388
     if (!game_state)
386
-      ui.goto_previous_screen();
389
+      quit_count = 0;
387 390
     else if (game_state == 1 && !laser.v)
388 391
       fire_cannon();
389 392
   }
390 393
 
394
+  if (!quit_count) exit_game();
395
+
391 396
   u8g.setColorIndex(1);
392 397
 
393 398
   // Draw invaders
@@ -452,6 +457,7 @@ void InvadersGame::game_screen() {
452 457
 void InvadersGame::enter_game() {
453 458
   init_game(20, game_screen); // countdown to reset invaders
454 459
   cannons_left = 3;
460
+  quit_count = 10;
455 461
   laser.v = 0;
456 462
   reset_invaders();
457 463
   reset_player();

+ 1
- 1
Marlin/src/lcd/menu/game/maze.cpp View File

@@ -125,7 +125,7 @@ void MazeGame::game_screen() {
125 125
   if (!game_state) draw_game_over();
126 126
 
127 127
   // A click always exits this game
128
-  if (ui.use_click()) ui.goto_previous_screen();
128
+  if (ui.use_click()) exit_game();
129 129
 }
130 130
 
131 131
 void MazeGame::enter_game() {

+ 1
- 1
Marlin/src/lcd/menu/game/snake.cpp View File

@@ -322,7 +322,7 @@ void SnakeGame::game_screen() {
322 322
   if (!game_state) draw_game_over();
323 323
 
324 324
   // A click always exits this game
325
-  if (ui.use_click()) ui.goto_previous_screen();
325
+  if (ui.use_click()) exit_game();
326 326
 }
327 327
 
328 328
 void SnakeGame::enter_game() {

Loading…
Cancel
Save