FreeRTOS Tetris
Macros | Functions
Main Game Module

Module that contains the primary game functionality. More...

Collaboration diagram for Main Game Module:

Macros

#define PRINT_TASK_ERROR(task)   PRINT_ERROR("Failed to print task ##task");
 Print error message for task. More...
 

Functions

int iGameInit ()
 Initialize the game. More...
 
static void buttonInput (bool *buttonPressed)
 Check for button input, give semaphores and write the pressed buttons in a queue. More...
 
static void changeTimerPeriod (TimerHandle_t timer, uint8_t level, int delay)
 Change a timer's period depending on the current level & start the timer. More...
 
static void mainMenuTask ()
 Task that handles the Main Menu. More...
 
static void posUpdateTimerCallback (TimerHandle_t PosUpdateTimer)
 Callback function for the Timer that updates the position. More...
 
static void delayAtBottomTimerCallback (TimerHandle_t DelayAtGroundTimer)
 Callback function for the Timer that starts a delay if a Tetromino hits the bottom. More...
 
static void gameTask ()
 Task that handles the Tetris gameplay. More...
 
static void pauseTask ()
 Task that handles the pause & game-over screen. More...
 
static void scoreTask ()
 Low priority task, running in the background, that handles the score.
 
static void swapBuffers ()
 Task that updates the screen every 20ms & gives ScreenLock & DrawSignal.
 

Task Handles

TaskHandle_t MainMenuTask = NULL
 Task for the Main Menu Task
 
TaskHandle_t GameTask = NULL
 Task for the Game Task
 
TaskHandle_t PauseTask = NULL
 Task for the Pause Task
 
TaskHandle_t ScoreTask = NULL
 Task for the Score Task
 

Timer Handles

TimerHandle_t PosUpdateTimer = NULL
 Timer for updating a Tetromino's position
 
TimerHandle_t DelayAtGroundTimer = NULL
 Timer for the delay, when a Tetromino hits the bottom
 

Semaphore Handles

SemaphoreHandle_t ScreenLock = NULL
 Semaphore for locking the screen
 
SemaphoreHandle_t DrawSignal = NULL
 Signal for drawing
 
SemaphoreHandle_t YSignal = NULL
 Signal for updating a Tetromino's y-position
 
SemaphoreHandle_t XSignal = NULL
 Signal for updating a Tetromino's x-position
 
SemaphoreHandle_t FallSignal = NULL
 Signal if the down-key is held
 
SemaphoreHandle_t RotationSignal = NULL
 Signal for rotating a Tetromino
 
SemaphoreHandle_t InitNextSignal = NULL
 Signal for initializing the next Tetromino
 
SemaphoreHandle_t ResetGameSignal = NULL
 Signal for resetting the game
 
SemaphoreHandle_t ResetUDPSignal = NULL
 Signal for resetting the UDP socket
 
SemaphoreHandle_t NoConnectionSignal = NULL
 Signal if the binary is not connected
 

Queue Handles

QueueHandle_t LeftRightQueue = NULL
 Queue for left & right input
 
QueueHandle_t ConnectionQueue = NULL
 Queue for the connection status
 
QueueHandle_t GameModeQueue = NULL
 Queue for the game mode
 
QueueHandle_t PlayerModeQueue = NULL
 Queue for the player mode
 
QueueHandle_t RotationModeQueue = NULL
 Queue for the rotation mode
 
QueueHandle_t ScoreQueue = NULL
 Queue for the current score
 
QueueHandle_t HighScoresQueue = NULL
 Queue for the highscores
 
QueueHandle_t LevelQueue = NULL
 Queue for the current level
 
QueueHandle_t GameOverQueue = NULL
 Queue for the game-over status
 

Detailed Description

Module that contains the primary game functionality.

This module contains the game's main functionality. It contains the different tasks, for the main game, main menu & pause screen. It interacts with the Logic Module, the GUI Module , the State Machine Module and the Opponent Module.

Authors
Philipp Karg (phili.nosp@m.pp.k.nosp@m.arg@t.nosp@m.um.d.nosp@m.e)
Date
04.02.2021

Macro Definition Documentation

◆ PRINT_TASK_ERROR

#define PRINT_TASK_ERROR (   task)    PRINT_ERROR("Failed to print task ##task");

#include <game.h>

Print error message for task.

Parameters
[in]task(const char*): Task to print error message for.

Function Documentation

◆ buttonInput()

static void buttonInput ( bool *  buttonPressed)
static

#include <game.c>

Check for button input, give semaphores and write the pressed buttons in a queue.

Parameters
[in,out]buttonPressed(bool): whether a button was pressed.

◆ changeTimerPeriod()

static void changeTimerPeriod ( TimerHandle_t  timer,
uint8_t  level,
int  delay 
)
static

#include <game.c>

Change a timer's period depending on the current level & start the timer.

Parameters
[in,out]timer( TimerHandle_t): Timer to change period for.
[in]level(uint8_t): Current level.
[in]delay(int): The delay for changing the period.

◆ delayAtBottomTimerCallback()

static void delayAtBottomTimerCallback ( TimerHandle_t  DelayAtGroundTimer)
static

#include <game.c>

Callback function for the Timer that starts a delay if a Tetromino hits the bottom.

Parameters
[in]DelayAtGroundTimer( TimerHandle_t): Timer to callback.

◆ gameTask()

static void gameTask ( )
static

#include <game.c>

Task that handles the Tetris gameplay.

  1. If the ResetGameSignal has been received, reset the game.
  2. At the beginning/if the game is reset, the first Tetromino is initialized.
  3. The Tetrominos position is updated, including x & y position & rotation.
  4. If a Tetromino hits the ground, start a Timer, so that the player can move around the Tetromino further.
  5. If the Tetromino is not moved anymore, initialize the next one & add the old one to the landed Tetrominos.
  6. Draw all aspects of the game, e.g. the falling Tetromino & the static elements.
  7. If the game is over, save the score & switch to the pause task.

◆ iGameInit()

int iGameInit ( )

#include <game.h>

Initialize the game.

Returns
(int): 0 upon successful initialization, -1 otherwise.

◆ mainMenuTask()

static void mainMenuTask ( )
static

#include <game.c>

Task that handles the Main Menu.

This Task draws the following textures:

Furthermore, this task:

  • sets the LevelQueue
  • checks if the opponent is connected
  • stops/resumes the UDP task depending on the opponents connection

◆ pauseTask()

static void pauseTask ( )
static

#include <game.c>

Task that handles the pause & game-over screen.

  1. Read from the GameOverQueue, ScoreQueue & ConnectionQueue.
  2. If the game is not over, call vGUIDrawPauseMenu().
  3. Otherwise, call vGUIDrawGameOverMenu().

◆ posUpdateTimerCallback()

static void posUpdateTimerCallback ( TimerHandle_t  PosUpdateTimer)
static

#include <game.c>

Callback function for the Timer that updates the position.

Parameters
[in]PosUpdateTimer( TimerHandle_t): Timer to callback.