mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:17:44 +00:00
FlappyBug: Support mouse clicks for flapping
This change allows to play the game using the mouse.
This commit is contained in:
parent
a099a77e82
commit
913b1fad25
2 changed files with 18 additions and 6 deletions
|
@ -85,14 +85,24 @@ void Game::keydown_event(GUI::KeyEvent& event)
|
||||||
GUI::Application::the()->quit();
|
GUI::Application::the()->quit();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
player_input();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Game::mousedown_event(GUI::MouseEvent&)
|
||||||
|
{
|
||||||
|
player_input();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Game::player_input()
|
||||||
|
{
|
||||||
if (ready_to_start()) {
|
if (ready_to_start()) {
|
||||||
m_active = true;
|
m_active = true;
|
||||||
}
|
}
|
||||||
if (m_active) {
|
if (m_active) {
|
||||||
m_bug.flap();
|
m_bug.flap();
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::tick()
|
void Game::tick()
|
||||||
|
|
|
@ -32,12 +32,14 @@ private:
|
||||||
|
|
||||||
virtual void paint_event(GUI::PaintEvent&) override;
|
virtual void paint_event(GUI::PaintEvent&) override;
|
||||||
virtual void keydown_event(GUI::KeyEvent&) override;
|
virtual void keydown_event(GUI::KeyEvent&) override;
|
||||||
|
virtual void mousedown_event(GUI::MouseEvent&) override;
|
||||||
virtual void timer_event(Core::TimerEvent&) override;
|
virtual void timer_event(Core::TimerEvent&) override;
|
||||||
|
|
||||||
void tick();
|
void tick();
|
||||||
void reset();
|
void reset();
|
||||||
void game_over();
|
void game_over();
|
||||||
bool ready_to_start() const;
|
bool ready_to_start() const;
|
||||||
|
void player_input();
|
||||||
|
|
||||||
struct Bug {
|
struct Bug {
|
||||||
const float x { 50 };
|
const float x { 50 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue