Raylib Bubbles
C++11 Raylib bubble shooter game.
window.hpp
1 #ifndef WINDOW_HPP_
2 #define WINDOW_HPP_
3 
4 #include <string>
5 #include <sstream>
6 #include <cmath>
7 
8 #include <raylib.h>
9 
10 #include "action.hpp"
11 #include "board.hpp"
12 #include "pboard.hpp"
13 #include "util.hpp"
14 #include "lissajous.hpp"
15 #include "hud.hpp"
16 
27 class GameWindow {
28 public:
42  GameWindow();
43 
49  ~GameWindow();
50 
53 
54  inline float getWidth() const {
55  return width;
56  }
57 
58  inline float getHeight() const {
59  return height;
60  }
61 
62  inline size_t getFPS() const {
63  return GetFPS();
64  }
65 
67 
70 
71  inline bool shouldClose() const {
72  return WindowShouldClose();
73  }
74 
75  inline void beginDrawing() {
76  BeginDrawing();
77  }
78 
79  inline void endDrawing() {
80  EndDrawing();
81  }
82 
84 
87 
99  void drawText(const std::string& text, const float x, const float y, const float scale = 1.0f, const Color& color = WHITE);
100 
115  void drawBubble(const float x, const float y, const float radius, const size_t hue);
116 
129  void drawBoard(const PlacedBoard& boardData);
130 
131  void drawHUD(const GameHUD& hud);
132 
134 
137 
142  void stepBackground();
143 
157  void loadBackground(const size_t index);
158 
170  void applyLoadedBackground();
171 
173 
176 
177  inline double time() const {
178  return GetTime();
179  }
180 
185  inline float getFrameDeltaRatio() const {
186  return GetFrameTime() / 0.01667f;
187  }
188 
190 
193 
200  inline size_t countBubbleTextures() const {
201  return bubbleTexs.size();
202  }
203 
209  inline size_t countBackgroundImages() const {
210  return bgImgs.size();
211  }
212 
214 
217 
218  enum class HandledKeys {
219  ACTION = KEY_LEFT_SHIFT,
220  LEFT = KEY_Z,
221  RIGHT = KEY_X,
222  };
223 
224  inline bool inputOnce(const HandledKeys key) const {
225  return IsKeyPressed(static_cast<int>(key));
226  }
227 
228  inline bool inputHold(const HandledKeys key) const {
229  return IsKeyDown(static_cast<int>(key));
230  }
231 
233 
234 private:
235  const float width;
236  const float height;
237  const size_t fps;
238 
239  Font font;
240  std::vector<Image> bgImgs;
241  std::vector<Texture2D> bubbleTexs;
242 
243  LissajousView lissajous;
244  Texture2D bgTex[2];
245  bool bgTexSelect;
246  bool bgTexEmpty;
247 
248  void initWindow();
249  void loadFont();
250  void loadImages();
251  void loadTextures();
252  void initBackground();
253 };
254 
255 #endif
Provides an object to manage the game HUD state.
Definition: hud.hpp:29
Handles the game window and provides rendering functionality.
Definition: window.hpp:27
void drawBoard(const PlacedBoard &boardData)
Draws the provided placed game board.
Definition: window.cpp:48
void loadBackground(const size_t index)
Loads a background image into the game window.
Definition: window.cpp:89
size_t countBackgroundImages() const
Gets the number of background images loaded.
Definition: window.hpp:209
~GameWindow()
Cleans up game window resources.
Definition: window.cpp:17
float getFrameDeltaRatio() const
Gets the ratio between the time the previous frame has taken and 60 FPS.
Definition: window.hpp:185
void drawBubble(const float x, const float y, const float radius, const size_t hue)
Draws a bubble at a specific position.
Definition: window.cpp:32
GameWindow()
Initializes the game window with specific configurations.
Definition: window.cpp:5
void stepBackground()
Steps the background movement animation.
Definition: window.cpp:84
void drawText(const std::string &text, const float x, const float y, const float scale=1.0f, const Color &color=WHITE)
Draws text at a specific position.
Definition: window.cpp:28
void applyLoadedBackground()
Applies the loaded background to the game window.
Definition: window.cpp:101
size_t countBubbleTextures() const
Gets the number of bubble textures loaded.
Definition: window.hpp:200
Provides a view of a Lissajous curve.
Definition: lissajous.hpp:19
Describes a game board placed in a window.
Definition: pboard.hpp:16