FreeRTOS Tetris
logic.h
Go to the documentation of this file.
1 
25 #ifndef LOGIC_H
26 #define LOGIC_H
27 
28 #include "tetrisConfig.h"
29 
30 #define EMPTY_SPACE 0
31 
32 
36 #define INIT_COORDS_X COLS/2 -1
37 #define INIT_COORDS_Y 0
38 
40 
44 #define LEFT_PRESSED 1
45 #define RIGHT_PRESSED 2
46 #define DOWN_PRESSED 3
47 
49 
52 typedef struct tetromino
53 {
57  int rotation;
59 
64 
65 } tetromino_t;
66 
70 typedef struct score
71 {
72  uint32_t score;
73  uint8_t level;
74  uint16_t rows;
75  char *userName;
76 } score_t;
77 
93  tetromino_type_t types[],
94  int *index,
95  player_mode_t playerMode);
96 
107 bool bLogicCheckMove( const color_t newShape[FIGURE_SIZE][FIGURE_SIZE],
108  coord_t newPosition,
109  const color_t landed[ROWS][COLS]);
110 
117 bool bLogicCheckGameOver(const tetromino_t *tetromino, const color_t landed[ROWS][COLS]);
118 
127 void vLogicUpdateXCoord(tetromino_t *tetromino, const color_t landed[ROWS][COLS], int pressedButton);
128 
136 
149 void vLogicRotate(tetromino_t *tetromino, const color_t landed[ROWS][COLS], rotation_t rotationMode);
150 
156 void vLogicAddToLanded(const tetromino_t *tetromino, color_t landed[ROWS][COLS]);
157 
164 bool vLogicRowFull(color_t landed[ROWS][COLS], score_t *score);
165 
167 #endif //LOGIC_H
FIGURE_SIZE
#define FIGURE_SIZE
Maximum length/width of a Tetromino.
Definition: tetrisConfig.h:78
tetromino_type_t
enum tetromino_type tetromino_type_t
Tetromino types.
score::level
uint8_t level
The current level.
Definition: logic.h:73
vLogicRotate
void vLogicRotate(tetromino_t *tetromino, const color_t landed[ROWS][COLS], rotation_t rotationMode)
Rotate tetromino, if possible.
Definition: logic.c:181
tetromino::shape
color_t shape[FIGURE_SIZE][FIGURE_SIZE]
Array containing the Tetrominos shape.
Definition: logic.h:61
vLogicRowFull
bool vLogicRowFull(color_t landed[ROWS][COLS], score_t *score)
Check how many rows are full and remove them.
Definition: logic.c:221
ROWS
#define ROWS
Number of rows, that the board contains.
Definition: tetrisConfig.h:80
color_t
enum color color_t
Tetromino colors.
tetrisConfig.h
File containing some game configurations.
tetromino::type
tetromino_type_t type
Tetromino type.
Definition: logic.h:56
COLS
#define COLS
Number of columns, that the board contains.
Definition: tetrisConfig.h:79
tetromino::color
color_t color
Tetrominos color.
Definition: logic.h:58
rotation_t
enum rotation rotation_t
Rotations.
vLogicAddToLanded
void vLogicAddToLanded(const tetromino_t *tetromino, color_t landed[ROWS][COLS])
Add tetromino to the landed array.
Definition: logic.c:207
tetromino::newShape
color_t newShape[FIGURE_SIZE][FIGURE_SIZE]
Array to check a potential shape.
Definition: logic.h:63
tetromino
Structure representing a Tetromino.
Definition: logic.h:52
score
Structure for the score.
Definition: logic.h:70
score::userName
char * userName
The selected User-Name.
Definition: logic.h:75
bLogicCheckGameOver
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.
Definition: logic.c:136
score_t
struct score score_t
Structure for the score.
score::score
uint32_t score
The current score.
Definition: logic.h:72
coord
Holds a pixel co-ordinate.
Definition: TUM_Draw.h:121
tetromino::newPosition
coord_t newPosition
New position to check.
Definition: logic.h:55
score::rows
uint16_t rows
Number of rows cleared.
Definition: logic.h:74
tetromino_t
struct tetromino tetromino_t
Structure representing a Tetromino.
bLogicCheckMove
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.
Definition: logic.c:108
tetromino::position
coord_t position
Position of top left square.
Definition: logic.h:54
bLogicUpdateYCoord
bool bLogicUpdateYCoord(tetromino_t *tetromino, const color_t landed[ROWS][COLS])
Update the y coordinate of tetromino.
Definition: logic.c:165
vLogicUpdateXCoord
void vLogicUpdateXCoord(tetromino_t *tetromino, const color_t landed[ROWS][COLS], int pressedButton)
Update the x coordinate of tetromino.
Definition: logic.c:143
player_mode_t
enum player_mode player_mode_t
Player modes.
tetromino::rotation
int rotation
Tetrominos rotation.
Definition: logic.h:57
vLogicInitTetromino
void vLogicInitTetromino(tetromino_t *tetromino, tetromino_type_t types[], int *index, player_mode_t playerMode)
Initialize a Tetromino.
Definition: logic.c:45