MXVK Vulkan Framework 0.24.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
mutatris::PuzzleGame Class Reference

#include <examples/mutatris/puzzle_game.hpp>

Public Member Functions

void newGame (int difficulty)
void procBlocks ()
 PuzzleGame (int difficulty, std::function< void()> lineSoundCallback)

Public Attributes

int clears = 0
std::array< GameGrid, 4 > grid {}
int level = 0
int score = 0
unsigned int timeout = 1200

Detailed Description

Definition at line 11 of file puzzle_game.hpp.

Constructor & Destructor Documentation

◆ PuzzleGame()

mutatris::PuzzleGame::PuzzleGame ( int difficulty,
std::function< void()> lineSoundCallback )
explicit

Definition at line 12 of file puzzle_game.cpp.

13 : playLineSound(std::move(lineSoundCallback)) {
14 newGame(difficulty);
15 }
void newGame(int difficulty)

Member Function Documentation

◆ newGame()

void mutatris::PuzzleGame::newGame ( int difficulty)

Definition at line 17 of file puzzle_game.cpp.

17 {
18 std::srand(static_cast<unsigned int>(std::time(nullptr)));
19 score = 0;
20 clears = 0;
21 level = 0;
22 timeout = difficulty == 0 ? 1200U : difficulty == 1 ? 900U
23 : 650U;
24 grid[0].initGrid(GRID_WIDTH, TOP_GRID_HEIGHT);
28 }
std::array< GameGrid, 4 > grid
constexpr int GRID_WIDTH
Definition common.hpp:16
constexpr int SIDE_GRID_WIDTH
Definition common.hpp:19
constexpr int SIDE_GRID_HEIGHT
Definition common.hpp:20
constexpr int BOTTOM_GRID_HEIGHT
Definition common.hpp:18
constexpr int TOP_GRID_HEIGHT
Definition common.hpp:17

◆ procBlocks()

void mutatris::PuzzleGame::procBlocks ( )

Definition at line 30 of file puzzle_game.cpp.

30 {
31 level = std::clamp((1200 - static_cast<int>(timeout)) / 100, 0, 10);
32 if (clearVisualRun()) {
33 return;
34 }
35 for (GameGrid &focusGrid : grid) {
36 for (int x = 0; x < focusGrid.width(); ++x) {
37 for (int y = 0; y < focusGrid.height(); ++y) {
38 if (clearRun(focusGrid, x, y, 0, 1) ||
39 clearRun(focusGrid, x, y, 1, 0) ||
40 clearRun(focusGrid, x, y, 1, 1) ||
41 clearRun(focusGrid, x, y, -1, 1)) {
42 return;
43 }
44 }
45 }
46 }
47 clearTopBottomSeams();
48 moveDownBlocks();
49 }

Member Data Documentation

◆ clears

int mutatris::PuzzleGame::clears = 0

Definition at line 21 of file puzzle_game.hpp.

◆ grid

std::array<GameGrid, 4> mutatris::PuzzleGame::grid {}

Definition at line 18 of file puzzle_game.hpp.

18{};

◆ level

int mutatris::PuzzleGame::level = 0

Definition at line 22 of file puzzle_game.hpp.

◆ score

int mutatris::PuzzleGame::score = 0

Definition at line 19 of file puzzle_game.hpp.

◆ timeout

unsigned int mutatris::PuzzleGame::timeout = 1200

Definition at line 20 of file puzzle_game.hpp.


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