mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-21 10:19:03 +03:00
Snake: Don't hardcode the snake painting logic
This patch adds a m_snake_base_color variable which dictates the color of the head of the snake and from which the rest of the snake color's are derived from by darkening the base color.
This commit is contained in:
parent
b354e858c8
commit
56a75ec94e
Notes:
sideshowbarker
2024-07-17 02:59:48 +09:00
Author: https://github.com/Baitinq Commit: https://github.com/SerenityOS/serenity/commit/56a75ec94e Pull-request: https://github.com/SerenityOS/serenity/pull/16577 Reviewed-by: https://github.com/trflynn89 ✅
@ -236,19 +236,19 @@ void SnakeGame::paint_event(GUI::PaintEvent& event)
|
|||||||
painter.add_clip_rect(event.rect());
|
painter.add_clip_rect(event.rect());
|
||||||
painter.fill_rect(event.rect(), Color::Black);
|
painter.fill_rect(event.rect(), Color::Black);
|
||||||
|
|
||||||
painter.fill_rect(cell_rect(m_head), Color::Yellow);
|
painter.fill_rect(cell_rect(m_head), m_snake_base_color);
|
||||||
for (auto& part : m_tail) {
|
for (auto& part : m_tail) {
|
||||||
auto rect = cell_rect(part);
|
auto rect = cell_rect(part);
|
||||||
painter.fill_rect(rect, Color::from_rgb(0xaaaa00));
|
painter.fill_rect(rect, m_snake_base_color.darkened(0.77));
|
||||||
|
|
||||||
Gfx::IntRect left_side(rect.x(), rect.y(), 2, rect.height());
|
Gfx::IntRect left_side(rect.x(), rect.y(), 2, rect.height());
|
||||||
Gfx::IntRect top_side(rect.x(), rect.y(), rect.width(), 2);
|
Gfx::IntRect top_side(rect.x(), rect.y(), rect.width(), 2);
|
||||||
Gfx::IntRect right_side(rect.right() - 1, rect.y(), 2, rect.height());
|
Gfx::IntRect right_side(rect.right() - 1, rect.y(), 2, rect.height());
|
||||||
Gfx::IntRect bottom_side(rect.x(), rect.bottom() - 1, rect.width(), 2);
|
Gfx::IntRect bottom_side(rect.x(), rect.bottom() - 1, rect.width(), 2);
|
||||||
painter.fill_rect(left_side, Color::from_rgb(0xcccc00));
|
painter.fill_rect(left_side, m_snake_base_color.darkened(0.88));
|
||||||
painter.fill_rect(right_side, Color::from_rgb(0x888800));
|
painter.fill_rect(right_side, m_snake_base_color.darkened(0.55));
|
||||||
painter.fill_rect(top_side, Color::from_rgb(0xcccc00));
|
painter.fill_rect(top_side, m_snake_base_color.darkened(0.88));
|
||||||
painter.fill_rect(bottom_side, Color::from_rgb(0x888800));
|
painter.fill_rect(bottom_side, m_snake_base_color.darkened(0.55));
|
||||||
}
|
}
|
||||||
|
|
||||||
painter.draw_scaled_bitmap(cell_rect(m_fruit), m_food_bitmaps[m_fruit_type], m_food_bitmaps[m_fruit_type].rect());
|
painter.draw_scaled_bitmap(cell_rect(m_fruit), m_food_bitmaps[m_fruit_type], m_food_bitmaps[m_fruit_type].rect());
|
||||||
|
@ -75,4 +75,6 @@ private:
|
|||||||
bool m_is_new_high_score { false };
|
bool m_is_new_high_score { false };
|
||||||
|
|
||||||
NonnullRefPtrVector<Gfx::Bitmap> m_food_bitmaps;
|
NonnullRefPtrVector<Gfx::Bitmap> m_food_bitmaps;
|
||||||
|
|
||||||
|
Gfx::Color m_snake_base_color { Color::Yellow };
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user