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

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

61
   ui.defer_status_screen();
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
 #endif // HAS_GAMES
69
 #endif // HAS_GAMES

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

55
 
55
 
56
   static bool game_frame();
56
   static bool game_frame();
57
   static void draw_game_over();
57
   static void draw_game_over();
58
+  static void exit_game();
58
 public:
59
 public:
59
-  MarlinGame() {}
60
   static void init_game(const uint8_t init_state, const screenFunc_t screen);
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
 laser_t laser, expl, bullet[10];
185
 laser_t laser, expl, bullet[10];
186
 constexpr uint8_t inv_off[] = { 2, 1, 0 }, inv_wide[] = { 8, 11, 12 };
186
 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;
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
 inline void update_invader_data() {
190
 inline void update_invader_data() {
191
   uint8_t inv_mask = 0;
191
   uint8_t inv_mask = 0;
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
   // Click to fire or exit
386
   // Click to fire or exit
384
   if (ui.use_click()) {
387
   if (ui.use_click()) {
385
     if (!game_state)
388
     if (!game_state)
386
-      ui.goto_previous_screen();
389
+      quit_count = 0;
387
     else if (game_state == 1 && !laser.v)
390
     else if (game_state == 1 && !laser.v)
388
       fire_cannon();
391
       fire_cannon();
389
   }
392
   }
390
 
393
 
394
+  if (!quit_count) exit_game();
395
+
391
   u8g.setColorIndex(1);
396
   u8g.setColorIndex(1);
392
 
397
 
393
   // Draw invaders
398
   // Draw invaders
452
 void InvadersGame::enter_game() {
457
 void InvadersGame::enter_game() {
453
   init_game(20, game_screen); // countdown to reset invaders
458
   init_game(20, game_screen); // countdown to reset invaders
454
   cannons_left = 3;
459
   cannons_left = 3;
460
+  quit_count = 10;
455
   laser.v = 0;
461
   laser.v = 0;
456
   reset_invaders();
462
   reset_invaders();
457
   reset_player();
463
   reset_player();

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

125
   if (!game_state) draw_game_over();
125
   if (!game_state) draw_game_over();
126
 
126
 
127
   // A click always exits this game
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
 void MazeGame::enter_game() {
131
 void MazeGame::enter_game() {

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

322
   if (!game_state) draw_game_over();
322
   if (!game_state) draw_game_over();
323
 
323
 
324
   // A click always exits this game
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
 void SnakeGame::enter_game() {
328
 void SnakeGame::enter_game() {

Loading…
Cancel
Save