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