8
8
9
9
#include < AK/Optional.h>
10
10
#include < AK/Random.h>
11
+ #include < AK/Vector.h>
11
12
#include < LibGUI/Application.h>
12
13
#include < LibGUI/Painter.h>
13
14
#include < LibGUI/Widget.h>
@@ -81,7 +82,7 @@ class Game final : public GUI::Widget {
81
82
struct Obstacle {
82
83
const float width { 20 };
83
84
Color color { Color::DarkGray };
84
- float x;
85
+ float x {} ;
85
86
float gap_top_y { 200 };
86
87
float gap_height { 175 };
87
88
@@ -102,14 +103,49 @@ class Game final : public GUI::Widget {
102
103
}
103
104
};
104
105
106
+ struct Cloud {
107
+ const Vector<RefPtr<Gfx::Bitmap>> cloud_bitmaps {
108
+ Gfx::Bitmap::load_from_file (" /res/icons/flappybug/cloud_0.png" ),
109
+ Gfx::Bitmap::load_from_file (" /res/icons/flappybug/cloud_1.png" ),
110
+ Gfx::Bitmap::load_from_file (" /res/icons/flappybug/cloud_2.png" ),
111
+ };
112
+ float x {};
113
+ float y {};
114
+ int bitmap_id {};
115
+
116
+ Cloud ()
117
+ {
118
+ reset ();
119
+ x = get_random_uniform (game_width);
120
+ }
121
+
122
+ void reset ()
123
+ {
124
+ bitmap_id = get_random_uniform (cloud_bitmaps.size ());
125
+ x = game_width + bitmap ()->width ();
126
+ y = get_random_uniform (game_height / 2 ) + bitmap ()->height ();
127
+ }
128
+
129
+ RefPtr<Gfx::Bitmap> bitmap () const
130
+ {
131
+ return cloud_bitmaps[bitmap_id];
132
+ }
133
+
134
+ Gfx::IntRect rect () const
135
+ {
136
+ return { (int )x - bitmap ()->width (), (int )y - bitmap ()->height (), bitmap ()->width (), bitmap ()->height () };
137
+ }
138
+ };
139
+
105
140
Bug m_bug;
106
141
Obstacle m_obstacle;
142
+ Cloud m_cloud;
107
143
bool m_active;
108
- Optional<float > m_highscore;
109
- float m_last_score;
110
- float m_difficulty;
111
- float m_restart_cooldown;
112
- Color m_sky_color { 100 , 100 , 200 };
144
+ Optional<float > m_highscore {} ;
145
+ float m_last_score {} ;
146
+ float m_difficulty {} ;
147
+ float m_restart_cooldown {} ;
148
+ const RefPtr<Gfx::Bitmap> m_background_bitmap { Gfx::Bitmap::load_from_file ( " /res/icons/flappybug/background.png " ) };
113
149
};
114
150
115
151
}
0 commit comments