Zap'Em Blast'Em Robots
robots that play laser tag!
Loading...
Searching...
No Matches
game_task.c File Reference

State machine for Zap'em Blast'em Robots game control logic. More...

#include "motor_driver.h"
#include "game_task.h"
#include "sound_task.h"
#include "photoresistor_task.h"
#include "stm32f4xx_hal_tim.h"
#include "stm32f4xx_it.h"
#include "lcd.h"
#include <stdio.h>

Functions

void game_task_run (GameTask *game_task)
 Runs the current state of the GameTask.
void game_task_state_0_init (GameTask *game_task)
 Initializes the game task (state 0).
void game_task_state_1_home (GameTask *game_task)
 Waits for player to initiate the game (state 1).
void game_task_state_2_play (GameTask *game_task)
 Handles gameplay logic and scoring (state 2).
void game_task_state_3_end (GameTask *game_task)
 Displays game over screen and resets (state 3).

Detailed Description

State machine for Zap'em Blast'em Robots game control logic.

Author
Andrew Carr and Kai De La Cruz game_task.c

Created on: May 22, 2025

Function Documentation

◆ game_task_run()

void game_task_run ( GameTask * game_task)

Runs the current state of the GameTask.

Executes the current game task state.

Checks whether the current state index is valid. If so, it calls the corresponding state function from the task's function pointer array.

Parameters
game_taskPointer to the GameTask instance.

◆ game_task_state_0_init()

void game_task_state_0_init ( GameTask * game_task)

Initializes the game task (state 0).

Clears and sets up the LCD, then advances to state 1.

Parameters
game_taskPointer to the GameTask instance.

◆ game_task_state_1_home()

void game_task_state_1_home ( GameTask * game_task)

Waits for player to initiate the game (state 1).

Displays title and instructions. When play_flag is set, transitions to the next state and triggers the start sound.

Parameters
game_taskPointer to the GameTask instance.

◆ game_task_state_2_play()

void game_task_state_2_play ( GameTask * game_task)

Handles gameplay logic and scoring (state 2).

Increments scores based on photoresistor hit flags, updates LCD with score, and transitions to end state when a score threshold is reached.

Parameters
game_taskPointer to the GameTask instance.

◆ game_task_state_3_end()

void game_task_state_3_end ( GameTask * game_task)

Displays game over screen and resets (state 3).

Shows a winning message based on who reached the score threshold first. After a delay, resets the game state and variables.

Parameters
game_taskPointer to the GameTask instance.