Meteor defense project

Dependencies:   N5110 mbed

Committer:
jasper0712
Date:
Sat Apr 29 19:27:20 2017 +0000
Revision:
40:3a0c66a0e10e
Parent:
38:c66a69c1a6de
Child:
41:1b396334256b
done commenting. MAYBE. implemented RETRY function in the game. need further testing

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 37:45da88e36d1d 72 int doneUpgrade_flag;
jasper0712 40:3a0c66a0e10e 73 int retry_flag;
jasper0712 40:3a0c66a0e10e 74 int gameMenu_flag;
jasper0712 28:450ab72fabdc 75
jasper0712 40:3a0c66a0e10e 76 //Main and secondary array required to allow the spawn move and to take damage
jasper0712 40:3a0c66a0e10e 77 Array main;
jasper0712 40:3a0c66a0e10e 78 Array scnd;
jasper0712 40:3a0c66a0e10e 79 //Retry array - when player press retry this array will be used
jasper0712 40:3a0c66a0e10e 80 Array retry;
jasper0712 9:4c4d787c7a8b 81
jasper0712 25:edd6a95607b1 82
jasper0712 4:4145abd09075 83 private:
jasper0712 40:3a0c66a0e10e 84 //declare class with their name
jasper0712 5:c74bbdda06f4 85 Weapon weap;
jasper0712 17:53aedd20155a 86 Weapon _d1;
jasper0712 17:53aedd20155a 87 Weapon _d2;
jasper0712 4:4145abd09075 88 Spawn spa;
jasper0712 29:6632dd9c48d8 89 GUI _gui;
jasper0712 28:450ab72fabdc 90
jasper0712 4:4145abd09075 91 int drawit;
jasper0712 32:580d74825810 92 int ledNumber;
jasper0712 34:6ac9541d4c31 93 int NumberOfLife;
jasper0712 40:3a0c66a0e10e 94 int fireInTheHole_flag;
jasper0712 13:38cbce17d7d7 95
jasper0712 40:3a0c66a0e10e 96 //Turn on LEDs
jasper0712 40:3a0c66a0e10e 97 //Number of LEDs that light up will depends on number of lifes left
jasper0712 40:3a0c66a0e10e 98 void numberOfLife_leds(Gamepad &pad);
jasper0712 40:3a0c66a0e10e 99
jasper0712 40:3a0c66a0e10e 100 //Draw spawn
jasper0712 40:3a0c66a0e10e 101 //This is where summon spawn, moving spawn and update array happens.
jasper0712 40:3a0c66a0e10e 102 void drawSpawn(N5110 &lcd);
jasper0712 40:3a0c66a0e10e 103
jasper0712 40:3a0c66a0e10e 104 //Laser and cannon
jasper0712 40:3a0c66a0e10e 105 //This function puts laser and cannon together because cannon can only fire when laser is switched on
jasper0712 40:3a0c66a0e10e 106 void laser_and_cannon(Gamepad &pad, N5110 &lcd);
jasper0712 40:3a0c66a0e10e 107
jasper0712 40:3a0c66a0e10e 108 //Game Rule
jasper0712 40:3a0c66a0e10e 109 //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 110 void checkGameRule(Gamepad &pad, N5110 &lcd);
jasper0712 40:3a0c66a0e10e 111
jasper0712 40:3a0c66a0e10e 112 //Bomb and Shield
jasper0712 40:3a0c66a0e10e 113 //This function puts bomb and shield together to prevent double click
jasper0712 40:3a0c66a0e10e 114 void bomb_And_Shield(Gamepad &pad, N5110 &lcd);
jasper0712 40:3a0c66a0e10e 115
jasper0712 40:3a0c66a0e10e 116 //Update array
jasper0712 40:3a0c66a0e10e 117 //After a loop in the game, the main array will be updated using the secondary array
jasper0712 40:3a0c66a0e10e 118 void updateArray();
jasper0712 40:3a0c66a0e10e 119
jasper0712 40:3a0c66a0e10e 120
jasper0712 40:3a0c66a0e10e 121
jasper0712 40:3a0c66a0e10e 122 void gameOver(Gamepad &pad, N5110 &lcd);
jasper0712 40:3a0c66a0e10e 123
jasper0712 36:2608622e5018 124
jasper0712 4:4145abd09075 125 };
jasper0712 4:4145abd09075 126
jasper0712 4:4145abd09075 127 #endif