summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorPedro Pereira <pmh.pereira@gmail.com>2021-11-23 00:53:52 +0000
committerBrian Gianforcaro <b.gianfo@gmail.com>2021-11-24 21:18:31 -0800
commit913b1fad25f994982edf607fe0110710347c2381 (patch)
treecee25cdc16936c81090a6b8b15a63f376c893fc2 /Userland
parenta099a77e821724afcd36840f457727ba21e27a45 (diff)
downloadserenity-913b1fad25f994982edf607fe0110710347c2381.zip
FlappyBug: Support mouse clicks for flapping
This change allows to play the game using the mouse.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Games/FlappyBug/Game.cpp22
-rw-r--r--Userland/Games/FlappyBug/Game.h2
2 files changed, 18 insertions, 6 deletions
diff --git a/Userland/Games/FlappyBug/Game.cpp b/Userland/Games/FlappyBug/Game.cpp
index f174bd9193..02344d7f85 100644
--- a/Userland/Games/FlappyBug/Game.cpp
+++ b/Userland/Games/FlappyBug/Game.cpp
@@ -85,16 +85,26 @@ void Game::keydown_event(GUI::KeyEvent& event)
GUI::Application::the()->quit();
break;
default:
- if (ready_to_start()) {
- m_active = true;
- }
- if (m_active) {
- m_bug.flap();
- }
+ player_input();
break;
}
}
+void Game::mousedown_event(GUI::MouseEvent&)
+{
+ player_input();
+}
+
+void Game::player_input()
+{
+ if (ready_to_start()) {
+ m_active = true;
+ }
+ if (m_active) {
+ m_bug.flap();
+ }
+}
+
void Game::tick()
{
auto queue_update = [&]() {
diff --git a/Userland/Games/FlappyBug/Game.h b/Userland/Games/FlappyBug/Game.h
index a9b0fd963b..f3055f475e 100644
--- a/Userland/Games/FlappyBug/Game.h
+++ b/Userland/Games/FlappyBug/Game.h
@@ -32,12 +32,14 @@ private:
virtual void paint_event(GUI::PaintEvent&) override;
virtual void keydown_event(GUI::KeyEvent&) override;
+ virtual void mousedown_event(GUI::MouseEvent&) override;
virtual void timer_event(Core::TimerEvent&) override;
void tick();
void reset();
void game_over();
bool ready_to_start() const;
+ void player_input();
struct Bug {
const float x { 50 };