MXVK Vulkan Framework 0.35.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.

12: playLineSound(std::move(lineSoundCallback)) { newGame(difficulty); }
void newGame(int difficulty)

Member Function Documentation

◆ newGame()

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

Definition at line 14 of file puzzle_game.cpp.

14 {
15 std::srand(static_cast<unsigned int>(std::time(nullptr)));
16 score = 0;
17 clears = 0;
18 level = 0;
19 timeout = difficulty == 0 ? 1200U : difficulty == 1 ? 900U : 650U;
20 grid[0].initGrid(GRID_WIDTH, TOP_GRID_HEIGHT);
24 }
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 26 of file puzzle_game.cpp.

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

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.

◆ 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: