summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMim Hufford <mim@hotmail.co.uk>2021-06-02 12:18:57 +0100
committerLinus Groh <mail@linusgroh.de>2021-06-20 10:54:27 +0100
commit28e08f08c2a661ac50b58bd9af84678c8cc1894b (patch)
tree730542fb1f2c4baf128d02865d92ffd4bab20dd1
parentf50003bdd265a8bfc9b7cba76837d627af23ca47 (diff)
downloadserenity-28e08f08c2a661ac50b58bd9af84678c8cc1894b.zip
FlappyBug: Add new graphics and tweak colors
This adds some actual graphics to the game, and tweaks the obstacle and sky colors. Eventually there will be graphics for those elements too.
-rw-r--r--Base/res/icons/16x16/app-flappybug.pngbin182 -> 195 bytes
-rw-r--r--Base/res/icons/32x32/app-flappybug.pngbin241 -> 279 bytes
-rw-r--r--Base/res/icons/flappybug/falling.pngbin0 -> 247 bytes
-rw-r--r--Base/res/icons/flappybug/flapping.pngbin0 -> 279 bytes
-rw-r--r--Userland/Games/FlappyBug/Game.cpp15
-rw-r--r--Userland/Games/FlappyBug/Game.h11
6 files changed, 18 insertions, 8 deletions
diff --git a/Base/res/icons/16x16/app-flappybug.png b/Base/res/icons/16x16/app-flappybug.png
index ebb81a51f0..cb79000fe6 100644
--- a/Base/res/icons/16x16/app-flappybug.png
+++ b/Base/res/icons/16x16/app-flappybug.png
Binary files differ
diff --git a/Base/res/icons/32x32/app-flappybug.png b/Base/res/icons/32x32/app-flappybug.png
index dae5073be6..13db9e46e9 100644
--- a/Base/res/icons/32x32/app-flappybug.png
+++ b/Base/res/icons/32x32/app-flappybug.png
Binary files differ
diff --git a/Base/res/icons/flappybug/falling.png b/Base/res/icons/flappybug/falling.png
new file mode 100644
index 0000000000..df97fed13f
--- /dev/null
+++ b/Base/res/icons/flappybug/falling.png
Binary files differ
diff --git a/Base/res/icons/flappybug/flapping.png b/Base/res/icons/flappybug/flapping.png
new file mode 100644
index 0000000000..13db9e46e9
--- /dev/null
+++ b/Base/res/icons/flappybug/flapping.png
Binary files differ
diff --git a/Userland/Games/FlappyBug/Game.cpp b/Userland/Games/FlappyBug/Game.cpp
index 4927f89924..4fe7344f11 100644
--- a/Userland/Games/FlappyBug/Game.cpp
+++ b/Userland/Games/FlappyBug/Game.cpp
@@ -56,19 +56,20 @@ void Game::paint_event(GUI::PaintEvent& event)
GUI::Painter painter(*this);
painter.add_clip_rect(event.rect());
- painter.fill_rect(rect(), Color::Black);
+ painter.fill_rect(rect(), m_sky_color);
- painter.fill_rect(enclosing_int_rect(m_obstacle.top_rect()), Color::White);
- painter.fill_rect(enclosing_int_rect(m_obstacle.bottom_rect()), Color::White);
- painter.fill_ellipse(enclosing_int_rect(m_bug.rect()), Color::Red);
+ 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);
+
+ painter.draw_scaled_bitmap(enclosing_int_rect(m_bug.rect()), *m_bug.current_bitmap(), m_bug.flapping_bitmap->rect());
if (m_active) {
- painter.draw_text({ 10, 10, 100, 100 }, String::formatted("{:.0}", m_difficulty), Gfx::TextAlignment::TopLeft, Color::Green);
+ painter.draw_text({ 10, 10, 100, 100 }, String::formatted("{:.0}", m_difficulty), Gfx::TextAlignment::TopLeft, Color::White);
} else if (m_highscore.has_value()) {
auto message = String::formatted("Your score: {:.0}\nHighscore: {:.0}\n\n{}", m_last_score, m_highscore.value(), m_restart_cooldown < 0 ? "Press any key to play again" : " ");
- painter.draw_text(rect(), message, Gfx::TextAlignment::Center, Color::Green);
+ painter.draw_text(rect(), message, Gfx::TextAlignment::Center, Color::White);
} else {
- painter.draw_text(rect(), "Press any key to start", Gfx::TextAlignment::Center, Color::Green);
+ painter.draw_text(rect(), "Press any key to start", Gfx::TextAlignment::Center, Color::White);
}
}
diff --git a/Userland/Games/FlappyBug/Game.h b/Userland/Games/FlappyBug/Game.h
index 1b7dbe6c08..09876bdbfb 100644
--- a/Userland/Games/FlappyBug/Game.h
+++ b/Userland/Games/FlappyBug/Game.h
@@ -38,8 +38,10 @@ private:
struct Bug {
const float x { 50 };
- const float radius { 10 };
+ const float radius { 16 };
const float starting_y { 200 };
+ const RefPtr<Gfx::Bitmap> falling_bitmap { Gfx::Bitmap::load_from_file("/res/icons/flappybug/falling.png") };
+ const RefPtr<Gfx::Bitmap> flapping_bitmap { Gfx::Bitmap::load_from_file("/res/icons/flappybug/flapping.png") };
float y {};
float velocity {};
@@ -48,6 +50,11 @@ private:
y = starting_y;
}
+ RefPtr<Gfx::Bitmap> current_bitmap() const
+ {
+ return velocity < 0 ? falling_bitmap : flapping_bitmap;
+ }
+
Gfx::FloatRect rect() const
{
return { x - radius, y - radius, radius * 2, radius * 2 };
@@ -73,6 +80,7 @@ private:
struct Obstacle {
const float width { 20 };
+ Color color { Color::DarkGray };
float x;
float gap_top_y { 200 };
float gap_height { 175 };
@@ -101,6 +109,7 @@ private:
float m_last_score;
float m_difficulty;
float m_restart_cooldown;
+ Color m_sky_color { 100, 100, 200 };
};
}