![](/media/cache/profiles/LinkedIn_0NghoZJ.jpeg.50x50_q85.jpg)
Snake vs Block Game to be run upon K64F.
SnakevsBlock/SnakevsBlock.h@37:ee47699915b8, 2019-04-18 (annotated)
- Committer:
- AhmedPlaymaker
- Date:
- Thu Apr 18 14:03:43 2019 +0000
- Revision:
- 37:ee47699915b8
- Parent:
- 33:249cf423fb18
- Child:
- 38:30e4e6191762
Added feature that sets the real length to max 10, the virtual length increases upto anything i want, currently 20, I may have second thoughts on this, so may revert commit.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AhmedPlaymaker | 7:48ba87cd79b5 | 1 | #ifndef SNAKEVSBLOCK_H |
AhmedPlaymaker | 7:48ba87cd79b5 | 2 | #define SNAKEVSBLOCK_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 | #include "Snake.h" |
AhmedPlaymaker | 9:d1d79d4ee673 | 8 | #include "SnakeFood.h" |
AhmedPlaymaker | 10:751bd953fa27 | 9 | #include "Blocks.h" |
AhmedPlaymaker | 33:249cf423fb18 | 10 | #include "StartScreen.h" |
AhmedPlaymaker | 33:249cf423fb18 | 11 | #include "Stats.h" |
AhmedPlaymaker | 33:249cf423fb18 | 12 | #include "SDFileSystem.h" |
AhmedPlaymaker | 7:48ba87cd79b5 | 13 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 14 | class SnakevsBlock |
AhmedPlaymaker | 7:48ba87cd79b5 | 15 | { |
AhmedPlaymaker | 7:48ba87cd79b5 | 16 | public: |
AhmedPlaymaker | 7:48ba87cd79b5 | 17 | SnakevsBlock(); |
AhmedPlaymaker | 7:48ba87cd79b5 | 18 | ~SnakevsBlock(); |
AhmedPlaymaker | 7:48ba87cd79b5 | 19 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 20 | /** Initialise Game Machine |
AhmedPlaymaker | 7:48ba87cd79b5 | 21 | * |
AhmedPlaymaker | 7:48ba87cd79b5 | 22 | * This function initialises the game machine. |
AhmedPlaymaker | 7:48ba87cd79b5 | 23 | */ |
AhmedPlaymaker | 7:48ba87cd79b5 | 24 | void init( ); |
AhmedPlaymaker | 7:48ba87cd79b5 | 25 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 26 | /** Read Input |
AhmedPlaymaker | 7:48ba87cd79b5 | 27 | * |
AhmedPlaymaker | 7:48ba87cd79b5 | 28 | * This function obtains numeric data from the gamepads joystick. |
AhmedPlaymaker | 7:48ba87cd79b5 | 29 | */ |
AhmedPlaymaker | 7:48ba87cd79b5 | 30 | void read_input(Gamepad &pad); |
AhmedPlaymaker | 7:48ba87cd79b5 | 31 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 32 | /** Update |
AhmedPlaymaker | 7:48ba87cd79b5 | 33 | * |
AhmedPlaymaker | 7:48ba87cd79b5 | 34 | * This function contains the update functions of the other libraries used in the game. |
AhmedPlaymaker | 7:48ba87cd79b5 | 35 | */ |
AhmedPlaymaker | 33:249cf423fb18 | 36 | int update(Gamepad &pad, SDFileSystem &sd); |
AhmedPlaymaker | 7:48ba87cd79b5 | 37 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 38 | /** Draw |
AhmedPlaymaker | 7:48ba87cd79b5 | 39 | * |
AhmedPlaymaker | 7:48ba87cd79b5 | 40 | * This function contains the draw functions of the other libraries used in the game. |
AhmedPlaymaker | 7:48ba87cd79b5 | 41 | */ |
AhmedPlaymaker | 7:48ba87cd79b5 | 42 | void draw(N5110 &lcd, Gamepad &pad); |
AhmedPlaymaker | 7:48ba87cd79b5 | 43 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 44 | /** Get Position |
AhmedPlaymaker | 7:48ba87cd79b5 | 45 | * |
AhmedPlaymaker | 7:48ba87cd79b5 | 46 | * This function contains the Get Position functions of the otehr libraries used in the game. |
AhmedPlaymaker | 7:48ba87cd79b5 | 47 | */ |
AhmedPlaymaker | 7:48ba87cd79b5 | 48 | void get_pos(); |
AhmedPlaymaker | 7:48ba87cd79b5 | 49 | |
AhmedPlaymaker | 29:c6358c39a70e | 50 | /** Check Block |
AhmedPlaymaker | 29:c6358c39a70e | 51 | * |
AhmedPlaymaker | 29:c6358c39a70e | 52 | * This function returns the srn of the block we are colliding with; |
AhmedPlaymaker | 29:c6358c39a70e | 53 | */ |
AhmedPlaymaker | 29:c6358c39a70e | 54 | int CheckBlock(int Block); |
AhmedPlaymaker | 29:c6358c39a70e | 55 | |
AhmedPlaymaker | 27:3b4775a0d0bb | 56 | /** Implement Collision |
AhmedPlaymaker | 27:3b4775a0d0bb | 57 | * |
AhmedPlaymaker | 27:3b4775a0d0bb | 58 | * This function allows the appropriate maths to take place after every collision. |
AhmedPlaymaker | 27:3b4775a0d0bb | 59 | */ |
AhmedPlaymaker | 27:3b4775a0d0bb | 60 | void ImplementCollision(Gamepad &pad); |
AhmedPlaymaker | 27:3b4775a0d0bb | 61 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 62 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 63 | int snakex; |
AhmedPlaymaker | 7:48ba87cd79b5 | 64 | int snakey; |
AhmedPlaymaker | 7:48ba87cd79b5 | 65 | int length; |
AhmedPlaymaker | 19:05cc9f801468 | 66 | int level; |
AhmedPlaymaker | 9:d1d79d4ee673 | 67 | int foodbuff; //this makes food 1,2,and 3 come at seperate times |
AhmedPlaymaker | 12:1e601b176437 | 68 | int blocknum; |
AhmedPlaymaker | 19:05cc9f801468 | 69 | int blockgap; //to change frequency of fall |
AhmedPlaymaker | 19:05cc9f801468 | 70 | int blockbuff; // to manage the fall of food relative to the blocks |
AhmedPlaymaker | 12:1e601b176437 | 71 | int srn; |
AhmedPlaymaker | 12:1e601b176437 | 72 | int send; //makes sure that the block number is only updated when send is activated. |
AhmedPlaymaker | 13:9785f2404045 | 73 | int speed; //makes sure that snake only moves if not colliding to block walls |
AhmedPlaymaker | 25:e827f1a8fadc | 74 | int back; //enables the player to go back on main menu if back is pressed. |
AhmedPlaymaker | 22:ee698f66146f | 75 | int b[15]; |
AhmedPlaymaker | 18:b391caa5754c | 76 | int b0_to_b14[15]; |
AhmedPlaymaker | 24:1c118b071430 | 77 | Vector2D snake_pos[15]; |
AhmedPlaymaker | 7:48ba87cd79b5 | 78 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 79 | private: |
AhmedPlaymaker | 7:48ba87cd79b5 | 80 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 81 | Snake _s; |
AhmedPlaymaker | 9:d1d79d4ee673 | 82 | SnakeFood _f; |
AhmedPlaymaker | 9:d1d79d4ee673 | 83 | SnakeFood _ff; |
AhmedPlaymaker | 9:d1d79d4ee673 | 84 | SnakeFood _fff; |
AhmedPlaymaker | 10:751bd953fa27 | 85 | Blocks _b; |
AhmedPlaymaker | 33:249cf423fb18 | 86 | Stats _statset; |
AhmedPlaymaker | 7:48ba87cd79b5 | 87 | int _speed; |
AhmedPlaymaker | 7:48ba87cd79b5 | 88 | Direction _d; |
AhmedPlaymaker | 7:48ba87cd79b5 | 89 | float _mag; |
AhmedPlaymaker | 37:ee47699915b8 | 90 | int _detect_slowly; //this makes sure that when the length is more than 10, the colliding block doesnt decrease the all the length in a single itteration. |
AhmedPlaymaker | 7:48ba87cd79b5 | 91 | int n; |
AhmedPlaymaker | 7:48ba87cd79b5 | 92 | |
AhmedPlaymaker | 9:d1d79d4ee673 | 93 | /** Check for Snake and Food collision |
AhmedPlaymaker | 9:d1d79d4ee673 | 94 | * |
AhmedPlaymaker | 9:d1d79d4ee673 | 95 | * This function checks if the Snake has come into contact with it's food. |
AhmedPlaymaker | 9:d1d79d4ee673 | 96 | */ |
AhmedPlaymaker | 9:d1d79d4ee673 | 97 | void CheckSnakeFoodCollision(Gamepad &pad); |
AhmedPlaymaker | 9:d1d79d4ee673 | 98 | |
AhmedPlaymaker | 12:1e601b176437 | 99 | /** Check for Snake and Block collision |
AhmedPlaymaker | 12:1e601b176437 | 100 | * |
AhmedPlaymaker | 12:1e601b176437 | 101 | * This function checks if the Snake has come into contact with any Block. |
AhmedPlaymaker | 12:1e601b176437 | 102 | */ |
AhmedPlaymaker | 12:1e601b176437 | 103 | void CheckSnakeBlockCollision(Gamepad &pad); |
AhmedPlaymaker | 13:9785f2404045 | 104 | |
AhmedPlaymaker | 13:9785f2404045 | 105 | /** Check for Snake and Block Sides collision |
AhmedPlaymaker | 13:9785f2404045 | 106 | * |
AhmedPlaymaker | 13:9785f2404045 | 107 | * This function checks if the Snake has come into contact with any the sides of the block and stops it moving. |
AhmedPlaymaker | 13:9785f2404045 | 108 | */ |
AhmedPlaymaker | 13:9785f2404045 | 109 | void CheckSnakeBlockSidesCollision(Gamepad &pad, Direction d); |
AhmedPlaymaker | 7:48ba87cd79b5 | 110 | }; |
AhmedPlaymaker | 7:48ba87cd79b5 | 111 | #endif |