JianWei Lee
/
project_game
Meteor defense project
GameEngine/GameEngine.h@45:1a013017ae92, 2017-05-03 (annotated)
- Committer:
- jasper0712
- Date:
- Wed May 03 23:41:41 2017 +0000
- Revision:
- 45:1a013017ae92
- Parent:
- 44:aa086363d09f
- Child:
- 46:abb046536524
final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jasper0712 | 4:4145abd09075 | 1 | #ifndef GAMEENGINE_H |
jasper0712 | 4:4145abd09075 | 2 | #define GAMEENGINE_H |
jasper0712 | 4:4145abd09075 | 3 | |
jasper0712 | 4:4145abd09075 | 4 | #include "mbed.h" |
jasper0712 | 4:4145abd09075 | 5 | #include "N5110.h" |
jasper0712 | 4:4145abd09075 | 6 | #include "Gamepad.h" |
jasper0712 | 4:4145abd09075 | 7 | #include "Weapon.h" |
jasper0712 | 4:4145abd09075 | 8 | #include "Spawn.h" |
jasper0712 | 29:6632dd9c48d8 | 9 | #include "GUI.h" |
jasper0712 | 4:4145abd09075 | 10 | |
jasper0712 | 4:4145abd09075 | 11 | #define Rows 48 |
jasper0712 | 4:4145abd09075 | 12 | #define Cols 84 |
jasper0712 | 4:4145abd09075 | 13 | |
jasper0712 | 40:3a0c66a0e10e | 14 | struct Array { |
jasper0712 | 40:3a0c66a0e10e | 15 | //int array to store the spawn health |
jasper0712 | 40:3a0c66a0e10e | 16 | int Arr[Cols][Rows]; |
jasper0712 | 40:3a0c66a0e10e | 17 | //char array to differentiate the 4 different kind of spawn A, B, C and D&E. |
jasper0712 | 40:3a0c66a0e10e | 18 | char cArr[Cols][Rows]; |
jasper0712 | 40:3a0c66a0e10e | 19 | }; |
jasper0712 | 40:3a0c66a0e10e | 20 | |
jasper0712 | 45:1a013017ae92 | 21 | /** GameEngine Class |
jasper0712 | 45:1a013017ae92 | 22 | @brief Main library for the game |
jasper0712 | 45:1a013017ae92 | 23 | @author JianWei Lee |
jasper0712 | 45:1a013017ae92 | 24 | @date April 2017 |
jasper0712 | 45:1a013017ae92 | 25 | */ |
jasper0712 | 4:4145abd09075 | 26 | class GameEngine |
jasper0712 | 4:4145abd09075 | 27 | { |
jasper0712 | 4:4145abd09075 | 28 | |
jasper0712 | 4:4145abd09075 | 29 | public: |
jasper0712 | 4:4145abd09075 | 30 | GameEngine(); |
jasper0712 | 4:4145abd09075 | 31 | ~GameEngine(); |
jasper0712 | 40:3a0c66a0e10e | 32 | |
jasper0712 | 40:3a0c66a0e10e | 33 | /**Initialise GameEngine |
jasper0712 | 40:3a0c66a0e10e | 34 | * |
jasper0712 | 45:1a013017ae92 | 35 | *@brief Set the number of life at every level to 3 |
jasper0712 | 45:1a013017ae92 | 36 | *@brief To initialise all the variables of Weapons and Spawns |
jasper0712 | 40:3a0c66a0e10e | 37 | *@param w - the current number level |
jasper0712 | 40:3a0c66a0e10e | 38 | */ |
jasper0712 | 32:580d74825810 | 39 | void init(int w); |
jasper0712 | 40:3a0c66a0e10e | 40 | |
jasper0712 | 40:3a0c66a0e10e | 41 | /**Update game |
jasper0712 | 40:3a0c66a0e10e | 42 | * |
jasper0712 | 45:1a013017ae92 | 43 | *@brief This is where all the gameplay and drawing is gathered |
jasper0712 | 45:1a013017ae92 | 44 | *@brief The only way to lose this game is when the spawns reaches the player side (y = 46) for 3 times in a wave |
jasper0712 | 45:1a013017ae92 | 45 | *@brief Lights up LEDs according to number of lifes left |
jasper0712 | 40:3a0c66a0e10e | 46 | */ |
jasper0712 | 21:e5585569a938 | 47 | void update(Gamepad &pad, N5110 &lcd); |
jasper0712 | 40:3a0c66a0e10e | 48 | |
jasper0712 | 40:3a0c66a0e10e | 49 | /**Weapon Upgrades |
jasper0712 | 40:3a0c66a0e10e | 50 | * |
jasper0712 | 45:1a013017ae92 | 51 | *@brief Weapon upgrade will happen everytime after completing a game wave |
jasper0712 | 45:1a013017ae92 | 52 | *@brief This function connects class GUI and Weapons to display weapon levels and confirm upgrades |
jasper0712 | 40:3a0c66a0e10e | 53 | */ |
jasper0712 | 28:450ab72fabdc | 54 | void weapUpgrade(Gamepad &pad, N5110 &lcd); |
jasper0712 | 40:3a0c66a0e10e | 55 | |
jasper0712 | 40:3a0c66a0e10e | 56 | /**Starting Menu |
jasper0712 | 40:3a0c66a0e10e | 57 | * |
jasper0712 | 45:1a013017ae92 | 58 | *@brief Few strings to be printed on the lcd before starting the game |
jasper0712 | 45:1a013017ae92 | 59 | *@brief Light up LEDs in a knight rider pattern |
jasper0712 | 40:3a0c66a0e10e | 60 | */ |
jasper0712 | 32:580d74825810 | 61 | void startingMenu(Gamepad &pad, N5110 &lcd); |
jasper0712 | 40:3a0c66a0e10e | 62 | |
jasper0712 | 45:1a013017ae92 | 63 | /**Update Retry array using Main array |
jasper0712 | 40:3a0c66a0e10e | 64 | * |
jasper0712 | 45:1a013017ae92 | 65 | *@brief To make a copy of the Main array to Retry array |
jasper0712 | 40:3a0c66a0e10e | 66 | */ |
jasper0712 | 40:3a0c66a0e10e | 67 | void update_MainToRetry(); |
jasper0712 | 40:3a0c66a0e10e | 68 | |
jasper0712 | 45:1a013017ae92 | 69 | /**Update Main array using Retry array |
jasper0712 | 40:3a0c66a0e10e | 70 | * |
jasper0712 | 45:1a013017ae92 | 71 | *@brief To make a copy of the Retry array to Main array |
jasper0712 | 40:3a0c66a0e10e | 72 | */ |
jasper0712 | 40:3a0c66a0e10e | 73 | void update_RetryToMain(); |
jasper0712 | 26:140515d80457 | 74 | |
jasper0712 | 41:1b396334256b | 75 | /**Reset the game |
jasper0712 | 41:1b396334256b | 76 | * |
jasper0712 | 45:1a013017ae92 | 77 | *@brief Only thing that resets is the array and weapon's variables |
jasper0712 | 41:1b396334256b | 78 | */ |
jasper0712 | 41:1b396334256b | 79 | void reset_Game(); |
jasper0712 | 41:1b396334256b | 80 | |
jasper0712 | 37:45da88e36d1d | 81 | int doneUpgrade_flag; |
jasper0712 | 40:3a0c66a0e10e | 82 | int retry_flag; |
jasper0712 | 40:3a0c66a0e10e | 83 | int gameMenu_flag; |
jasper0712 | 28:450ab72fabdc | 84 | |
jasper0712 | 40:3a0c66a0e10e | 85 | //Main and secondary array required to allow the spawn move and to take damage |
jasper0712 | 40:3a0c66a0e10e | 86 | Array main; |
jasper0712 | 40:3a0c66a0e10e | 87 | Array scnd; |
jasper0712 | 44:aa086363d09f | 88 | //Retry array - when player press retry, this array will be used |
jasper0712 | 40:3a0c66a0e10e | 89 | Array retry; |
jasper0712 | 9:4c4d787c7a8b | 90 | |
jasper0712 | 25:edd6a95607b1 | 91 | |
jasper0712 | 4:4145abd09075 | 92 | private: |
jasper0712 | 40:3a0c66a0e10e | 93 | //declare class with their name |
jasper0712 | 5:c74bbdda06f4 | 94 | Weapon weap; |
jasper0712 | 17:53aedd20155a | 95 | Weapon _d1; |
jasper0712 | 17:53aedd20155a | 96 | Weapon _d2; |
jasper0712 | 4:4145abd09075 | 97 | Spawn spa; |
jasper0712 | 29:6632dd9c48d8 | 98 | GUI _gui; |
jasper0712 | 28:450ab72fabdc | 99 | |
jasper0712 | 4:4145abd09075 | 100 | int drawit; |
jasper0712 | 32:580d74825810 | 101 | int ledNumber; |
jasper0712 | 34:6ac9541d4c31 | 102 | int NumberOfLife; |
jasper0712 | 40:3a0c66a0e10e | 103 | int fireInTheHole_flag; |
jasper0712 | 13:38cbce17d7d7 | 104 | |
jasper0712 | 40:3a0c66a0e10e | 105 | //Turn on LEDs |
jasper0712 | 40:3a0c66a0e10e | 106 | //Number of LEDs that light up will depends on number of lifes left |
jasper0712 | 40:3a0c66a0e10e | 107 | void numberOfLife_leds(Gamepad &pad); |
jasper0712 | 40:3a0c66a0e10e | 108 | |
jasper0712 | 40:3a0c66a0e10e | 109 | //Draw spawn |
jasper0712 | 40:3a0c66a0e10e | 110 | //This is where summon spawn, moving spawn and update array happens. |
jasper0712 | 40:3a0c66a0e10e | 111 | void drawSpawn(N5110 &lcd); |
jasper0712 | 40:3a0c66a0e10e | 112 | |
jasper0712 | 40:3a0c66a0e10e | 113 | //Laser and cannon |
jasper0712 | 40:3a0c66a0e10e | 114 | //This function puts laser and cannon together because cannon can only fire when laser is switched on |
jasper0712 | 40:3a0c66a0e10e | 115 | void laser_and_cannon(Gamepad &pad, N5110 &lcd); |
jasper0712 | 40:3a0c66a0e10e | 116 | |
jasper0712 | 40:3a0c66a0e10e | 117 | //Game Rule |
jasper0712 | 40:3a0c66a0e10e | 118 | //The only way to lose this game is when the spawns reaches the player side (y = 46) for 3 times in a wave |
jasper0712 | 40:3a0c66a0e10e | 119 | void checkGameRule(Gamepad &pad, N5110 &lcd); |
jasper0712 | 40:3a0c66a0e10e | 120 | |
jasper0712 | 40:3a0c66a0e10e | 121 | //Bomb and Shield |
jasper0712 | 40:3a0c66a0e10e | 122 | //This function puts bomb and shield together to prevent double click |
jasper0712 | 40:3a0c66a0e10e | 123 | void bomb_And_Shield(Gamepad &pad, N5110 &lcd); |
jasper0712 | 40:3a0c66a0e10e | 124 | |
jasper0712 | 40:3a0c66a0e10e | 125 | //Update array |
jasper0712 | 40:3a0c66a0e10e | 126 | //After a loop in the game, the main array will be updated using the secondary array |
jasper0712 | 40:3a0c66a0e10e | 127 | void updateArray(); |
jasper0712 | 40:3a0c66a0e10e | 128 | |
jasper0712 | 44:aa086363d09f | 129 | /**Game over |
jasper0712 | 44:aa086363d09f | 130 | * |
jasper0712 | 44:aa086363d09f | 131 | *This function will be executed when player loses |
jasper0712 | 44:aa086363d09f | 132 | *Allows player to retry the wave or give up. |
jasper0712 | 44:aa086363d09f | 133 | */ |
jasper0712 | 40:3a0c66a0e10e | 134 | void gameOver(Gamepad &pad, N5110 &lcd); |
jasper0712 | 40:3a0c66a0e10e | 135 | |
jasper0712 | 36:2608622e5018 | 136 | |
jasper0712 | 4:4145abd09075 | 137 | }; |
jasper0712 | 4:4145abd09075 | 138 | |
jasper0712 | 4:4145abd09075 | 139 | #endif |