Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Snake Class Reference

Snake Class Reference

Snake Class. More...

#include <Snake.h>

Public Member Functions

 Snake ()
 Constructor.
 ~Snake ()
 Destructor.
void init (N5110 *lcd)
 Initialises the snakes position struct and reset variable and gets pointers of lcd from int main() to be used privately in the entire class.
void _setLength (int length)
 This mutator sets the length of the snake directly when called.
void _setSpeed (int speed)
 This mutator sets the speed of the snake directly when called.
void draw ()
 This function draws the Snake sprite onto the screen at the specified coordinates.
void set_pos (Vector2D p)
 This function sets a position for where the snake should spawn.
void update (Direction d, int *immobile_bead_n)
 This function updates the Snake sprite position on screen.
void chainSnakeTogether (int *immobile_bead_n)
 This function makes all of the snake beeds chained together by making the lower ones drag towards where the top one was in the previous loop.
void moveSnake (int *immobile_bead_n)
 This function makes the controls of W/E directions only exclusive to the top beed in the snake.
void _setSnakeLimits ()
 This function makes sure that the snake stays where it is when it ate food and does not travel off the screen.
Vector2D get_pos (int snakeIndex)
 This function returns the coordinate of the top-left pixel in the Snake sprite of each bead which is reffered to by snakeIndex.

Detailed Description

Snake Class.

This class draws and updates snake after every collision, and creates perfect animations of the snake moving.

Author:
Ahmed N.Adamjee
Date:
9th May 2019

Definition at line 13 of file Snake.h.


Constructor & Destructor Documentation

Snake (  )

Constructor.

Definition at line 3 of file Snake.cpp.

~Snake (  )

Destructor.

Definition at line 8 of file Snake.cpp.


Member Function Documentation

void _setLength ( int  length )

This mutator sets the length of the snake directly when called.

Parameters:
lengthThis is the length of the snake, which is recieved from the SnakevsBlocks class or test files to draw snake with relation to it's length.

Definition at line 27 of file Snake.cpp.

void _setSnakeLimits (  )

This function makes sure that the snake stays where it is when it ate food and does not travel off the screen.

Definition at line 135 of file Snake.cpp.

void _setSpeed ( int  speed )

This mutator sets the speed of the snake directly when called.

Parameters:
speedThis is the x axis speed of the snake, which is recieved from the SnakevsBlocks class or test files to move snake with respect to joystick or motion control input.

Definition at line 35 of file Snake.cpp.

void chainSnakeTogether ( int *  immobile_bead_n )

This function makes all of the snake beeds chained together by making the lower ones drag towards where the top one was in the previous loop.

Parameters:
immobile_bead_n[10]this array is indexed by the beed number of the colliding snake, if immobile_bead_n[2] = 1 the particular bead can move freely.

Definition at line 101 of file Snake.cpp.

void draw (  )

This function draws the Snake sprite onto the screen at the specified coordinates.

Definition at line 40 of file Snake.cpp.

Vector2D get_pos ( int  snakeIndex )

This function returns the coordinate of the top-left pixel in the Snake sprite of each bead which is reffered to by snakeIndex.

Parameters:
intsnakeIndex

This is the index of the snake bead of which the position needs to be returned.

Returns:
Vector2D snakepos

This is a struct that returns the x and y position of the snake bead that is being referred to by the snakeIndex.

Definition at line 68 of file Snake.cpp.

void init ( N5110 lcd )

Initialises the snakes position struct and reset variable and gets pointers of lcd from int main() to be used privately in the entire class.

Parameters:
N5110*lcd

pointer to the N5110 object in main, address of this pointer is saved to make availability to the entire class, without passing address to each function.

Definition at line 20 of file Snake.cpp.

void moveSnake ( int *  immobile_bead_n )

This function makes the controls of W/E directions only exclusive to the top beed in the snake.

Parameters:
immobile_bead_n[10]this array is indexed by the beed number of the colliding snake, if immobile_bead_n[2] = 1 the particular bead can move freely.

Definition at line 117 of file Snake.cpp.

void set_pos ( Vector2D  p )

This function sets a position for where the snake should spawn.

Parameters:
Vector2Dp

This is a struct that saves the x and y position one of the snake beads during the time of initialisation and sets other snake bead coordinates with respect to this.

Definition at line 57 of file Snake.cpp.

void update ( Direction  d,
int *  immobile_bead_n 
)

This function updates the Snake sprite position on screen.

Parameters:
Directiond

This struct saves the direction of snake movement.

Parameters:
immobile_bead_n[10]this array is indexed by the beed number of the colliding snake, if immobile_bead_n[2] = 1 the particular bead can move freely.

Definition at line 90 of file Snake.cpp.