1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-03 08:48:11 +00:00

FlappyBug: Add cloud and sky graphics

We now have a nice sunset sky and some random cloud graphics.
The obstacles will get graphics at some point too :)
This commit is contained in:
Mim Hufford 2021-06-07 11:03:01 +01:00 committed by Linus Groh
parent 28e08f08c2
commit ddc855ffcd
6 changed files with 50 additions and 7 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 650 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View file

@ -56,7 +56,9 @@ void Game::paint_event(GUI::PaintEvent& event)
GUI::Painter painter(*this); GUI::Painter painter(*this);
painter.add_clip_rect(event.rect()); 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.top_rect()), m_obstacle.color);
painter.fill_rect(enclosing_int_rect(m_obstacle.bottom_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.fall();
m_bug.apply_velocity(); m_bug.apply_velocity();
m_obstacle.x -= 4 + m_difficulty / 16.0f; 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) { if (m_bug.y > game_height || m_bug.y < 0) {
game_over(); game_over();
@ -110,6 +113,10 @@ void Game::tick()
if (m_obstacle.x < 0) { if (m_obstacle.x < 0) {
m_obstacle.reset(); m_obstacle.reset();
} }
if (m_cloud.x < 0) {
m_cloud.reset();
}
} }
m_restart_cooldown -= 1.0f / 16.0f; m_restart_cooldown -= 1.0f / 16.0f;

View file

@ -8,6 +8,7 @@
#include <AK/Optional.h> #include <AK/Optional.h>
#include <AK/Random.h> #include <AK/Random.h>
#include <AK/Vector.h>
#include <LibGUI/Application.h> #include <LibGUI/Application.h>
#include <LibGUI/Painter.h> #include <LibGUI/Painter.h>
#include <LibGUI/Widget.h> #include <LibGUI/Widget.h>
@ -81,7 +82,7 @@ private:
struct Obstacle { struct Obstacle {
const float width { 20 }; const float width { 20 };
Color color { Color::DarkGray }; Color color { Color::DarkGray };
float x; float x {};
float gap_top_y { 200 }; float gap_top_y { 200 };
float gap_height { 175 }; float gap_height { 175 };
@ -102,14 +103,49 @@ private:
} }
}; };
struct Cloud {
const Vector<RefPtr<Gfx::Bitmap>> 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<Gfx::Bitmap> 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; Bug m_bug;
Obstacle m_obstacle; Obstacle m_obstacle;
Cloud m_cloud;
bool m_active; bool m_active;
Optional<float> m_highscore; Optional<float> m_highscore {};
float m_last_score; float m_last_score {};
float m_difficulty; float m_difficulty {};
float m_restart_cooldown; float m_restart_cooldown {};
Color m_sky_color { 100, 100, 200 }; const RefPtr<Gfx::Bitmap> m_background_bitmap { Gfx::Bitmap::load_from_file("/res/icons/flappybug/background.png") };
}; };
} }