Raylib Bubbles
C++11 Raylib bubble shooter game.
pboard.hpp
1 #ifndef PBOARD_HPP_
2 #define PBOARD_HPP_
3 
4 #include "board.hpp"
5 
16 struct PlacedBoard {
17 
26  struct BoardDims {
27  float x;
28  float y;
29  float viewportWidth;
30  float viewportHeight;
31  float radius;
32  };
33 
36 
41  inline float getWidth() const {
42  return 2.0f * dims.radius * board.getCols() + (board.getCols() % 2) * dims.radius;
43  }
44 
49  inline float getHeight() const {
50  return 2.0f * dims.radius * board.getRows();
51  }
52 
54 
57 
65  inline bool oob(const float x, const float y) const {
66  return (
67  x < dims.x
68  or x > dims.x + getWidth()
69  or y < dims.y
70  or y > dims.y + getHeight()
71  );
72  }
73 
81  inline bool oow(const float x, const float y) const {
82  return (
83  x < 0.0f
84  or x > dims.viewportWidth
85  or y < 0.0f
86  or y > dims.viewportHeight
87  );
88  }
89 
91 
94 
102  inline int xyToCol(const float x, const float y) const {
103  return static_cast<int>(((x - (yToRow(y) % 2 == 0 ? 0.0f : dims.radius)) / (2.0f * dims.radius)));
104  }
105 
112  inline int yToRow(const float y) const {
113  return static_cast<int>(y / (2.0f * dims.radius));
114  }
115 
123  inline float rowColToX(const size_t row, const size_t col) const {
124  return static_cast<float>(col * 2) * dims.radius + (row % 2) * dims.radius;
125  }
126 
133  inline float rowToY(const size_t row) const {
134  return static_cast<float>(row * 2) * dims.radius;
135  }
136 
138 
139  PlacedBoard(GameBoard& board, const BoardDims& dims)
140  : board(board), dims(dims) {}
141 
142  GameBoard& board;
143  BoardDims dims;
144 };
145 
146 #endif
Represents the game board and provides public methods to interact with it.
Definition: board.hpp:47
size_t getCols() const
Getter for the maximum number of columns in the game board (column amount alternates on row index).
Definition: board.cpp:9
size_t getRows() const
Getter for the number of rows in the game board.
Definition: board.cpp:5
Describes the offset and scale of the board in reference to the window.
Definition: pboard.hpp:26
Describes a game board placed in a window.
Definition: pboard.hpp:16
float getHeight() const
Get the height of the board placed on the window.
Definition: pboard.hpp:49
bool oob(const float x, const float y) const
Check if an absolute coordinate pair is out of bounds of the PlacedBoard.
Definition: pboard.hpp:65
float rowColToX(const size_t row, const size_t col) const
Convert row, column indices to an x coordinate.
Definition: pboard.hpp:123
bool oow(const float x, const float y) const
Check if an absolute coordinate pair is out of the parent window viewport of the PlacedBoard.
Definition: pboard.hpp:81
float getWidth() const
Get the width of the board placed on the window.
Definition: pboard.hpp:41
int yToRow(const float y) const
Convert relative y coordinate to a row index.
Definition: pboard.hpp:112
float rowToY(const size_t row) const
Convert row index to a y coordinate.
Definition: pboard.hpp:133
int xyToCol(const float x, const float y) const
Convert relative x, y coordinates to a column index.
Definition: pboard.hpp:102