Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

SnakevsBlock Class Reference

SnakevsBlock Class Reference

SnakevsBlock Class. More...

#include <SnakevsBlock.h>

Public Member Functions

 SnakevsBlock ()
 Constructor.
 ~SnakevsBlock ()
 Destructor.
void init (N5110 *lcd, Gamepad *pad)
 Initialise Game Machine.
void reset ()
 This function prepares the game machine for the next level.
void object_initialisations ()
 This function initialises the objects that are used to functionalise the game.
void read_input (FXOS8700CQ &device, int g_mode)
 This function obtains numeric data from the gamepads joystick.
void calculateTilt (FXOS8700CQ &device)
 This function reads the angle of tilt required for motion contol and also processes it by reseting the angle buffer if A is pressed.
void lightTheLEDS ()
 This function ligths the LEDS dependent on the direction of travel.
void updateSnakeLengthAndMovement ()
 This function updates length and motion data inside the snake class and also uses the length manager class to update length.
void draw ()
 This function contains the draw functions of the other libraries used in the game.
void update ()
 This function contains the update functions of the other libraries used in the game.
int CheckGameProgression (SDFileSystem &sd)
 Function handles level progression and level failure operations by using the class WinLoose.
void get_pos ()
 This function contains the Get Position functions of all the class objects used in the game and saves them to use in an array throughout the class.
void _setVelocity (int srn)
 this is to stop/move the background (food and blocks), when collision occurs at a length greater than 10.lock.
void MakeDefaultMotionFree ()
 This function makes the default motion of the snake freemoving before a collision is checked for, to forget the previous collision.
void makeVirtualLengthMaxTen ()
 This makes the virtual length -> 10 for the side collision implementation because if the length is fifteen and the last beed collides, it still is the 10th beed on screen.

Detailed Description

SnakevsBlock Class.

This class controls the game by detecting collisions, drawing objects and updating game parameters.

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

Definition at line 23 of file SnakevsBlock.h.


Constructor & Destructor Documentation

SnakevsBlock (  )

Constructor.

Definition at line 3 of file SnakevsBlock.cpp.

~SnakevsBlock (  )

Destructor.

Definition at line 8 of file SnakevsBlock.cpp.


Member Function Documentation

void _setVelocity ( int  srn )

this is to stop/move the background (food and blocks), when collision occurs at a length greater than 10.lock.

Parameters:
srnthis is the serial number of blocks and tells us which of the 5 blocks we are colliding with

Definition at line 338 of file SnakevsBlock.cpp.

void calculateTilt ( FXOS8700CQ &  device )

This function reads the angle of tilt required for motion contol and also processes it by reseting the angle buffer if A is pressed.

Parameters:
FXOS8700CQ&device

The FXOS8700CQ library.

Definition at line 94 of file SnakevsBlock.cpp.

int CheckGameProgression ( SDFileSystem &  sd )

Function handles level progression and level failure operations by using the class WinLoose.

Parameters:
SDFileSystem&sd

The SDFileSystem library.

Definition at line 182 of file SnakevsBlock.cpp.

void draw (  )

This function contains the draw functions of the other libraries used in the game.

Definition at line 133 of file SnakevsBlock.cpp.

void get_pos (  )

This function contains the Get Position functions of all the class objects used in the game and saves them to use in an array throughout the class.

Definition at line 206 of file SnakevsBlock.cpp.

void init ( N5110 lcd,
Gamepad pad 
)

Initialise Game Machine.

This function initialises the game machine. Initialises all game parameters and objects and therefore configures the start state of the game.

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.

Parameters:
Gamepad*pad

pointer to the gamepad 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 13 of file SnakevsBlock.cpp.

void lightTheLEDS (  )

This function ligths the LEDS dependent on the direction of travel.

Definition at line 109 of file SnakevsBlock.cpp.

void MakeDefaultMotionFree (  )

This function makes the default motion of the snake freemoving before a collision is checked for, to forget the previous collision.

Definition at line 376 of file SnakevsBlock.cpp.

void makeVirtualLengthMaxTen (  )

This makes the virtual length -> 10 for the side collision implementation because if the length is fifteen and the last beed collides, it still is the 10th beed on screen.

Definition at line 476 of file SnakevsBlock.cpp.

void object_initialisations (  )

This function initialises the objects that are used to functionalise the game.

Definition at line 57 of file SnakevsBlock.cpp.

void read_input ( FXOS8700CQ &  device,
int  g_mode 
)

This function obtains numeric data from the gamepads joystick.

Parameters:
FXOS8700CQ&device

The FXOS8700CQ library. g_mode

Contains a value that is used to choose between setting the controls based on joystick or motion control.

Definition at line 70 of file SnakevsBlock.cpp.

void reset (  )

This function prepares the game machine for the next level.

Definition at line 43 of file SnakevsBlock.cpp.

void update (  )

This function contains the update functions of the other libraries used in the game.

Definition at line 159 of file SnakevsBlock.cpp.

void updateSnakeLengthAndMovement (  )

This function updates length and motion data inside the snake class and also uses the length manager class to update length.

Definition at line 126 of file SnakevsBlock.cpp.