nSnake
A ncurses implementation of the classic Snake game
|
Definition of the player functions. More...
Functions | |
void | player_change_direction (int new_direction) |
Changes the snake direction based on the input received. | |
int | player_collided_with_borders () |
Depending on the game mode, the player may be able to hit borders or not. | |
void | player_exit () |
Free all memory associated with the player. | |
int | player_hit_borders () |
Checks collision between the snake and the walls. | |
int | player_hit_fruit () |
Checks if the snake has eaten the fruit. | |
int | player_hit_self () |
Checks if the snake have collided with itself. | |
void | player_increase_score (int add) |
Simply increases the score by the value sent as the parameter. | |
void | player_increase_size (int size) |
Increases the snake size. | |
void | player_init () |
Starts the player-related variables. | |
void | player_teleport_borders () |
Teleports the player around the borders. | |
void | player_update () |
Updates the player position, one piece at a time. | |
Variables | |
struct player_t | snake |
Global player structure. |
Definition of the player functions.
int player_collided_with_borders | ( | ) |
Depending on the game mode, the player may be able to hit borders or not.
If it is possible, we call player_hit_borders().
int player_hit_borders | ( | ) |
Checks collision between the snake and the walls.
int player_hit_fruit | ( | ) |
Checks if the snake has eaten the fruit.
void player_increase_size | ( | int | size | ) |
Increases the snake size.
Here we have the core function of this file. Each time the snake increases its size, we expand the array that represents its body.
void player_update | ( | ) |
Updates the player position, one piece at a time.
Start by moving the snake pieces one at a time from the last to the first, and then moves the head according to its direction.