nSnake
A ncurses implementation of the classic Snake game
|
Declaration of the player functions, defines and globals. More...
#include "nsnake.h"
Go to the source code of this file.
Data Structures | |
struct | player_pieces |
The structure of each part of the player. More... | |
struct | player_t |
Represent the snake itself. More... | |
Enumerations | |
enum | directions { UP = 0, LEFT, DOWN, RIGHT } |
Simple enum to make the directions of the player easier to read. | |
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. |
Declaration of the player functions, defines and globals.
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.