Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
GameObjects/Snake/Snake.h@70:7caab8069b9b, 2019-05-04 (annotated)
- Committer:
- AhmedPlaymaker
- Date:
- Sat May 04 20:48:10 2019 +0000
- Revision:
- 70:7caab8069b9b
- Parent:
- 69:55e309da7efd
- Child:
- 71:4bd2b27693f3
Thanks to my newly created test files, I removed some of the most uselessly redundant functions in my snake class relating to get pos. The test classes helped me debug the problems with the bulky code by letting me know what coordinates were saved.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AhmedPlaymaker | 7:48ba87cd79b5 | 1 | #ifndef Snake_H |
AhmedPlaymaker | 7:48ba87cd79b5 | 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 | 68:b9cfd27987ac | 21 | void init(int length, int speed); |
AhmedPlaymaker | 69:55e309da7efd | 22 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 23 | /** Draw |
AhmedPlaymaker | 7:48ba87cd79b5 | 24 | * |
AhmedPlaymaker | 9:d1d79d4ee673 | 25 | * This function draws the Snake sprite onto the screen at the specified coordinates. |
AhmedPlaymaker | 7:48ba87cd79b5 | 26 | */ |
AhmedPlaymaker | 53:527cf297b088 | 27 | void draw(N5110 &lcd, int length, int level); |
AhmedPlaymaker | 69:55e309da7efd | 28 | |
AhmedPlaymaker | 68:b9cfd27987ac | 29 | /** Set Position |
AhmedPlaymaker | 68:b9cfd27987ac | 30 | * |
AhmedPlaymaker | 68:b9cfd27987ac | 31 | * This function sets a position for where the snake should spawn. |
AhmedPlaymaker | 68:b9cfd27987ac | 32 | */ |
AhmedPlaymaker | 68:b9cfd27987ac | 33 | void set_pos(Vector2D p); |
AhmedPlaymaker | 69:55e309da7efd | 34 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 35 | /** Update |
AhmedPlaymaker | 7:48ba87cd79b5 | 36 | * |
AhmedPlaymaker | 9:d1d79d4ee673 | 37 | * This function updates the Snake sprite position on screen. |
AhmedPlaymaker | 7:48ba87cd79b5 | 38 | */ |
AhmedPlaymaker | 41:4edac50f010d | 39 | void update(Direction d, int* b); |
AhmedPlaymaker | 69:55e309da7efd | 40 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 41 | /** Get Position |
AhmedPlaymaker | 7:48ba87cd79b5 | 42 | * |
AhmedPlaymaker | 9:d1d79d4ee673 | 43 | * This function obtains the coordinate of the top-left pixel in the Snake sprite. |
AhmedPlaymaker | 7:48ba87cd79b5 | 44 | */ |
AhmedPlaymaker | 70:7caab8069b9b | 45 | Vector2D get_pos(int snakeIndex); |
AhmedPlaymaker | 70:7caab8069b9b | 46 | |
AhmedPlaymaker | 13:9785f2404045 | 47 | int m; |
AhmedPlaymaker | 25:e827f1a8fadc | 48 | int b[15]; //each element in this array represents the beed number in the snake. |
AhmedPlaymaker | 69:55e309da7efd | 49 | |
AhmedPlaymaker | 69:55e309da7efd | 50 | private: |
AhmedPlaymaker | 25:e827f1a8fadc | 51 | int _speed; //this is the speed of the snake flowing in the x axis. |
AhmedPlaymaker | 25:e827f1a8fadc | 52 | int _x[15]; //each element in this array represents the x position of each beed in the snake. |
AhmedPlaymaker | 25:e827f1a8fadc | 53 | int _y[15]; //each element in this array represents the y position of each beed in the snake. |
AhmedPlaymaker | 37:ee47699915b8 | 54 | int _length; |
AhmedPlaymaker | 7:48ba87cd79b5 | 55 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 56 | }; |
AhmedPlaymaker | 7:48ba87cd79b5 | 57 | #endif |