diff --git a/Base/res/icons/flappybug/background.png b/Base/res/icons/flappybug/background.png new file mode 100644 index 0000000000..6541413f21 Binary files /dev/null and b/Base/res/icons/flappybug/background.png differ diff --git a/Base/res/icons/flappybug/cloud_0.png b/Base/res/icons/flappybug/cloud_0.png new file mode 100644 index 0000000000..f8e4341b88 Binary files /dev/null and b/Base/res/icons/flappybug/cloud_0.png differ diff --git a/Base/res/icons/flappybug/cloud_1.png b/Base/res/icons/flappybug/cloud_1.png new file mode 100644 index 0000000000..834d33ebe3 Binary files /dev/null and b/Base/res/icons/flappybug/cloud_1.png differ diff --git a/Base/res/icons/flappybug/cloud_2.png b/Base/res/icons/flappybug/cloud_2.png new file mode 100644 index 0000000000..f49019058d Binary files /dev/null and b/Base/res/icons/flappybug/cloud_2.png differ diff --git a/Userland/Games/FlappyBug/Game.cpp b/Userland/Games/FlappyBug/Game.cpp index 4fe7344f11..c6174016c3 100644 --- a/Userland/Games/FlappyBug/Game.cpp +++ b/Userland/Games/FlappyBug/Game.cpp @@ -56,7 +56,9 @@ void Game::paint_event(GUI::PaintEvent& event) GUI::Painter painter(*this); painter.add_clip_rect(event.rect()); - painter.fill_rect(rect(), m_sky_color); + painter.draw_tiled_bitmap(rect(), *m_background_bitmap); + + painter.draw_scaled_bitmap(m_cloud.rect(), *m_cloud.bitmap(), m_cloud.bitmap()->rect(), 0.2f); painter.fill_rect(enclosing_int_rect(m_obstacle.top_rect()), m_obstacle.color); painter.fill_rect(enclosing_int_rect(m_obstacle.bottom_rect()), m_obstacle.color); @@ -98,6 +100,7 @@ void Game::tick() m_bug.fall(); m_bug.apply_velocity(); m_obstacle.x -= 4 + m_difficulty / 16.0f; + m_cloud.x -= m_difficulty / 16.0f; if (m_bug.y > game_height || m_bug.y < 0) { game_over(); @@ -110,6 +113,10 @@ void Game::tick() if (m_obstacle.x < 0) { m_obstacle.reset(); } + + if (m_cloud.x < 0) { + m_cloud.reset(); + } } m_restart_cooldown -= 1.0f / 16.0f; diff --git a/Userland/Games/FlappyBug/Game.h b/Userland/Games/FlappyBug/Game.h index 09876bdbfb..18d92dc118 100644 --- a/Userland/Games/FlappyBug/Game.h +++ b/Userland/Games/FlappyBug/Game.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -81,7 +82,7 @@ private: struct Obstacle { const float width { 20 }; Color color { Color::DarkGray }; - float x; + float x {}; float gap_top_y { 200 }; float gap_height { 175 }; @@ -102,14 +103,49 @@ private: } }; + struct Cloud { + const Vector> cloud_bitmaps { + Gfx::Bitmap::load_from_file("/res/icons/flappybug/cloud_0.png"), + Gfx::Bitmap::load_from_file("/res/icons/flappybug/cloud_1.png"), + Gfx::Bitmap::load_from_file("/res/icons/flappybug/cloud_2.png"), + }; + float x {}; + float y {}; + int bitmap_id {}; + + Cloud() + { + reset(); + x = get_random_uniform(game_width); + } + + void reset() + { + bitmap_id = get_random_uniform(cloud_bitmaps.size()); + x = game_width + bitmap()->width(); + y = get_random_uniform(game_height / 2) + bitmap()->height(); + } + + RefPtr bitmap() const + { + return cloud_bitmaps[bitmap_id]; + } + + Gfx::IntRect rect() const + { + return { (int)x - bitmap()->width(), (int)y - bitmap()->height(), bitmap()->width(), bitmap()->height() }; + } + }; + Bug m_bug; Obstacle m_obstacle; + Cloud m_cloud; bool m_active; - Optional m_highscore; - float m_last_score; - float m_difficulty; - float m_restart_cooldown; - Color m_sky_color { 100, 100, 200 }; + Optional m_highscore {}; + float m_last_score {}; + float m_difficulty {}; + float m_restart_cooldown {}; + const RefPtr m_background_bitmap { Gfx::Bitmap::load_from_file("/res/icons/flappybug/background.png") }; }; }