Brick Game v1.0
Implementation of the game Tetris in the C programming language with a terminal user interface.
Loading...
Searching...
No Matches
GameData Struct Reference

A structure containing all data about the current game session. More...

#include <game.h>

+ Collaboration diagram for GameData:

Public Member Functions

void update_game_data (GameData *game_data)
 Advance the game by one frame.
 
PlayField get_combined_game_field (const GameData *game_data)
 Get the copy of the current playfield combined with the current piece.
 
int get_level (const GameData *game_data)
 Get the current level of the game.
 

Static Public Member Functions

static void transition_state (GameData *game_data, GameState new_state)
 Transition the current game state to the given one.
 
static void reset_game_data (GameData *game_data)
 Reset game state between play sessions.
 

Data Fields

GameState state
 Current state of the game's state machine.
 
PlayField field
 Current Playfield.
 
PlayedPiece played_piece
 Information about the currently played piece.
 
PieceType next_piece
 The type of the next piece to spawn.
 
FilledLines filled_lines
 Information about cleared lines.
 
int timer
 Counter used for timing different things.
 
int piece_land_y
 The y position of the last attached piece.
 
int score
 Current score.
 
int top_score
 Current highscore.
 
Inputs inputs
 Inputs that are being pressed this frame.
 
bool paused
 Indicates if the game is currently paused.
 
bool top_score_loaded
 Indicates if the top_score has been loaded from the file yet.
 

Detailed Description

A structure containing all data about the current game session.

Member Function Documentation

◆ update_game_data()

void update_game_data ( GameData game_data)

Advance the game by one frame.

If the game is not paused, the code for the current FSM state will be executed.

◆ get_combined_game_field()

PlayField get_combined_game_field ( const GameData game_data)

Get the copy of the current playfield combined with the current piece.

A wrapper for playfield_merge_piece.

◆ get_level()

int get_level ( const GameData game_data)

Get the current level of the game.

Level is fully depended on score. Starting at 1, it increases by one for every 600 points earned, until level 10.

Because level depends on score, it is not stored, instead it can just be calculated.

◆ transition_state()

static void transition_state ( GameData game_data,
GameState  new_state 
)
inlinestatic

Transition the current game state to the given one.

Resets the GameData::timer.

◆ reset_game_data()

static void reset_game_data ( GameData game_data)
inlinestatic

Reset game state between play sessions.

Preserves top score so it does not need to be reloaded.

Field Documentation

◆ field

PlayField GameData::field

Current Playfield.

Does not include the blocks of the played piece.

◆ filled_lines

FilledLines GameData::filled_lines

Information about cleared lines.

Only used in ATTACHING and CLEARING

◆ timer

int GameData::timer

Counter used for timing different things.

Used to time piece falling, clearing animation and spawn delay.

Reset to 0 on state transition.

◆ piece_land_y

int GameData::piece_land_y

The y position of the last attached piece.

Used to calculate spawn delay.

◆ top_score

int GameData::top_score

Current highscore.

It is stored in a file and thus, persists through games.

◆ top_score_loaded

bool GameData::top_score_loaded

Indicates if the top_score has been loaded from the file yet.

If this is false, top_score will be loaded during the next update.


The documentation for this struct was generated from the following files: