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