mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 02:55:49 +03: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:
parent
28e08f08c2
commit
ddc855ffcd
Notes:
sideshowbarker
2024-07-18 11:59:53 +09:00
Author: https://github.com/mimhufford Commit: https://github.com/SerenityOS/serenity/commit/ddc855ffcd4 Pull-request: https://github.com/SerenityOS/serenity/pull/7668 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/gunnarbeutner
BIN
Base/res/icons/flappybug/background.png
Normal file
BIN
Base/res/icons/flappybug/background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 650 B |
BIN
Base/res/icons/flappybug/cloud_0.png
Normal file
BIN
Base/res/icons/flappybug/cloud_0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
BIN
Base/res/icons/flappybug/cloud_1.png
Normal file
BIN
Base/res/icons/flappybug/cloud_1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
BIN
Base/res/icons/flappybug/cloud_2.png
Normal file
BIN
Base/res/icons/flappybug/cloud_2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
@ -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;
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/Random.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGUI/Application.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGUI/Widget.h>
|
||||
@ -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<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;
|
||||
Obstacle m_obstacle;
|
||||
Cloud m_cloud;
|
||||
bool m_active;
|
||||
Optional<float> m_highscore;
|
||||
float m_last_score;
|
||||
float m_difficulty;
|
||||
float m_restart_cooldown;
|
||||
Color m_sky_color { 100, 100, 200 };
|
||||
Optional<float> m_highscore {};
|
||||
float m_last_score {};
|
||||
float m_difficulty {};
|
||||
float m_restart_cooldown {};
|
||||
const RefPtr<Gfx::Bitmap> m_background_bitmap { Gfx::Bitmap::load_from_file("/res/icons/flappybug/background.png") };
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user