Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Committer:
AhmedPlaymaker
Date:
Thu May 09 09:23:57 2019 +0000
Revision:
96:1ab67b3e6898
Parent:
95:b068b0735f45
Documented snakes class

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AhmedPlaymaker 10:751bd953fa27 1 #ifndef BLOCKS_H
AhmedPlaymaker 10:751bd953fa27 2 #define BLOCKS_H
AhmedPlaymaker 10:751bd953fa27 3
AhmedPlaymaker 10:751bd953fa27 4 #include "mbed.h"
AhmedPlaymaker 10:751bd953fa27 5 #include "N5110.h"
AhmedPlaymaker 10:751bd953fa27 6 #include "Gamepad.h"
AhmedPlaymaker 10:751bd953fa27 7
AhmedPlaymaker 95:b068b0735f45 8 /** Blocks Class
AhmedPlaymaker 95:b068b0735f45 9 @brief This class draws and updates blocks after every collision, and randomly, but logically assigns numbers to the block.
AhmedPlaymaker 95:b068b0735f45 10 @author Ahmed N.Adamjee
AhmedPlaymaker 96:1ab67b3e6898 11 @date 9th May 2019
AhmedPlaymaker 95:b068b0735f45 12 */
AhmedPlaymaker 10:751bd953fa27 13 class Blocks
AhmedPlaymaker 10:751bd953fa27 14 {
AhmedPlaymaker 95:b068b0735f45 15 public:
AhmedPlaymaker 95:b068b0735f45 16 /** Constructor */
AhmedPlaymaker 10:751bd953fa27 17 Blocks();
AhmedPlaymaker 95:b068b0735f45 18 /** Destructor */
AhmedPlaymaker 10:751bd953fa27 19 ~Blocks();
AhmedPlaymaker 95:b068b0735f45 20
AhmedPlaymaker 95:b068b0735f45 21 /**
AhmedPlaymaker 95:b068b0735f45 22 * @brief Initialises the blocks position struct and reset variable and gets pointers of lcd from int main() to be used privately in the entire class.
AhmedPlaymaker 95:b068b0735f45 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 10:751bd953fa27 24 */
AhmedPlaymaker 83:329da564799a 25 void init(N5110 *lcd);
AhmedPlaymaker 95:b068b0735f45 26
AhmedPlaymaker 95:b068b0735f45 27 /**
AhmedPlaymaker 95:b068b0735f45 28 * @brief This function draws the blocks onto the screen and selects numbers to be stored in them.
AhmedPlaymaker 95:b068b0735f45 29 * @param length @details This is the length of the snake, which is recieved from the SnakevsBlocks class to store numbers with relation to it's length.
AhmedPlaymaker 10:751bd953fa27 30 */
AhmedPlaymaker 83:329da564799a 31 void draw(int length);
AhmedPlaymaker 95:b068b0735f45 32
AhmedPlaymaker 95:b068b0735f45 33 /**
AhmedPlaymaker 95:b068b0735f45 34 * @brief This function draws the Block's sides onto the screen as the blocks are basically individual boxes without sides.
AhmedPlaymaker 53:527cf297b088 35 */
AhmedPlaymaker 83:329da564799a 36 void DrawFrame();
AhmedPlaymaker 95:b068b0735f45 37
AhmedPlaymaker 95:b068b0735f45 38 /**
AhmedPlaymaker 95:b068b0735f45 39 * @brief This function chooses the correct block using a case structure and draws them onto the screen.
AhmedPlaymaker 53:527cf297b088 40 */
AhmedPlaymaker 83:329da564799a 41 void ChooseBlocks();
AhmedPlaymaker 95:b068b0735f45 42
AhmedPlaymaker 95:b068b0735f45 43 /**
AhmedPlaymaker 95:b068b0735f45 44 * @brief This function updates the position of the Blocks as they move down the screen by reacting to collisions if any.
AhmedPlaymaker 95:b068b0735f45 45 * @param blocknum @details saves the numbers inside the block with respect to it's serial number.
AhmedPlaymaker 95:b068b0735f45 46 * @param blockgap @details this is the amount in pixels of the gap between blocks and sets the frequency of block fall.
AhmedPlaymaker 95:b068b0735f45 47 * @param srn @details sr number of the block we are refering to (1 to 5).
AhmedPlaymaker 95:b068b0735f45 48 * @param send_block_number @details makes sure that the block number is only updated when this is at a logic of 1.
AhmedPlaymaker 10:751bd953fa27 49 */
AhmedPlaymaker 95:b068b0735f45 50 void update(int blocknum, int blockgap, int srn, bool send_block_number);
AhmedPlaymaker 95:b068b0735f45 51
AhmedPlaymaker 95:b068b0735f45 52 /**
AhmedPlaymaker 95:b068b0735f45 53 * @brief This function sends the coordinates of the top-left pixel in the Blocks sprites.
AhmedPlaymaker 96:1ab67b3e6898 54 * @returns Vector2D blockpos @details This is a struct that returns the x and y position of the origin of the blocks sprite to be read.
AhmedPlaymaker 10:751bd953fa27 55 */
AhmedPlaymaker 10:751bd953fa27 56 Vector2D get_pos();
AhmedPlaymaker 95:b068b0735f45 57
AhmedPlaymaker 95:b068b0735f45 58 /**
AhmedPlaymaker 95:b068b0735f45 59 * @brief This function sends the number inside the Blocks sprite at a specefic location.
AhmedPlaymaker 95:b068b0735f45 60 * @returns caseselect[5] @details The array of all the numbers saved inside the blocks.
AhmedPlaymaker 12:1e601b176437 61 */
AhmedPlaymaker 12:1e601b176437 62 int * get_number();
AhmedPlaymaker 95:b068b0735f45 63
AhmedPlaymaker 95:b068b0735f45 64 /**
AhmedPlaymaker 95:b068b0735f45 65 * @brief This function is used to change the position of the sprite to specific coordinates when called.
AhmedPlaymaker 95:b068b0735f45 66 * @param Vector2D p @details Stores the values from the struct obtained as the new coordinates of the block.
AhmedPlaymaker 10:751bd953fa27 67 */
AhmedPlaymaker 10:751bd953fa27 68 void set_pos(Vector2D p);
AhmedPlaymaker 95:b068b0735f45 69
AhmedPlaymaker 95:b068b0735f45 70
AhmedPlaymaker 47:b448ffd073e7 71 double round; //used to save the rounded number to set the value inside the block.
AhmedPlaymaker 95:b068b0735f45 72 int caseselect[5]; //The array of all the numbers saved inside the blocks.
AhmedPlaymaker 95:b068b0735f45 73 Vector2D velocity; //This is a struct that stores the x and y axis velocities of the blocks.
AhmedPlaymaker 10:751bd953fa27 74
AhmedPlaymaker 95:b068b0735f45 75 private:
AhmedPlaymaker 95:b068b0735f45 76 int _length; //length of the snake
AhmedPlaymaker 95:b068b0735f45 77 int reset; //reset is used to draw a new set of blocks.
AhmedPlaymaker 10:751bd953fa27 78 int _bx; //block x
AhmedPlaymaker 10:751bd953fa27 79 int _by; //block y
AhmedPlaymaker 84:9950d561fdf8 80
AhmedPlaymaker 83:329da564799a 81 //Pointer to the game pad object pad.
AhmedPlaymaker 83:329da564799a 82 Gamepad *_pad;
AhmedPlaymaker 83:329da564799a 83 //Pointer to the N5110 object lcd.
AhmedPlaymaker 83:329da564799a 84 N5110 *_lcd;
AhmedPlaymaker 10:751bd953fa27 85
AhmedPlaymaker 10:751bd953fa27 86 };
AhmedPlaymaker 10:751bd953fa27 87 #endif