Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
GameObjects/Barriers/Barriers.h@83:329da564799a, 2019-05-06 (annotated)
- Committer:
- AhmedPlaymaker
- Date:
- Mon May 06 14:28:35 2019 +0000
- Revision:
- 83:329da564799a
- Parent:
- 81:4c1641e10dcd
- Child:
- 94:4e603bd6c381
Now, I have put gamepad and lcd objects from the main() in a pointer, so that i can declare them in init() in every class i use them in and use them as global objects for each class, without having to send their addresses to all of the functions.
Who changed what in which revision?
User | Revision | Line number | New 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 | 81:4c1641e10dcd | 8 | |
AhmedPlaymaker | 81:4c1641e10dcd | 9 | class Barriers |
AhmedPlaymaker | 81:4c1641e10dcd | 10 | { |
AhmedPlaymaker | 81:4c1641e10dcd | 11 | public: |
AhmedPlaymaker | 81:4c1641e10dcd | 12 | Barriers(); |
AhmedPlaymaker | 81:4c1641e10dcd | 13 | ~Barriers(); |
AhmedPlaymaker | 81:4c1641e10dcd | 14 | /** Initialise Barriers |
AhmedPlaymaker | 81:4c1641e10dcd | 15 | * |
AhmedPlaymaker | 81:4c1641e10dcd | 16 | * This function initialises the Barriers library. |
AhmedPlaymaker | 81:4c1641e10dcd | 17 | */ |
AhmedPlaymaker | 83:329da564799a | 18 | void init(N5110 *lcd); |
AhmedPlaymaker | 81:4c1641e10dcd | 19 | |
AhmedPlaymaker | 81:4c1641e10dcd | 20 | /** Draw |
AhmedPlaymaker | 81:4c1641e10dcd | 21 | * |
AhmedPlaymaker | 81:4c1641e10dcd | 22 | * This function draws the Barriers onto the screen. |
AhmedPlaymaker | 81:4c1641e10dcd | 23 | */ |
AhmedPlaymaker | 83:329da564799a | 24 | void draw(int b_y); |
AhmedPlaymaker | 81:4c1641e10dcd | 25 | |
AhmedPlaymaker | 81:4c1641e10dcd | 26 | /** Update |
AhmedPlaymaker | 81:4c1641e10dcd | 27 | * |
AhmedPlaymaker | 81:4c1641e10dcd | 28 | * This function updates the position of the Barriers as they move down the screen. |
AhmedPlaymaker | 81:4c1641e10dcd | 29 | */ |
AhmedPlaymaker | 81:4c1641e10dcd | 30 | void update(int blockgap); |
AhmedPlaymaker | 81:4c1641e10dcd | 31 | |
AhmedPlaymaker | 81:4c1641e10dcd | 32 | /** Get Position |
AhmedPlaymaker | 81:4c1641e10dcd | 33 | * |
AhmedPlaymaker | 81:4c1641e10dcd | 34 | * This function obtains the coordinates of the top-left pixel in the Barriers sprites. |
AhmedPlaymaker | 81:4c1641e10dcd | 35 | */ |
AhmedPlaymaker | 81:4c1641e10dcd | 36 | Vector2D get_pos(); |
AhmedPlaymaker | 81:4c1641e10dcd | 37 | |
AhmedPlaymaker | 81:4c1641e10dcd | 38 | /** Set Position |
AhmedPlaymaker | 81:4c1641e10dcd | 39 | * |
AhmedPlaymaker | 81:4c1641e10dcd | 40 | * This function is used to change the position of the barrier to specific coordinates when called. |
AhmedPlaymaker | 81:4c1641e10dcd | 41 | */ |
AhmedPlaymaker | 81:4c1641e10dcd | 42 | void set_pos(Vector2D p); |
AhmedPlaymaker | 81:4c1641e10dcd | 43 | |
AhmedPlaymaker | 81:4c1641e10dcd | 44 | |
AhmedPlaymaker | 81:4c1641e10dcd | 45 | Vector2D velocity; |
AhmedPlaymaker | 81:4c1641e10dcd | 46 | |
AhmedPlaymaker | 81:4c1641e10dcd | 47 | private: |
AhmedPlaymaker | 81:4c1641e10dcd | 48 | int reset; |
AhmedPlaymaker | 81:4c1641e10dcd | 49 | int _barx; //barrier x |
AhmedPlaymaker | 81:4c1641e10dcd | 50 | int _bary; //barrier y |
AhmedPlaymaker | 81:4c1641e10dcd | 51 | int _barriergap; |
AhmedPlaymaker | 81:4c1641e10dcd | 52 | int _blockgap; |
AhmedPlaymaker | 83:329da564799a | 53 | |
AhmedPlaymaker | 83:329da564799a | 54 | //Pointer to the game pad object pad. |
AhmedPlaymaker | 83:329da564799a | 55 | Gamepad *_pad; |
AhmedPlaymaker | 83:329da564799a | 56 | //Pointer to the N5110 object lcd. |
AhmedPlaymaker | 83:329da564799a | 57 | N5110 *_lcd; |
AhmedPlaymaker | 81:4c1641e10dcd | 58 | |
AhmedPlaymaker | 81:4c1641e10dcd | 59 | }; |
AhmedPlaymaker | 81:4c1641e10dcd | 60 | #endif |