Meteor defense project

Dependencies:   N5110 mbed

Committer:
jasper0712
Date:
Sun Apr 30 21:53:28 2017 +0000
Revision:
41:1b396334256b
Parent:
40:3a0c66a0e10e
Child:
43:acbed608a8df
discovered few bug on retry and fixed it

Who changed what in which revision?

UserRevisionLine numberNew 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 4:4145abd09075 21
jasper0712 4:4145abd09075 22 class GameEngine
jasper0712 4:4145abd09075 23 {
jasper0712 4:4145abd09075 24
jasper0712 4:4145abd09075 25 public:
jasper0712 4:4145abd09075 26 GameEngine();
jasper0712 4:4145abd09075 27 ~GameEngine();
jasper0712 40:3a0c66a0e10e 28
jasper0712 40:3a0c66a0e10e 29 /**Initialise GameEngine
jasper0712 40:3a0c66a0e10e 30 *
jasper0712 40:3a0c66a0e10e 31 *Set the number of life at every level to 3
jasper0712 40:3a0c66a0e10e 32 *To initialise all the variables of Weapons and Spawns
jasper0712 40:3a0c66a0e10e 33 *@param w - the current number level
jasper0712 40:3a0c66a0e10e 34 */
jasper0712 32:580d74825810 35 void init(int w);
jasper0712 40:3a0c66a0e10e 36
jasper0712 40:3a0c66a0e10e 37 /**Update game
jasper0712 40:3a0c66a0e10e 38 *
jasper0712 40:3a0c66a0e10e 39 *This is where all the gameplay is gathered
jasper0712 40:3a0c66a0e10e 40 *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 41 *Lights up LEDs according to number of lifes left
jasper0712 40:3a0c66a0e10e 42 */
jasper0712 21:e5585569a938 43 void update(Gamepad &pad, N5110 &lcd);
jasper0712 40:3a0c66a0e10e 44
jasper0712 40:3a0c66a0e10e 45 /**Weapon Upgrades
jasper0712 40:3a0c66a0e10e 46 *
jasper0712 40:3a0c66a0e10e 47 *Weapon upgrade will happen everytime after completing a game wave
jasper0712 40:3a0c66a0e10e 48 *This function connects class GUI and Weapons to display weapon levels and confirm upgrades
jasper0712 40:3a0c66a0e10e 49 */
jasper0712 28:450ab72fabdc 50 void weapUpgrade(Gamepad &pad, N5110 &lcd);
jasper0712 40:3a0c66a0e10e 51
jasper0712 40:3a0c66a0e10e 52 /**Starting Menu
jasper0712 40:3a0c66a0e10e 53 *
jasper0712 40:3a0c66a0e10e 54 *Few strings to be printed on the lcd before starting the game
jasper0712 40:3a0c66a0e10e 55 *Light up LEDs in a knight rider pattern
jasper0712 40:3a0c66a0e10e 56 */
jasper0712 32:580d74825810 57 void startingMenu(Gamepad &pad, N5110 &lcd);
jasper0712 40:3a0c66a0e10e 58
jasper0712 40:3a0c66a0e10e 59 /**Update retry.Arr & retry.cArr
jasper0712 40:3a0c66a0e10e 60 *
jasper0712 40:3a0c66a0e10e 61 *retry.Arr and retry.cArr is always updated at the start of a wave.
jasper0712 40:3a0c66a0e10e 62 *To make a copy of the main array
jasper0712 40:3a0c66a0e10e 63 */
jasper0712 40:3a0c66a0e10e 64 void update_MainToRetry();
jasper0712 40:3a0c66a0e10e 65
jasper0712 40:3a0c66a0e10e 66 /**Update main array using retry array
jasper0712 40:3a0c66a0e10e 67 *
jasper0712 40:3a0c66a0e10e 68 *this function will be used when player decided to retry the game
jasper0712 40:3a0c66a0e10e 69 */
jasper0712 40:3a0c66a0e10e 70 void update_RetryToMain();
jasper0712 26:140515d80457 71
jasper0712 41:1b396334256b 72 /**Reset the game
jasper0712 41:1b396334256b 73 *
jasper0712 41:1b396334256b 74 *Only thing requires reset is the array and weapon's variables
jasper0712 41:1b396334256b 75 */
jasper0712 41:1b396334256b 76 void reset_Game();
jasper0712 41:1b396334256b 77
jasper0712 37:45da88e36d1d 78 int doneUpgrade_flag;
jasper0712 40:3a0c66a0e10e 79 int retry_flag;
jasper0712 40:3a0c66a0e10e 80 int gameMenu_flag;
jasper0712 28:450ab72fabdc 81
jasper0712 40:3a0c66a0e10e 82 //Main and secondary array required to allow the spawn move and to take damage
jasper0712 40:3a0c66a0e10e 83 Array main;
jasper0712 40:3a0c66a0e10e 84 Array scnd;
jasper0712 40:3a0c66a0e10e 85 //Retry array - when player press retry this array will be used
jasper0712 40:3a0c66a0e10e 86 Array retry;
jasper0712 9:4c4d787c7a8b 87
jasper0712 25:edd6a95607b1 88
jasper0712 4:4145abd09075 89 private:
jasper0712 40:3a0c66a0e10e 90 //declare class with their name
jasper0712 5:c74bbdda06f4 91 Weapon weap;
jasper0712 17:53aedd20155a 92 Weapon _d1;
jasper0712 17:53aedd20155a 93 Weapon _d2;
jasper0712 4:4145abd09075 94 Spawn spa;
jasper0712 29:6632dd9c48d8 95 GUI _gui;
jasper0712 28:450ab72fabdc 96
jasper0712 4:4145abd09075 97 int drawit;
jasper0712 32:580d74825810 98 int ledNumber;
jasper0712 34:6ac9541d4c31 99 int NumberOfLife;
jasper0712 40:3a0c66a0e10e 100 int fireInTheHole_flag;
jasper0712 13:38cbce17d7d7 101
jasper0712 40:3a0c66a0e10e 102 //Turn on LEDs
jasper0712 40:3a0c66a0e10e 103 //Number of LEDs that light up will depends on number of lifes left
jasper0712 40:3a0c66a0e10e 104 void numberOfLife_leds(Gamepad &pad);
jasper0712 40:3a0c66a0e10e 105
jasper0712 40:3a0c66a0e10e 106 //Draw spawn
jasper0712 40:3a0c66a0e10e 107 //This is where summon spawn, moving spawn and update array happens.
jasper0712 40:3a0c66a0e10e 108 void drawSpawn(N5110 &lcd);
jasper0712 40:3a0c66a0e10e 109
jasper0712 40:3a0c66a0e10e 110 //Laser and cannon
jasper0712 40:3a0c66a0e10e 111 //This function puts laser and cannon together because cannon can only fire when laser is switched on
jasper0712 40:3a0c66a0e10e 112 void laser_and_cannon(Gamepad &pad, N5110 &lcd);
jasper0712 40:3a0c66a0e10e 113
jasper0712 40:3a0c66a0e10e 114 //Game Rule
jasper0712 40:3a0c66a0e10e 115 //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 116 void checkGameRule(Gamepad &pad, N5110 &lcd);
jasper0712 40:3a0c66a0e10e 117
jasper0712 40:3a0c66a0e10e 118 //Bomb and Shield
jasper0712 40:3a0c66a0e10e 119 //This function puts bomb and shield together to prevent double click
jasper0712 40:3a0c66a0e10e 120 void bomb_And_Shield(Gamepad &pad, N5110 &lcd);
jasper0712 40:3a0c66a0e10e 121
jasper0712 40:3a0c66a0e10e 122 //Update array
jasper0712 40:3a0c66a0e10e 123 //After a loop in the game, the main array will be updated using the secondary array
jasper0712 40:3a0c66a0e10e 124 void updateArray();
jasper0712 40:3a0c66a0e10e 125
jasper0712 40:3a0c66a0e10e 126
jasper0712 40:3a0c66a0e10e 127
jasper0712 40:3a0c66a0e10e 128 void gameOver(Gamepad &pad, N5110 &lcd);
jasper0712 40:3a0c66a0e10e 129
jasper0712 36:2608622e5018 130
jasper0712 4:4145abd09075 131 };
jasper0712 4:4145abd09075 132
jasper0712 4:4145abd09075 133 #endif