Raylib Bubbles
C++11 Raylib bubble shooter game.
GameWindow Class Reference

Handles the game window and provides rendering functionality. More...

#include <window.hpp>

Public Member Functions

 GameWindow ()
 Initializes the game window with specific configurations. More...
 
 ~GameWindow ()
 Cleans up game window resources. More...
 
Getters for window properties.
float getWidth () const
 
float getHeight () const
 
size_t getFPS () const
 
Inline calls to Raylib main loop functions.
bool shouldClose () const
 
void beginDrawing ()
 
void endDrawing ()
 
Public drawing methods.
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. More...
 
void drawBubble (const float x, const float y, const float radius, const size_t hue)
 Draws a bubble at a specific position. More...
 
void drawBoard (const PlacedBoard &boardData)
 Draws the provided placed game board. More...
 
void drawHUD (const GameHUD &hud)
 
Public background methods.
void stepBackground ()
 Steps the background movement animation. More...
 
void loadBackground (const size_t index)
 Loads a background image into the game window. More...
 
void applyLoadedBackground ()
 Applies the loaded background to the game window. More...
 
Public methods for game timing.
double time () const
 
float getFrameDeltaRatio () const
 Gets the ratio between the time the previous frame has taken and 60 FPS. More...
 
Getters for counts of loaded resources.
size_t countBubbleTextures () const
 Gets the number of bubble textures loaded. More...
 
size_t countBackgroundImages () const
 Gets the number of background images loaded. More...
 

Raylib input handling.

enum class  HandledKeys { ACTION = KEY_LEFT_SHIFT , LEFT = KEY_Z , RIGHT = KEY_X }
 
bool inputOnce (const HandledKeys key) const
 
bool inputHold (const HandledKeys key) const
 

Detailed Description

Handles the game window and provides rendering functionality.

This class includes most rendering functionality for primary components of the game.

Note
The GameHUD class is also allowed to directly interact with the Raylib API to handle more complex HUD elements.
Warning
This class is no longer responsible for the game loop! This is now handled by the Game class since branch feature/implement_game.
See also
GameBoard, GameActionMgr, GameHUD

Constructor & Destructor Documentation

◆ GameWindow()

GameWindow::GameWindow ( )

Initializes the game window with specific configurations.

This constructor initializes the game window using configurations specified in the game's configuration file. It sets up the window dimensions, frame rate, and board size based on these configurations. The initialization process involves setting up the Raylib window, loading necessary fonts, images, and textures for the game.

Note
The window dimensions, frame rate, and board dimensions are read from the game's configuration file. Defaults are provided in case specific configurations are absent. The GameWindow class loads the settings from the config file instead of providing constructor arguments because of the sheer number of settings.
Warning
Calling the constructor will open a window and load resources, but not start the game loop.

◆ ~GameWindow()

GameWindow::~GameWindow ( )

Cleans up game window resources.

This destructor cleans up the resources used by the game window, including the window itself, fonts, images, and textures.

Member Function Documentation

◆ applyLoadedBackground()

void GameWindow::applyLoadedBackground ( )

Applies the loaded background to the game window.

This method swaps the current and new Texture2D loaded background textures, allowing a buffered background load. Since loading the image into VRAM and unloading the old one is handled by loadBackground(), all this method does is swap the bgTexSelect boolean index to pick the correct background texture, as well as configure the correct viewport size for the LissajousView being used.

Warning
This method should be called after loadBackground() to apply the loaded background to the game window.
See also
loadBackground()

◆ countBackgroundImages()

size_t GameWindow::countBackgroundImages ( ) const
inline

Gets the number of background images loaded.

Returns
The number of background images loaded.
See also
loadBackground()

◆ countBubbleTextures()

size_t GameWindow::countBubbleTextures ( ) const
inline

Gets the number of bubble textures loaded.

Warning
Make sure to interpret the bubble hue index correctly (1-indexed).
Returns
The number of bubble textures loaded.
See also
drawBubble()

◆ drawBoard()

void GameWindow::drawBoard ( const PlacedBoard boardData)

Draws the provided placed game board.

This method draws iterates through the board's cells and draws bubbles at the appropriate positions, based on the board scale and position. check out PlacedBoard for more information.

Note
As mentioned in GameBoard, the number of columns in the board will determine if rows alternate in cells between cols and cols - 1 or not. The GameBoard::getColAlign() method is used to determine this.
Warning
This method is indirectly responsible for auto scaling the board based on the radius given to PlacedBoard.
See also
GameBoard, GameBoard::getColAlign(), PlacedBoard

◆ drawBubble()

void GameWindow::drawBubble ( const float  x,
const float  y,
const float  radius,
const size_t  hue 
)

Draws a bubble at a specific position.

Parameters
xThe x coordinate to draw the bubble.
yThe y coordinate to draw the bubble.
radiusThe radius of the bubble.
hueThe hue property of the bubble

This method draws a bubble texture at the requested position on the game window. Check out GameBoard::BubbleCell for more information on the hue property.

Exceptions
std::out_of_rangeif the hue is not a valid index in the bubble textures.
Warning
Be aware that the hue is 1-indexed, due to the presence of the "empty" bubble texture at index 0!
See also
GameBoard::BubbleCell

◆ drawText()

void GameWindow::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.

Parameters
textThe text to draw.
xThe x coordinate to draw the text.
yThe y coordinate to draw the text.
scaleThe scale of the text (default 1.0f).
colorThe color of the text (default WHITE).

This method draws text using the main font loaded on construction at a specific position on the game window. The text can be scaled and colored as needed.

◆ getFrameDeltaRatio()

float GameWindow::getFrameDeltaRatio ( ) const
inline

Gets the ratio between the time the previous frame has taken and 60 FPS.

Returns
The frame time over 60 FPS.

◆ loadBackground()

void GameWindow::loadBackground ( const size_t  index)

Loads a background image into the game window.

Parameters
indexThe index of the background image to load.

This method loads a background image that has been specified in the game's configuration file. The index corresponds to the order in which the images are listed in the configuration file. The picked image is loaded into a Texture2D (VRAM) and is ready to be swapped with the current background once applyLoadedBackground() is called (this way double buffering is achieved).

Exceptions
std::out_of_rangeif the index is not a valid index in the background images.
Warning
Contrary to bubble textures, the background images are 0-indexed.
See also
applyLoadedBackground()

◆ stepBackground()

void GameWindow::stepBackground ( )

Steps the background movement animation.

Note
This method considers frame delta internally.

The documentation for this class was generated from the following files: