Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Committer:
AhmedPlaymaker
Date:
Thu May 09 08:35:02 2019 +0000
Revision:
95:b068b0735f45
Parent:
94:4e603bd6c381
Child:
96:1ab67b3e6898
documented the blocks class

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AhmedPlaymaker 81:4c1641e10dcd 1 #ifndef BARRIERS_H
AhmedPlaymaker 81:4c1641e10dcd 2 #define BARRIERS_H
AhmedPlaymaker 81:4c1641e10dcd 3
AhmedPlaymaker 81:4c1641e10dcd 4 #include "mbed.h"
AhmedPlaymaker 81:4c1641e10dcd 5 #include "N5110.h"
AhmedPlaymaker 81:4c1641e10dcd 6 #include "Gamepad.h"
AhmedPlaymaker 81:4c1641e10dcd 7
AhmedPlaymaker 94:4e603bd6c381 8 /** Barriers Class
AhmedPlaymaker 94:4e603bd6c381 9 @brief This class helps to draw barriers in the game which are obstacles the snake has no effect to but stops it's x axis motion.
AhmedPlaymaker 94:4e603bd6c381 10 @author Ahmed N.Adamjee
AhmedPlaymaker 94:4e603bd6c381 11 @date 9th May 2019
AhmedPlaymaker 94:4e603bd6c381 12 */
AhmedPlaymaker 81:4c1641e10dcd 13 class Barriers
AhmedPlaymaker 81:4c1641e10dcd 14 {
AhmedPlaymaker 94:4e603bd6c381 15 public:
AhmedPlaymaker 94:4e603bd6c381 16 /** Constructor */
AhmedPlaymaker 81:4c1641e10dcd 17 Barriers();
AhmedPlaymaker 94:4e603bd6c381 18 /** Destructor */
AhmedPlaymaker 81:4c1641e10dcd 19 ~Barriers();
AhmedPlaymaker 94:4e603bd6c381 20
AhmedPlaymaker 94:4e603bd6c381 21 /**
AhmedPlaymaker 94:4e603bd6c381 22 * @brief Initialises barrier position and reset variable and gets pointers of lcd from int main() to be used privately in the entire class.
AhmedPlaymaker 94:4e603bd6c381 23 * @param N5110 *lcd @details 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.
AhmedPlaymaker 81:4c1641e10dcd 24 */
AhmedPlaymaker 83:329da564799a 25 void init(N5110 *lcd);
AhmedPlaymaker 94:4e603bd6c381 26
AhmedPlaymaker 94:4e603bd6c381 27 /**
AhmedPlaymaker 94:4e603bd6c381 28 * @brief This function draws the Barriers onto the screen.
AhmedPlaymaker 94:4e603bd6c381 29 * @param block_y_pos @details This is the y axis position of the blocks sprites.
AhmedPlaymaker 81:4c1641e10dcd 30 */
AhmedPlaymaker 94:4e603bd6c381 31 void draw(int block_y_pos);
AhmedPlaymaker 94:4e603bd6c381 32
AhmedPlaymaker 94:4e603bd6c381 33 /**
AhmedPlaymaker 94:4e603bd6c381 34 * @brief This function updates the position of the Barriers as they move down the screen.
AhmedPlaymaker 94:4e603bd6c381 35 * @param blockgap @details this is the amount in pixels of the gap between blocks
AhmedPlaymaker 81:4c1641e10dcd 36 */
AhmedPlaymaker 81:4c1641e10dcd 37 void update(int blockgap);
AhmedPlaymaker 94:4e603bd6c381 38
AhmedPlaymaker 94:4e603bd6c381 39 /**
AhmedPlaymaker 94:4e603bd6c381 40 * @brief This function obtains the coordinates of the top-left pixel in the Barriers sprites.
AhmedPlaymaker 94:4e603bd6c381 41 * @returns Vector2D barrierpos @details this is a struct that saves the x and y psition of the origin of the barriers sprite to be read.
AhmedPlaymaker 81:4c1641e10dcd 42 */
AhmedPlaymaker 81:4c1641e10dcd 43 Vector2D get_pos();
AhmedPlaymaker 94:4e603bd6c381 44
AhmedPlaymaker 94:4e603bd6c381 45 /**
AhmedPlaymaker 94:4e603bd6c381 46 * @brief This function is used to change the position of the barrier to specific coordinates when called.
AhmedPlaymaker 94:4e603bd6c381 47 * @param Vector2D p @details this is a struct that saves the x and y psition of the origin of the barriers sprite to be set.
AhmedPlaymaker 81:4c1641e10dcd 48 */
AhmedPlaymaker 81:4c1641e10dcd 49 void set_pos(Vector2D p);
AhmedPlaymaker 94:4e603bd6c381 50
AhmedPlaymaker 94:4e603bd6c381 51
AhmedPlaymaker 94:4e603bd6c381 52 Vector2D velocity; //This is a struct that stores the x and y axis velocities of the barrier.
AhmedPlaymaker 94:4e603bd6c381 53
AhmedPlaymaker 94:4e603bd6c381 54 private:
AhmedPlaymaker 94:4e603bd6c381 55 int reset; //reset is used to draw a new set of barriers.
AhmedPlaymaker 81:4c1641e10dcd 56 int _barx; //barrier x
AhmedPlaymaker 81:4c1641e10dcd 57 int _bary; //barrier y
AhmedPlaymaker 94:4e603bd6c381 58 int _barriergap; //gap between barriers falling
AhmedPlaymaker 94:4e603bd6c381 59 int _blockgap; //gap between blocks falling.
AhmedPlaymaker 94:4e603bd6c381 60
AhmedPlaymaker 83:329da564799a 61 //Pointer to the game pad object pad.
AhmedPlaymaker 83:329da564799a 62 Gamepad *_pad;
AhmedPlaymaker 83:329da564799a 63 //Pointer to the N5110 object lcd.
AhmedPlaymaker 83:329da564799a 64 N5110 *_lcd;
AhmedPlaymaker 81:4c1641e10dcd 65
AhmedPlaymaker 81:4c1641e10dcd 66 };
AhmedPlaymaker 81:4c1641e10dcd 67 #endif