Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Committer:
AhmedPlaymaker
Date:
Wed May 08 16:39:24 2019 +0000
Revision:
87:871d9fecb593
Parent:
83:329da564799a
Child:
96:1ab67b3e6898
I have changed some variable names so that they have more meaning, and also added some more comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AhmedPlaymaker 87:871d9fecb593 1 #ifndef SNAKE_H
AhmedPlaymaker 87:871d9fecb593 2 #define SNAKE_H
AhmedPlaymaker 7:48ba87cd79b5 3
AhmedPlaymaker 7:48ba87cd79b5 4 #include "mbed.h"
AhmedPlaymaker 7:48ba87cd79b5 5 #include "N5110.h"
AhmedPlaymaker 7:48ba87cd79b5 6 #include "Gamepad.h"
AhmedPlaymaker 7:48ba87cd79b5 7
AhmedPlaymaker 7:48ba87cd79b5 8
AhmedPlaymaker 7:48ba87cd79b5 9 class Snake
AhmedPlaymaker 7:48ba87cd79b5 10 {
AhmedPlaymaker 69:55e309da7efd 11 public:
AhmedPlaymaker 69:55e309da7efd 12
AhmedPlaymaker 69:55e309da7efd 13
AhmedPlaymaker 7:48ba87cd79b5 14 Snake();
AhmedPlaymaker 7:48ba87cd79b5 15 ~Snake();
AhmedPlaymaker 69:55e309da7efd 16
AhmedPlaymaker 9:d1d79d4ee673 17 /** Initialise Snake
AhmedPlaymaker 7:48ba87cd79b5 18 *
AhmedPlaymaker 9:d1d79d4ee673 19 * This function initalises the Snake library.
AhmedPlaymaker 7:48ba87cd79b5 20 */
AhmedPlaymaker 83:329da564799a 21 void init(N5110 *lcd);
AhmedPlaymaker 83:329da564799a 22
AhmedPlaymaker 83:329da564799a 23 void _setLength(int length);
AhmedPlaymaker 83:329da564799a 24 void _setSpeed(int speed);
AhmedPlaymaker 69:55e309da7efd 25
AhmedPlaymaker 7:48ba87cd79b5 26 /** Draw
AhmedPlaymaker 7:48ba87cd79b5 27 *
AhmedPlaymaker 9:d1d79d4ee673 28 * This function draws the Snake sprite onto the screen at the specified coordinates.
AhmedPlaymaker 7:48ba87cd79b5 29 */
AhmedPlaymaker 83:329da564799a 30 void draw();
AhmedPlaymaker 69:55e309da7efd 31
AhmedPlaymaker 68:b9cfd27987ac 32 /** Set Position
AhmedPlaymaker 68:b9cfd27987ac 33 *
AhmedPlaymaker 68:b9cfd27987ac 34 * This function sets a position for where the snake should spawn.
AhmedPlaymaker 68:b9cfd27987ac 35 */
AhmedPlaymaker 68:b9cfd27987ac 36 void set_pos(Vector2D p);
AhmedPlaymaker 69:55e309da7efd 37
AhmedPlaymaker 7:48ba87cd79b5 38 /** Update
AhmedPlaymaker 7:48ba87cd79b5 39 *
AhmedPlaymaker 9:d1d79d4ee673 40 * This function updates the Snake sprite position on screen.
AhmedPlaymaker 7:48ba87cd79b5 41 */
AhmedPlaymaker 87:871d9fecb593 42 void update(Direction d, int* immobile_bead_n);
AhmedPlaymaker 71:4bd2b27693f3 43
AhmedPlaymaker 71:4bd2b27693f3 44 /** Chain Snake Together
AhmedPlaymaker 71:4bd2b27693f3 45 *
AhmedPlaymaker 71:4bd2b27693f3 46 * 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
AhmedPlaymaker 71:4bd2b27693f3 47 */
AhmedPlaymaker 87:871d9fecb593 48 void chainSnakeTogether(int* immobile_bead_n);
AhmedPlaymaker 71:4bd2b27693f3 49
AhmedPlaymaker 87:871d9fecb593 50 /** move Snake
AhmedPlaymaker 71:4bd2b27693f3 51 *
AhmedPlaymaker 71:4bd2b27693f3 52 * This function makes the controls of W/E directions only exclusive to the top beed in the snake
AhmedPlaymaker 71:4bd2b27693f3 53 */
AhmedPlaymaker 87:871d9fecb593 54 void moveSnake(int* immobile_bead_n);
AhmedPlaymaker 71:4bd2b27693f3 55
AhmedPlaymaker 71:4bd2b27693f3 56 /** Set Snake Limits
AhmedPlaymaker 71:4bd2b27693f3 57 *
AhmedPlaymaker 71:4bd2b27693f3 58 * This function makes sure that the snake stays where it is when it ate food and does not travel off the screen.
AhmedPlaymaker 71:4bd2b27693f3 59 */
AhmedPlaymaker 71:4bd2b27693f3 60 void _setSnakeLimits();
AhmedPlaymaker 69:55e309da7efd 61
AhmedPlaymaker 7:48ba87cd79b5 62 /** Get Position
AhmedPlaymaker 7:48ba87cd79b5 63 *
AhmedPlaymaker 9:d1d79d4ee673 64 * This function obtains the coordinate of the top-left pixel in the Snake sprite.
AhmedPlaymaker 7:48ba87cd79b5 65 */
AhmedPlaymaker 70:7caab8069b9b 66 Vector2D get_pos(int snakeIndex);
AhmedPlaymaker 70:7caab8069b9b 67
AhmedPlaymaker 81:4c1641e10dcd 68 int reset;
AhmedPlaymaker 87:871d9fecb593 69 int immobile_bead_n[10]; //each element in this array represents the beed number in the snake.
AhmedPlaymaker 69:55e309da7efd 70
AhmedPlaymaker 69:55e309da7efd 71 private:
AhmedPlaymaker 25:e827f1a8fadc 72 int _speed; //this is the speed of the snake flowing in the x axis.
AhmedPlaymaker 79:35cb65c52d25 73 int _x[10]; //each element in this array represents the x position of each beed in the snake.
AhmedPlaymaker 79:35cb65c52d25 74 int _y[10]; //each element in this array represents the y position of each beed in the snake.
AhmedPlaymaker 87:871d9fecb593 75 int _length; //stores thee length of snake to be drawn or managed in terms of structure.
AhmedPlaymaker 87:871d9fecb593 76 Direction _d; //Stores the direction the snake moves in.
AhmedPlaymaker 83:329da564799a 77
AhmedPlaymaker 83:329da564799a 78 //Pointer to the game pad object pad.
AhmedPlaymaker 83:329da564799a 79 Gamepad *_pad;
AhmedPlaymaker 83:329da564799a 80 //Pointer to the N5110 object lcd.
AhmedPlaymaker 83:329da564799a 81 N5110 *_lcd;
AhmedPlaymaker 7:48ba87cd79b5 82
AhmedPlaymaker 7:48ba87cd79b5 83 };
AhmedPlaymaker 7:48ba87cd79b5 84 #endif