SNAKE_STM32F3
Loading...
Searching...
No Matches
snake.h File Reference

Snake game logic module with low level state machine. More...

#include <stdint.h>
#include <stdbool.h>
#include "2dspace.h"
Include dependency graph for snake.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  snake_state
 Structure holding all snake info. More...

Macros

#define GAME_DIM   8
 Width of the game in snake length units (should be consulted with dispay width).
#define MAX_SNAKE_SIZE   (GAME_DIM*GAME_DIM)
 Maximum size that can be occupied by snake body parts.

Enumerations

enum  state_t { INIT , GAME_OVER , RUNNING }
 snake game state type More...

Functions

void snake_update (void)
 snake logic state machine function.
void snake_direction_request (direction_t requested_direction)
 Requests change of current snake direction in state machine.
void snake_init_request (int fruit_seed)
 Requests initialization of the snake game in state machine.
void snake_move_request (void)
 Requests 1-tile move of snake in state machine.
bool snake_is_over (void)
 Checks if snake game state is GAME_OVER.
const snake_statesnake_get_state (void)
 Passes current snake game state.

Detailed Description

Snake game logic module with low level state machine.

Author
bslrd
Date
2026

SPDX-License-Identifier: MIT

Macro Definition Documentation

◆ GAME_DIM

#define GAME_DIM   8

Width of the game in snake length units (should be consulted with dispay width).

◆ MAX_SNAKE_SIZE

#define MAX_SNAKE_SIZE   (GAME_DIM*GAME_DIM)

Maximum size that can be occupied by snake body parts.

Enumeration Type Documentation

◆ state_t

enum state_t

snake game state type

Enumerator
INIT 
GAME_OVER 
RUNNING 

Function Documentation

◆ snake_direction_request()

void snake_direction_request ( direction_t requested_direction)

Requests change of current snake direction in state machine.

Parameters
requested_directionDirection requested by input system.
Note
Called by game.c state machine.

◆ snake_get_state()

const snake_state * snake_get_state ( void )

Passes current snake game state.

Note
The pointer represents valid state until next snake_update() function use.

◆ snake_init_request()

void snake_init_request ( int fruit_seed)

Requests initialization of the snake game in state machine.

Parameters
fruit_seedSeed used for random fruit position generator.
Note
Called by game.c state machine.

◆ snake_is_over()

bool snake_is_over ( void )

Checks if snake game state is GAME_OVER.

◆ snake_move_request()

void snake_move_request ( void )

Requests 1-tile move of snake in state machine.

Note
Called by game.c state machine.

◆ snake_update()

void snake_update ( void )

snake logic state machine function.

Handles three snake game states (INIT, GAME_OVER, RUNNING).

Note
Called by game.c state machine.
Here is the call graph for this function: