MXVK Vulkan Framework 0.24.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
game_grid.cpp
Go to the documentation of this file.
1#include "game_grid.hpp"
2
3#include <cstddef>
4
5namespace mutatris {
6
8 : gamePiece(this) {
9 }
10
12 gridWidth = width;
13 gridHeight = height;
14 cells.assign(static_cast<std::size_t>(width * height), {});
15 gamePiece.reset();
16 }
17
18 Block *GameGrid::at(int x, int y) {
19 if (x < 0 || x >= gridWidth || y < 0 || y >= gridHeight) {
20 return nullptr;
21 }
22 return &cells[static_cast<std::size_t>(y * gridWidth + x)];
23 }
24
25 const Block *GameGrid::at(int x, int y) const {
26 if (x < 0 || x >= gridWidth || y < 0 || y >= gridHeight) {
27 return nullptr;
28 }
29 return &cells[static_cast<std::size_t>(y * gridWidth + x)];
30 }
31
32 bool GameGrid::canMoveDown() const {
33 return gamePiece.getDirection() == 3 || gamePiece.checkLocation(gamePiece.getX(), gamePiece.getY()) || gamePiece.getY() != 0;
34 }
35
36} // namespace mutatris
int width() const
Definition game_grid.hpp:18
bool canMoveDown() const
Definition game_grid.cpp:32
void initGrid(int width, int height)
Definition game_grid.cpp:11
int height() const
Definition game_grid.hpp:19
Block * at(int x, int y)
Definition game_grid.cpp:18