Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
SnakevsBlock/SnakevsBlock.h@41:4edac50f010d, 2019-04-23 (annotated)
- Committer:
- AhmedPlaymaker
- Date:
- Tue Apr 23 12:25:49 2019 +0000
- Revision:
- 41:4edac50f010d
- Parent:
- 39:210ac915e0a0
- Child:
- 42:973bb6036f81
This version has a separate class to interface with length, and also changed a lot of the code to interface with it.
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 | 38:30e4e6191762 | 6 | #include "FXOS8700CQ.h" |
AhmedPlaymaker | 7:48ba87cd79b5 | 7 | #include "Gamepad.h" |
AhmedPlaymaker | 7:48ba87cd79b5 | 8 | #include "Snake.h" |
AhmedPlaymaker | 41:4edac50f010d | 9 | #include "LengthCalc.h" |
AhmedPlaymaker | 9:d1d79d4ee673 | 10 | #include "SnakeFood.h" |
AhmedPlaymaker | 10:751bd953fa27 | 11 | #include "Blocks.h" |
AhmedPlaymaker | 33:249cf423fb18 | 12 | #include "StartScreen.h" |
AhmedPlaymaker | 33:249cf423fb18 | 13 | #include "Stats.h" |
AhmedPlaymaker | 33:249cf423fb18 | 14 | #include "SDFileSystem.h" |
AhmedPlaymaker | 7:48ba87cd79b5 | 15 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 16 | class SnakevsBlock |
AhmedPlaymaker | 7:48ba87cd79b5 | 17 | { |
AhmedPlaymaker | 7:48ba87cd79b5 | 18 | public: |
AhmedPlaymaker | 7:48ba87cd79b5 | 19 | SnakevsBlock(); |
AhmedPlaymaker | 7:48ba87cd79b5 | 20 | ~SnakevsBlock(); |
AhmedPlaymaker | 7:48ba87cd79b5 | 21 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 22 | /** Initialise Game Machine |
AhmedPlaymaker | 7:48ba87cd79b5 | 23 | * |
AhmedPlaymaker | 7:48ba87cd79b5 | 24 | * This function initialises the game machine. |
AhmedPlaymaker | 7:48ba87cd79b5 | 25 | */ |
AhmedPlaymaker | 7:48ba87cd79b5 | 26 | void init( ); |
AhmedPlaymaker | 7:48ba87cd79b5 | 27 | |
AhmedPlaymaker | 41:4edac50f010d | 28 | /** Reset Game Machine |
AhmedPlaymaker | 41:4edac50f010d | 29 | * |
AhmedPlaymaker | 41:4edac50f010d | 30 | * This function prepares the game machine for the next level. |
AhmedPlaymaker | 41:4edac50f010d | 31 | */ |
AhmedPlaymaker | 41:4edac50f010d | 32 | void reset( ); |
AhmedPlaymaker | 41:4edac50f010d | 33 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 34 | /** Read Input |
AhmedPlaymaker | 7:48ba87cd79b5 | 35 | * |
AhmedPlaymaker | 7:48ba87cd79b5 | 36 | * This function obtains numeric data from the gamepads joystick. |
AhmedPlaymaker | 7:48ba87cd79b5 | 37 | */ |
AhmedPlaymaker | 38:30e4e6191762 | 38 | void read_input(Gamepad &pad, FXOS8700CQ &device, int gm); |
AhmedPlaymaker | 7:48ba87cd79b5 | 39 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 40 | /** Update |
AhmedPlaymaker | 7:48ba87cd79b5 | 41 | * |
AhmedPlaymaker | 7:48ba87cd79b5 | 42 | * This function contains the update functions of the other libraries used in the game. |
AhmedPlaymaker | 7:48ba87cd79b5 | 43 | */ |
AhmedPlaymaker | 41:4edac50f010d | 44 | int update(Gamepad &pad); |
AhmedPlaymaker | 7:48ba87cd79b5 | 45 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 46 | /** Draw |
AhmedPlaymaker | 7:48ba87cd79b5 | 47 | * |
AhmedPlaymaker | 7:48ba87cd79b5 | 48 | * This function contains the draw functions of the other libraries used in the game. |
AhmedPlaymaker | 7:48ba87cd79b5 | 49 | */ |
AhmedPlaymaker | 41:4edac50f010d | 50 | void draw(N5110 &lcd, Gamepad &pad, SDFileSystem &sd); |
AhmedPlaymaker | 39:210ac915e0a0 | 51 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 52 | /** Get Position |
AhmedPlaymaker | 7:48ba87cd79b5 | 53 | * |
AhmedPlaymaker | 7:48ba87cd79b5 | 54 | * This function contains the Get Position functions of the otehr libraries used in the game. |
AhmedPlaymaker | 7:48ba87cd79b5 | 55 | */ |
AhmedPlaymaker | 7:48ba87cd79b5 | 56 | void get_pos(); |
AhmedPlaymaker | 7:48ba87cd79b5 | 57 | |
AhmedPlaymaker | 29:c6358c39a70e | 58 | /** Check Block |
AhmedPlaymaker | 29:c6358c39a70e | 59 | * |
AhmedPlaymaker | 29:c6358c39a70e | 60 | * This function returns the srn of the block we are colliding with; |
AhmedPlaymaker | 29:c6358c39a70e | 61 | */ |
AhmedPlaymaker | 29:c6358c39a70e | 62 | int CheckBlock(int Block); |
AhmedPlaymaker | 29:c6358c39a70e | 63 | |
AhmedPlaymaker | 27:3b4775a0d0bb | 64 | /** Implement Collision |
AhmedPlaymaker | 27:3b4775a0d0bb | 65 | * |
AhmedPlaymaker | 27:3b4775a0d0bb | 66 | * This function allows the appropriate maths to take place after every collision. |
AhmedPlaymaker | 27:3b4775a0d0bb | 67 | */ |
AhmedPlaymaker | 27:3b4775a0d0bb | 68 | void ImplementCollision(Gamepad &pad); |
AhmedPlaymaker | 27:3b4775a0d0bb | 69 | |
AhmedPlaymaker | 41:4edac50f010d | 70 | int snakex; //x position of top beed |
AhmedPlaymaker | 41:4edac50f010d | 71 | int snakey; //y position of top beed |
AhmedPlaymaker | 7:48ba87cd79b5 | 72 | int length; |
AhmedPlaymaker | 39:210ac915e0a0 | 73 | int velocity; //this is to stop/move the background (food and blocks), when collision occurs at a length greater than 10. |
AhmedPlaymaker | 19:05cc9f801468 | 74 | int level; |
AhmedPlaymaker | 41:4edac50f010d | 75 | char bufferlevel[14]; //this helps me print the level on screen. |
AhmedPlaymaker | 38:30e4e6191762 | 76 | int garbage; //to save the angle at the point button A is pressed. |
AhmedPlaymaker | 38:30e4e6191762 | 77 | float angle; //saves the angle of tilt. |
AhmedPlaymaker | 9:d1d79d4ee673 | 78 | int foodbuff; //this makes food 1,2,and 3 come at seperate times |
AhmedPlaymaker | 12:1e601b176437 | 79 | int blocknum; |
AhmedPlaymaker | 19:05cc9f801468 | 80 | int blockgap; //to change frequency of fall |
AhmedPlaymaker | 19:05cc9f801468 | 81 | int blockbuff; // to manage the fall of food relative to the blocks |
AhmedPlaymaker | 12:1e601b176437 | 82 | int srn; |
AhmedPlaymaker | 12:1e601b176437 | 83 | int send; //makes sure that the block number is only updated when send is activated. |
AhmedPlaymaker | 25:e827f1a8fadc | 84 | int back; //enables the player to go back on main menu if back is pressed. |
AhmedPlaymaker | 22:ee698f66146f | 85 | int b[15]; |
AhmedPlaymaker | 18:b391caa5754c | 86 | int b0_to_b14[15]; |
AhmedPlaymaker | 41:4edac50f010d | 87 | int *b_number; //pointer to save the numbers inside the block. |
AhmedPlaymaker | 24:1c118b071430 | 88 | Vector2D snake_pos[15]; |
AhmedPlaymaker | 41:4edac50f010d | 89 | Vector2D food_pos[3]; |
AhmedPlaymaker | 41:4edac50f010d | 90 | Vector2D b_pos; |
AhmedPlaymaker | 7:48ba87cd79b5 | 91 | |
AhmedPlaymaker | 7:48ba87cd79b5 | 92 | private: |
AhmedPlaymaker | 7:48ba87cd79b5 | 93 | Snake _s; |
AhmedPlaymaker | 41:4edac50f010d | 94 | LengthCalc _l; |
AhmedPlaymaker | 9:d1d79d4ee673 | 95 | SnakeFood _f; |
AhmedPlaymaker | 9:d1d79d4ee673 | 96 | SnakeFood _ff; |
AhmedPlaymaker | 9:d1d79d4ee673 | 97 | SnakeFood _fff; |
AhmedPlaymaker | 10:751bd953fa27 | 98 | Blocks _b; |
AhmedPlaymaker | 33:249cf423fb18 | 99 | Stats _statset; |
AhmedPlaymaker | 7:48ba87cd79b5 | 100 | int _speed; |
AhmedPlaymaker | 41:4edac50f010d | 101 | int _length; |
AhmedPlaymaker | 7:48ba87cd79b5 | 102 | Direction _d; |
AhmedPlaymaker | 7:48ba87cd79b5 | 103 | float _mag; |
AhmedPlaymaker | 37:ee47699915b8 | 104 | 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 | 105 | int n; |
AhmedPlaymaker | 7:48ba87cd79b5 | 106 | |
AhmedPlaymaker | 9:d1d79d4ee673 | 107 | /** Check for Snake and Food collision |
AhmedPlaymaker | 9:d1d79d4ee673 | 108 | * |
AhmedPlaymaker | 9:d1d79d4ee673 | 109 | * This function checks if the Snake has come into contact with it's food. |
AhmedPlaymaker | 9:d1d79d4ee673 | 110 | */ |
AhmedPlaymaker | 9:d1d79d4ee673 | 111 | void CheckSnakeFoodCollision(Gamepad &pad); |
AhmedPlaymaker | 9:d1d79d4ee673 | 112 | |
AhmedPlaymaker | 12:1e601b176437 | 113 | /** Check for Snake and Block collision |
AhmedPlaymaker | 12:1e601b176437 | 114 | * |
AhmedPlaymaker | 12:1e601b176437 | 115 | * This function checks if the Snake has come into contact with any Block. |
AhmedPlaymaker | 12:1e601b176437 | 116 | */ |
AhmedPlaymaker | 12:1e601b176437 | 117 | void CheckSnakeBlockCollision(Gamepad &pad); |
AhmedPlaymaker | 13:9785f2404045 | 118 | |
AhmedPlaymaker | 39:210ac915e0a0 | 119 | /** Implement velocity alteration. |
AhmedPlaymaker | 39:210ac915e0a0 | 120 | * |
AhmedPlaymaker | 39:210ac915e0a0 | 121 | * this is to stop/move the background (food and blocks), when collision occurs at a length greater than 10.lock. |
AhmedPlaymaker | 39:210ac915e0a0 | 122 | */ |
AhmedPlaymaker | 39:210ac915e0a0 | 123 | void _set_velocity(); |
AhmedPlaymaker | 39:210ac915e0a0 | 124 | |
AhmedPlaymaker | 13:9785f2404045 | 125 | /** Check for Snake and Block Sides collision |
AhmedPlaymaker | 13:9785f2404045 | 126 | * |
AhmedPlaymaker | 13:9785f2404045 | 127 | * This function checks if the Snake has come into contact with any the sides of the block and stops it moving. |
AhmedPlaymaker | 13:9785f2404045 | 128 | */ |
AhmedPlaymaker | 38:30e4e6191762 | 129 | void CheckSnakeBlockSidesCollision(Gamepad &pad); |
AhmedPlaymaker | 7:48ba87cd79b5 | 130 | }; |
AhmedPlaymaker | 7:48ba87cd79b5 | 131 | #endif |