![](/media/cache/profiles/LinkedIn_0NghoZJ.jpeg.50x50_q85.jpg)
Snake vs Block Game to be run upon K64F.
GameEngine/SnakevsBlock/SnakevsBlock.h
- Committer:
- AhmedPlaymaker
- Date:
- 2019-05-08
- Revision:
- 87:871d9fecb593
- Parent:
- 84:9950d561fdf8
- Child:
- 92:693a6ae0ff8e
File content as of revision 87:871d9fecb593:
#ifndef SNAKEVSBLOCK_H #define SNAKEVSBLOCK_H #include "mbed.h" #include "N5110.h" #include "FXOS8700CQ.h" #include "Gamepad.h" #include "Snake.h" #include "LengthManager.h" #include "WinLoose.h" #include "SnakeFood.h" #include "Blocks.h" #include "Barriers.h" #include "StartScreen.h" #include "Stats.h" #include "SDFileSystem.h" class SnakevsBlock { public: SnakevsBlock(); ~SnakevsBlock(); /** Initialise Game Machine * * This function initialises the game machine. */ void init(N5110 *lcd, Gamepad *pad); /** Reset Game Machine * * This function prepares the game machine for the next level. */ void reset( ); /** Initialise objects * * This function initialises the objects that are used to functionalise the game. */ void object_initialisations(); /** Read Input * * This function obtains numeric data from the gamepads joystick. */ void read_input(FXOS8700CQ &device, int gm); /** Calculate Tilt * * 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 calculateTilt(FXOS8700CQ &device); /** Light The LEDS * * This function ligths the LEDS dependent on the direction of travel. */ void lightTheLEDS(); /** Update Snake Length And Movement * * This function updates length and motion data inside the snake class and also uses the length manager class to update length. */ void updateSnakeLengthAndMovement(); /** Draw * * This function contains the draw functions of the other libraries used in the game. */ void draw(); /** Update * * This function contains the update functions of the other libraries used in the game. */ void update(); /** Check Game Progression * * Function handles level progression and level failure operations by using the class WinLoose. */ int CheckGameProgression(SDFileSystem &sd); /** Get Position * * This function contains the Get Position functions of the otehr libraries used in the game. */ void get_pos(); //Gamepad @enginePad private: /** Check for Snake and Food collision * * This function checks if the Snake has come into contact with it's food. */ void CheckSnakeFoodCollision(); /** Check Snake Food Y Collision * * This function automatically detects each combination of collision in the y postion. */ void CheckSnakeFoodYCollision(int food_sr); /** Check Snake Food X Collision * * This function automatically detects each combination of collision in the x postion. */ void CheckSnakeFoodXCollision(int food_sr); /** Implement Snake Food Collision * * This function automatically detects which food we are interacting with and increases the snake length accordingly. */ void ImplementSnakeFoodCollision(int food_sr); /** Check for Snake and Block collision * * This function checks if the Snake has come into contact with any Block. */ void CheckSnakeBlockCollision(); /** Implement velocity alteration. * * this is to stop/move the background (food and blocks), when collision occurs at a length greater than 10.lock. */ void _setVelocity(int srn); /** Check Block * * This function returns the srn of the block we are colliding with; */ int CheckBlock(int Block); /** Implement Collision * * This function allows the appropriate maths to take place after every collision. */ void ImplementSnakeBlockCollision(); /** Check for Snake and Block Sides collision * * This function checks if the Snake has come into contact with any the sides of the block and stops it moving. */ void CheckSnakeBlockSidesCollision(); /** Make Default Motion Free * * This function makes the default motion of the snake freemoving before a collision is checked for, to forget the previous collision. */ void MakeDefaultMotionFree(); /** Check Collision in Y axis * * This function checks if the Snake and blocks collide anywhere in the Y axis. */ void CheckSnakeBlockSidesYCollision(int i); /** Check Collision in X axis * * This function checks if the Snake and blocks collide anywhere in the X axis. */ void CheckSnakeBlockSidesXCollision(int i); /** Check Block sides Collision is East or West * * checks if the colliding wall is on east side or west side and then calls ImplementBarrierCollision(i) to carry out the required task. */ void CheckSnakeBlockSidesEastWestCollision(int X, int i); /** Check for Snake and Barrier collisions. * * This function checks if the Snake has come into contact with any the sides of the barriers and stops it moving in the X axis if true. */ void CheckSnakeBarrierCollision(int bar_sr_no); /** Check Collision in Y axis * * This function checks if the Snake and blocks collide anywhere in the Y axis. */ void CheckSnakeBarrierYCollision(int i, int bar_sr_no); //i is the index of the snake beed and checks for all possible collisions with the snake respective to it's length. /** Check Barrier Collision is East or West * * checks if the colliding barrier's side is on east side or west side of snake and then calls ImplementBarrierCollision(i) to carry out the required task. */ void CheckSnakeBarrierEastWestCollision(int i, int bar_sr_no); //i checks for all possible collisions with the snake respective to it's length. /** Make Virtual Length Max Ten * * 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. */ void makeVirtualLengthMaxTen(); /** Stop X Axis Motion * * This function implements the sides collision by making the x axis speed of the particular snake beed 0. */ void ImplementBarrierCollision(int i); //OBJECT DECLARATIONS. Snake _s; LengthManager _l; WinLoose _wl; SnakeFood _f; SnakeFood _ff; SnakeFood _fff; Blocks _b; Barriers _barA; Barriers _barB; Stats _Setstats; //Pointer to the game pad object pad. Gamepad *_pad; //Pointer to the N5110 object lcd. N5110 *_lcd; //OBJECT POSITIONS ON SCREEN. int snakex; //x position of top beed int snakey; //y position of top beed Vector2D snake_pos[10]; //saves the position of all the snake beeds in an array for ease of collision processing. Vector2D food_pos[3]; //saves the position of all 3 snake food on the screen in a single array for ease of collision processing. Vector2D b_pos; //saves the origin of the blocks on the screen (this is the top left corner of the block row). Vector2D bar_pos[2]; //saves the origin of the barrier on the screen (this is the top left corner of the barrier). //LEVEL PROGRESSION, FAILURE AND STATISTICS PARAMETERS. int level; // this is diffrent to int _length as this stops at 10 to not complicate collisions as the snake doesn't grow longer than 10 visually. char bufferlevel[14]; //this helps me print the level on screen. int back; //enables the player to go back on main menu if back is pressed. int _maxLength; // this makes us go to the next level if if maxLength is achieved; //Block, Food and Barrier Y AXIS VELOCITY, SNAKE LENGTH ,MAX VIRTUAL LENGTH AND VARABLE THAT ALLOWS FREE MOTION OF A SPECIFIC BEED NUMBER OF THE SNAKE. int velocity; //this is to stop/move the background (food and blocks), when collision occurs at a length greater than 10. int _length; //this is diffrent to the _virtualLength as this saves the length of the snake, for collision detection relative to it's length and calculations. int _virtualLength; //saves the length of the snake, for collision detection relative to it's Max screen length. int immobile_bead_n[10]; //this saves the beed number of the colliding snake, if beed 3 from top was colliding with any obstruction, immobile_bead_n[2] will be 1. //TURN DIRECTION, TILT ANGLE AND ANGLE RESET BUFFER (GARBAGE). Direction _d; float _tiltAngle; //saves the angle of tilt. int garbage; //to save the angle at the point button A is pressed. //BLOCK NUMBERS, BLOCK DROP GAP, BLOCK DETECTION SRN AND VARIABLE TO SEND/NOT BLOCK NUMBER TO BLOCK CLASS int *b_number; //pointer to save the numbers inside the block. int blocknum; // saves the number inside the specific colliding block, for calculations. int blockgap; //to change frequency of fall int srn; //sr number of the block we are colliding with (1 to 5) int send_block_number; //makes sure that the block number is only updated when send is activated. //INITIAL FOOD AND BLOCK DROP GAP. int _dropbuff; //this makes food 1,2,and 3 come at seperate times }; #endif