mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
BrickGame: Stop bricks from falling when paused
Allows for pausing with either the `P` or `Escape` keys. In this commit you can still rotate pieces when paused - which makes for an interesting "stop-time" cheat mechanic, but probably isn't yet what we want.
This commit is contained in:
parent
dfb45705e6
commit
06a9e4280b
Notes:
sideshowbarker
2024-07-18 22:57:59 +09:00
Author: https://github.com/karolba Commit: https://github.com/SerenityOS/serenity/commit/06a9e4280b Pull-request: https://github.com/SerenityOS/serenity/pull/17781 Reviewed-by: https://github.com/MacDue ✅
1 changed files with 28 additions and 4 deletions
|
@ -246,6 +246,7 @@ class Bricks final {
|
|||
public:
|
||||
enum class GameState {
|
||||
Active,
|
||||
Paused,
|
||||
GameOver
|
||||
};
|
||||
|
||||
|
@ -316,6 +317,20 @@ public:
|
|||
return RenderRequest::RequestUpdate;
|
||||
}
|
||||
|
||||
void toggle_pause()
|
||||
{
|
||||
switch (m_state) {
|
||||
case GameState::Active:
|
||||
m_state = GameState::Paused;
|
||||
break;
|
||||
case GameState::Paused:
|
||||
m_state = GameState::Active;
|
||||
break;
|
||||
case GameState::GameOver:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] RenderRequest update()
|
||||
{
|
||||
auto const current_level { m_level };
|
||||
|
@ -433,12 +448,17 @@ void BrickGame::reset()
|
|||
|
||||
void BrickGame::timer_event(Core::TimerEvent&)
|
||||
{
|
||||
if (m_brick_game->state() == Bricks::GameState::GameOver) {
|
||||
switch (m_brick_game->state()) {
|
||||
case Bricks::GameState::GameOver:
|
||||
game_over();
|
||||
return;
|
||||
break;
|
||||
case Bricks::GameState::Active:
|
||||
if (m_brick_game->update() == Bricks::RenderRequest::RequestUpdate)
|
||||
update();
|
||||
break;
|
||||
case Bricks::GameState::Paused:
|
||||
break;
|
||||
}
|
||||
if (m_brick_game->update() == Bricks::RenderRequest::RequestUpdate)
|
||||
update();
|
||||
}
|
||||
|
||||
void BrickGame::keydown_event(GUI::KeyEvent& event)
|
||||
|
@ -470,6 +490,10 @@ void BrickGame::keydown_event(GUI::KeyEvent& event)
|
|||
case KeyCode::Key_Space:
|
||||
render_request = m_brick_game->move_down_fast();
|
||||
break;
|
||||
case KeyCode::Key_Escape:
|
||||
case KeyCode::Key_P:
|
||||
m_brick_game->toggle_pause();
|
||||
break;
|
||||
default:
|
||||
event.ignore();
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue