Click-hold to exit Invaders, fix Brickout compile
This commit is contained in:
parent
240ea1bbb3
commit
83e214478e
6 changed files with 18 additions and 9 deletions
|
@ -65,7 +65,7 @@ void reset_ball() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrickoutGame::game_screen() {
|
void BrickoutGame::game_screen() {
|
||||||
if (game_frame()) do { // Run logic twice for finer resolution
|
if (game_frame()) { // Run logic twice for finer resolution
|
||||||
// Update Paddle Position
|
// Update Paddle Position
|
||||||
paddle_x = (int8_t)ui.encoderPosition;
|
paddle_x = (int8_t)ui.encoderPosition;
|
||||||
paddle_x = constrain(paddle_x, 0, (LCD_PIXEL_WIDTH - (PADDLE_W)) / (PADDLE_VEL));
|
paddle_x = constrain(paddle_x, 0, (LCD_PIXEL_WIDTH - (PADDLE_W)) / (PADDLE_VEL));
|
||||||
|
@ -75,7 +75,7 @@ void BrickoutGame::game_screen() {
|
||||||
// Run the ball logic
|
// Run the ball logic
|
||||||
if (game_state) do {
|
if (game_state) do {
|
||||||
|
|
||||||
// Provisionally update the position
|
// Provisionally update the ball position
|
||||||
const fixed_t newx = ballx + ballh, newy = bally + ballv; // current next position
|
const fixed_t newx = ballx + ballh, newy = bally + ballv; // current next position
|
||||||
if (!WITHIN(newx, 0, BTOF(LCD_PIXEL_WIDTH - 1))) { // out in x?
|
if (!WITHIN(newx, 0, BTOF(LCD_PIXEL_WIDTH - 1))) { // out in x?
|
||||||
ballh = -ballh; _BUZZ(5, 220); // bounce x
|
ballh = -ballh; _BUZZ(5, 220); // bounce x
|
||||||
|
@ -197,7 +197,7 @@ void BrickoutGame::game_screen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// A click always exits this game
|
// A click always exits this game
|
||||||
if (ui.use_click()) ui.goto_previous_screen();
|
if (ui.use_click()) exit_game();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrickoutGame::enter_game() {
|
void BrickoutGame::enter_game() {
|
||||||
|
|
|
@ -61,6 +61,9 @@ void MarlinGame::init_game(const uint8_t init_state, const screenFunc_t screen)
|
||||||
ui.defer_status_screen();
|
ui.defer_status_screen();
|
||||||
}
|
}
|
||||||
|
|
||||||
//void MarlinGame::exit_game() { ui.goto_previous_screen(); }
|
void MarlinGame::exit_game() {
|
||||||
|
ui.goto_previous_screen();
|
||||||
|
ui.defer_status_screen(false);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // HAS_GAMES
|
#endif // HAS_GAMES
|
||||||
|
|
|
@ -55,8 +55,8 @@ protected:
|
||||||
|
|
||||||
static bool game_frame();
|
static bool game_frame();
|
||||||
static void draw_game_over();
|
static void draw_game_over();
|
||||||
|
static void exit_game();
|
||||||
public:
|
public:
|
||||||
MarlinGame() {}
|
|
||||||
static void init_game(const uint8_t init_state, const screenFunc_t screen);
|
static void init_game(const uint8_t init_state, const screenFunc_t screen);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -185,7 +185,7 @@ int8_t cannon_x;
|
||||||
laser_t laser, expl, bullet[10];
|
laser_t laser, expl, bullet[10];
|
||||||
constexpr uint8_t inv_off[] = { 2, 1, 0 }, inv_wide[] = { 8, 11, 12 };
|
constexpr uint8_t inv_off[] = { 2, 1, 0 }, inv_wide[] = { 8, 11, 12 };
|
||||||
int8_t invaders_x, invaders_y, invaders_dir, leftmost, rightmost, botmost;
|
int8_t invaders_x, invaders_y, invaders_dir, leftmost, rightmost, botmost;
|
||||||
uint8_t invader_count, bugs[INVADER_ROWS], shooters[(INVADER_ROWS) * (INVADER_COLS)];
|
uint8_t invader_count, quit_count, bugs[INVADER_ROWS], shooters[(INVADER_ROWS) * (INVADER_COLS)];
|
||||||
|
|
||||||
inline void update_invader_data() {
|
inline void update_invader_data() {
|
||||||
uint8_t inv_mask = 0;
|
uint8_t inv_mask = 0;
|
||||||
|
@ -380,14 +380,19 @@ void InvadersGame::game_screen() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Click-and-hold to abort
|
||||||
|
if (ui.button_pressed()) --quit_count; else quit_count = 10;
|
||||||
|
|
||||||
// Click to fire or exit
|
// Click to fire or exit
|
||||||
if (ui.use_click()) {
|
if (ui.use_click()) {
|
||||||
if (!game_state)
|
if (!game_state)
|
||||||
ui.goto_previous_screen();
|
quit_count = 0;
|
||||||
else if (game_state == 1 && !laser.v)
|
else if (game_state == 1 && !laser.v)
|
||||||
fire_cannon();
|
fire_cannon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!quit_count) exit_game();
|
||||||
|
|
||||||
u8g.setColorIndex(1);
|
u8g.setColorIndex(1);
|
||||||
|
|
||||||
// Draw invaders
|
// Draw invaders
|
||||||
|
@ -452,6 +457,7 @@ void InvadersGame::game_screen() {
|
||||||
void InvadersGame::enter_game() {
|
void InvadersGame::enter_game() {
|
||||||
init_game(20, game_screen); // countdown to reset invaders
|
init_game(20, game_screen); // countdown to reset invaders
|
||||||
cannons_left = 3;
|
cannons_left = 3;
|
||||||
|
quit_count = 10;
|
||||||
laser.v = 0;
|
laser.v = 0;
|
||||||
reset_invaders();
|
reset_invaders();
|
||||||
reset_player();
|
reset_player();
|
||||||
|
|
|
@ -125,7 +125,7 @@ void MazeGame::game_screen() {
|
||||||
if (!game_state) draw_game_over();
|
if (!game_state) draw_game_over();
|
||||||
|
|
||||||
// A click always exits this game
|
// A click always exits this game
|
||||||
if (ui.use_click()) ui.goto_previous_screen();
|
if (ui.use_click()) exit_game();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MazeGame::enter_game() {
|
void MazeGame::enter_game() {
|
||||||
|
|
|
@ -322,7 +322,7 @@ void SnakeGame::game_screen() {
|
||||||
if (!game_state) draw_game_over();
|
if (!game_state) draw_game_over();
|
||||||
|
|
||||||
// A click always exits this game
|
// A click always exits this game
|
||||||
if (ui.use_click()) ui.goto_previous_screen();
|
if (ui.use_click()) exit_game();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnakeGame::enter_game() {
|
void SnakeGame::enter_game() {
|
||||||
|
|
Reference in a new issue