Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
GameObjects/Blocks/Blocks.h@54:20abd16c7d74, 2019-04-26 (annotated)
- Committer:
- AhmedPlaymaker
- Date:
- Fri Apr 26 19:32:57 2019 +0000
- Revision:
- 54:20abd16c7d74
- Parent:
- 53:527cf297b088
- Child:
- 81:4c1641e10dcd
There was a bug where the snake didnt detect the block on some occasions , i think it's fixed now.
Who changed what in which revision?
User | Revision | Line number | New 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 | 10:751bd953fa27 | 8 | |
AhmedPlaymaker | 10:751bd953fa27 | 9 | class Blocks |
AhmedPlaymaker | 10:751bd953fa27 | 10 | { |
AhmedPlaymaker | 10:751bd953fa27 | 11 | public: |
AhmedPlaymaker | 10:751bd953fa27 | 12 | Blocks(); |
AhmedPlaymaker | 10:751bd953fa27 | 13 | ~Blocks(); |
AhmedPlaymaker | 10:751bd953fa27 | 14 | /** Initialise Blocks |
AhmedPlaymaker | 10:751bd953fa27 | 15 | * |
AhmedPlaymaker | 10:751bd953fa27 | 16 | * This function initialises the Blocks library. |
AhmedPlaymaker | 10:751bd953fa27 | 17 | */ |
AhmedPlaymaker | 10:751bd953fa27 | 18 | void init(); |
AhmedPlaymaker | 10:751bd953fa27 | 19 | |
AhmedPlaymaker | 10:751bd953fa27 | 20 | /** Draw |
AhmedPlaymaker | 10:751bd953fa27 | 21 | * |
AhmedPlaymaker | 10:751bd953fa27 | 22 | * This function draws the Blocks onto the screen. |
AhmedPlaymaker | 10:751bd953fa27 | 23 | */ |
AhmedPlaymaker | 48:d774bb162c61 | 24 | void draw(N5110 &lcd, int length); |
AhmedPlaymaker | 10:751bd953fa27 | 25 | |
AhmedPlaymaker | 53:527cf297b088 | 26 | /** Draw Frame |
AhmedPlaymaker | 53:527cf297b088 | 27 | * |
AhmedPlaymaker | 53:527cf297b088 | 28 | * This function draws the Blocks' sides onto the screen. |
AhmedPlaymaker | 53:527cf297b088 | 29 | */ |
AhmedPlaymaker | 53:527cf297b088 | 30 | void DrawFrame(N5110 &lcd); |
AhmedPlaymaker | 53:527cf297b088 | 31 | |
AhmedPlaymaker | 53:527cf297b088 | 32 | /** Choose Blocks |
AhmedPlaymaker | 53:527cf297b088 | 33 | * |
AhmedPlaymaker | 53:527cf297b088 | 34 | * This function chooses the correct block using a case structure and draws them onto the screen. |
AhmedPlaymaker | 53:527cf297b088 | 35 | */ |
AhmedPlaymaker | 53:527cf297b088 | 36 | void ChooseBlocks(N5110 &lcd); |
AhmedPlaymaker | 53:527cf297b088 | 37 | |
AhmedPlaymaker | 10:751bd953fa27 | 38 | /** Update |
AhmedPlaymaker | 10:751bd953fa27 | 39 | * |
AhmedPlaymaker | 10:751bd953fa27 | 40 | * This function updates the position of the Blocks as they move down the screen. |
AhmedPlaymaker | 10:751bd953fa27 | 41 | */ |
AhmedPlaymaker | 48:d774bb162c61 | 42 | void update(int blocknum, int blockgap, int srn, int send_block_number); |
AhmedPlaymaker | 10:751bd953fa27 | 43 | |
AhmedPlaymaker | 10:751bd953fa27 | 44 | /** Get Position |
AhmedPlaymaker | 10:751bd953fa27 | 45 | * |
AhmedPlaymaker | 10:751bd953fa27 | 46 | * This function obtains the coordinates of the top-left pixel in the Blocks sprites. |
AhmedPlaymaker | 10:751bd953fa27 | 47 | */ |
AhmedPlaymaker | 10:751bd953fa27 | 48 | Vector2D get_pos(); |
AhmedPlaymaker | 10:751bd953fa27 | 49 | |
AhmedPlaymaker | 12:1e601b176437 | 50 | /** Get Number |
AhmedPlaymaker | 12:1e601b176437 | 51 | * |
AhmedPlaymaker | 12:1e601b176437 | 52 | * This function obtains the number inside the Blocks sprite at a specefic location. |
AhmedPlaymaker | 12:1e601b176437 | 53 | */ |
AhmedPlaymaker | 12:1e601b176437 | 54 | int * get_number(); |
AhmedPlaymaker | 12:1e601b176437 | 55 | |
AhmedPlaymaker | 10:751bd953fa27 | 56 | /** Set Position |
AhmedPlaymaker | 10:751bd953fa27 | 57 | * |
AhmedPlaymaker | 10:751bd953fa27 | 58 | * This function is used to change the position of the sprite to specific coordinates when called. |
AhmedPlaymaker | 10:751bd953fa27 | 59 | */ |
AhmedPlaymaker | 10:751bd953fa27 | 60 | void set_pos(Vector2D p); |
AhmedPlaymaker | 10:751bd953fa27 | 61 | int state; |
AhmedPlaymaker | 47:b448ffd073e7 | 62 | double round; //used to save the rounded number to set the value inside the block. |
AhmedPlaymaker | 10:751bd953fa27 | 63 | int caseselect[5]; |
AhmedPlaymaker | 12:1e601b176437 | 64 | int send; |
AhmedPlaymaker | 37:ee47699915b8 | 65 | Vector2D velocity; |
AhmedPlaymaker | 10:751bd953fa27 | 66 | |
AhmedPlaymaker | 11:d6ceff1ff6d7 | 67 | |
AhmedPlaymaker | 10:751bd953fa27 | 68 | |
AhmedPlaymaker | 10:751bd953fa27 | 69 | private: |
AhmedPlaymaker | 41:4edac50f010d | 70 | int _length; |
AhmedPlaymaker | 10:751bd953fa27 | 71 | int k; |
AhmedPlaymaker | 10:751bd953fa27 | 72 | int _bx; //block x |
AhmedPlaymaker | 10:751bd953fa27 | 73 | int _by; //block y |
AhmedPlaymaker | 10:751bd953fa27 | 74 | |
AhmedPlaymaker | 10:751bd953fa27 | 75 | }; |
AhmedPlaymaker | 10:751bd953fa27 | 76 | #endif |