Module handling the logic components of the game.
More...
|
#define | EMPTY_SPACE 0 |
| If an tetromino does not contain a block in specific position, the value is set to 0.
|
|
|
void | vLogicInitTetromino (tetromino_t *tetromino, tetromino_type_t types[], int *index, player_mode_t playerMode) |
| Initialize a Tetromino. More...
|
|
bool | bLogicCheckMove (const color_t newShape[FIGURE_SIZE][FIGURE_SIZE], coord_t newPosition, const color_t landed[ROWS][COLS]) |
| Check if a move to a newPosition is possible. More...
|
|
bool | bLogicCheckGameOver (const tetromino_t *tetromino, const color_t landed[ROWS][COLS]) |
| Check if the game will be over if the new tetromino is created. More...
|
|
void | vLogicUpdateXCoord (tetromino_t *tetromino, const color_t landed[ROWS][COLS], int pressedButton) |
| Update the x coordinate of tetromino . More...
|
|
bool | bLogicUpdateYCoord (tetromino_t *tetromino, const color_t landed[ROWS][COLS]) |
| Update the y coordinate of tetromino . More...
|
|
void | vLogicRotate (tetromino_t *tetromino, const color_t landed[ROWS][COLS], rotation_t rotationMode) |
| Rotate tetromino , if possible. More...
|
|
void | vLogicAddToLanded (const tetromino_t *tetromino, color_t landed[ROWS][COLS]) |
| Add tetromino to the landed array. More...
|
|
bool | vLogicRowFull (color_t landed[ROWS][COLS], score_t *score) |
| Check how many rows are full and remove them. More...
|
|
static void | setTetrominoType (tetromino_t *tetromino, tetromino_type_t types[], int *index) |
| Set a Tetromino's type. More...
|
|
static void | increaseScore (score_t *score, uint8_t rowsAmount) |
| Increase score if a row is full. More...
|
|
static void | setTetrominoShape (color_t color, tetromino_type_t type, color_t shape[FIGURE_SIZE][FIGURE_SIZE], int rotateAmount, bool init) |
| Set the shape array of the tetromino, depending on the rotation & type. More...
|
|
Module handling the logic components of the game.
This includes calculating new coordinates, checking if a Tetromino can move/rotate, checking for complete rows and more.
- Authors
- Philipp Karg (phili.nosp@m.pp.k.nosp@m.arg@t.nosp@m.um.d.nosp@m.e)
- Date
- 04.02.2021
- Copyright
- Philipp Karg 2022
◆ bLogicCheckGameOver()
bool bLogicCheckGameOver |
( |
const tetromino_t * |
tetromino, |
|
|
const color_t |
landed[ROWS][COLS] |
|
) |
| |
#include <logic.h>
Check if the game will be over if the new tetromino
is created.
- Parameters
-
[in] | tetromino | (const tetromino_t *): Tetromino to check. |
[in] | landed | (const color_t [][]): Array of landed Tetrominos. |
- Returns
- (bool): whether the game will be over.
◆ bLogicCheckMove()
bool bLogicCheckMove |
( |
const color_t |
newShape[FIGURE_SIZE][FIGURE_SIZE], |
|
|
coord_t |
newPosition, |
|
|
const color_t |
landed[ROWS][COLS] |
|
) |
| |
#include <logic.h>
Check if a move to a newPosition
is possible.
Check for possible collisions on the side borders, the ground and with the landed tetrominos.
- Parameters
-
[in] | newShape | (const color_t): New shape to check. |
[in] | newPosition | ( coord_t): New position to check. |
[in] | landed | (const landed): Array of landed Tetrominos. |
- Returns
- (bool): whether a move to a
newPosition
is possible.
◆ bLogicUpdateYCoord()
#include <logic.h>
Update the y coordinate of tetromino
.
- Parameters
-
[in,out] | tetromino | ( tetromino_t *): Tetromino object to increase y coordinate of. |
[in] | landed | (const color_t [][]): Array of landed Tetrominos. |
- Returns
- (bool): true if the y coordinate could be increased.
◆ increaseScore()
static void increaseScore |
( |
score_t * |
score, |
|
|
uint8_t |
rowsAmount |
|
) |
| |
|
static |
#include <logic.c>
Increase score if a row is full.
- Parameters
-
[in] | score | ( score_t *): Score object to change. |
[in] | rowsAmount | (uint8_t): NUmber of rows cleared. |
◆ setTetrominoShape()
#include <logic.c>
Set the shape array of the tetromino, depending on the rotation & type.
- Parameters
-
[in] | color | ( color_t): Color of the tetromino. |
[in] | type | ( tetromino_type_t): Type of the tetromino. |
[in] | shape | ( color_t [][]): Shape array to set. |
[in] | rotateAmount | (int): Amount of rotation for the shape. |
[in] | init | (bool): For some Tetrominos, the shape is set differently at the start. |
◆ setTetrominoType()
#include <logic.c>
Set a Tetromino's type.
Randomly take one of the 7 possible tetromino types and reduce the number of possible types, so that every type is selected once for every seven new tetrominos.
- Parameters
-
[out] | tetromino | ( tetromino_t *): Tetromino to set type for. |
[in,out] | types | ( tetromino_type_t []): Array of tetromino types. |
[in,out] | index | (int*): Current index of the types array. |
◆ vLogicAddToLanded()
#include <logic.h>
Add tetromino
to the landed
array.
- Parameters
-
[in] | tetromino | (const tetromino_t *): Tetromino to add |
[out] | landed | ( color_t [][]): Array of landed Tetrominos. |
◆ vLogicInitTetromino()
#include <logic.h>
Initialize a Tetromino.
- Set the Tetromino's type by calling setTetrominoType().
- Set rotation
- Set color
- Init the position
- Set the shape array.
- Parameters
-
[out] | tetromino | ( tetromino_t *): Tetromino to initialize. |
[in] | types | ( tetromino_type_t [][]): Array of possible types. |
[in] | index | (int*): Index of the types-array. |
[in] | playerMode | ( player_mode_t): Current player mode. |
◆ vLogicRotate()
#include <logic.h>
Rotate tetromino
, if possible.
- Increase/decrease
tetromino's
rotation counter, depending on rotationMode
.
- Set
tetromino's
new shape, by calling setTetrominoShape().
- Check if that new shape is possible with bLogicCheckMove().
- If it is, copy the new shape to the old shape.
- Parameters
-
[in,out] | tetromino | ( tetromino_t *): Tetromino object to rotate. |
[in] | landed | (const color_t [][]): Array of landed Tetrominos. |
[in] | rotationMode | ( rotation_t): Rotation mode, either left or right. |
◆ vLogicRowFull()
#include <logic.h>
Check how many rows are full and remove them.
- Parameters
-
[in,out] | landed | ( color_t [][]): Array of landed Tetrominos. |
[in,out] | score | ( score_t *): Score object to increase if rows are full. |
- Returns
- (bool): true if one or more rows are full. False otherwise.
◆ vLogicUpdateXCoord()
void vLogicUpdateXCoord |
( |
tetromino_t * |
tetromino, |
|
|
const color_t |
landed[ROWS][COLS], |
|
|
int |
pressedButton |
|
) |
| |
#include <logic.h>
Update the x coordinate of tetromino
.
If the pressedButton
is LEFT_PRESSED/RIGHT_PRESSED, try to decrease/increase the position by 1.
- Parameters
-
[in,out] | tetromino | ( tetromino_t *): Tetromino object to increase x coordinate of. |
[in] | landed | (const color_t [][]): Array of landed Tetrominos. |
[in] | pressedButton | (int): The button that was pressed. |