JianWei Lee
/
project_game
Meteor defense project
Spawn/Spawn.h@40:3a0c66a0e10e, 2017-04-29 (annotated)
- Committer:
- jasper0712
- Date:
- Sat Apr 29 19:27:20 2017 +0000
- Revision:
- 40:3a0c66a0e10e
- Parent:
- 34:6ac9541d4c31
- Child:
- 45:1a013017ae92
done commenting. MAYBE. implemented RETRY function in the game. need further testing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jasper0712 | 1:f5cda0674f24 | 1 | #ifndef SPAWN_H |
jasper0712 | 1:f5cda0674f24 | 2 | #define SPAWN_H |
jasper0712 | 1:f5cda0674f24 | 3 | |
jasper0712 | 1:f5cda0674f24 | 4 | #include "mbed.h" |
jasper0712 | 1:f5cda0674f24 | 5 | #include "N5110.h" |
jasper0712 | 1:f5cda0674f24 | 6 | #include "Gamepad.h" |
jasper0712 | 1:f5cda0674f24 | 7 | #include "Weapon.h" |
jasper0712 | 1:f5cda0674f24 | 8 | |
jasper0712 | 1:f5cda0674f24 | 9 | //Y rows and X columns |
jasper0712 | 1:f5cda0674f24 | 10 | #define Rows 48 |
jasper0712 | 1:f5cda0674f24 | 11 | #define Cols 84 |
jasper0712 | 1:f5cda0674f24 | 12 | |
jasper0712 | 40:3a0c66a0e10e | 13 | //store the stats of spawn A, B, C and D&E. |
jasper0712 | 34:6ac9541d4c31 | 14 | struct Stats { |
jasper0712 | 34:6ac9541d4c31 | 15 | int health; |
jasper0712 | 34:6ac9541d4c31 | 16 | int spawnRate; |
jasper0712 | 34:6ac9541d4c31 | 17 | }; |
jasper0712 | 34:6ac9541d4c31 | 18 | |
jasper0712 | 1:f5cda0674f24 | 19 | class Spawn |
jasper0712 | 1:f5cda0674f24 | 20 | { |
jasper0712 | 1:f5cda0674f24 | 21 | public: |
jasper0712 | 1:f5cda0674f24 | 22 | Spawn(); |
jasper0712 | 1:f5cda0674f24 | 23 | ~Spawn(); |
jasper0712 | 40:3a0c66a0e10e | 24 | |
jasper0712 | 40:3a0c66a0e10e | 25 | /**Initialise Spawn |
jasper0712 | 40:3a0c66a0e10e | 26 | * |
jasper0712 | 40:3a0c66a0e10e | 27 | *The health and spawn rate of the spawn depends on the number of level |
jasper0712 | 40:3a0c66a0e10e | 28 | *Randomise the seed to make the spawning pattern different for every level |
jasper0712 | 40:3a0c66a0e10e | 29 | *@param w - the number of level |
jasper0712 | 40:3a0c66a0e10e | 30 | */ |
jasper0712 | 32:580d74825810 | 31 | void init(int w); |
jasper0712 | 34:6ac9541d4c31 | 32 | |
jasper0712 | 40:3a0c66a0e10e | 33 | /**Summon Spawn |
jasper0712 | 40:3a0c66a0e10e | 34 | * |
jasper0712 | 40:3a0c66a0e10e | 35 | *Spawn A and C takes turn to be summoned to prevent collision (summon spawn A this row and spawn C the next row) |
jasper0712 | 40:3a0c66a0e10e | 36 | *Spawn B and DE will be summoned randomly depends solely on the spawn rate |
jasper0712 | 40:3a0c66a0e10e | 37 | *@param Arr[][Rows] - int Array to store spawn health |
jasper0712 | 40:3a0c66a0e10e | 38 | *@param cArr2[][Rows] - char Array to store the spawn character |
jasper0712 | 40:3a0c66a0e10e | 39 | */ |
jasper0712 | 40:3a0c66a0e10e | 40 | void summon_spawn(int Arr[][Rows], char cArr[][Rows]); |
jasper0712 | 40:3a0c66a0e10e | 41 | |
jasper0712 | 40:3a0c66a0e10e | 42 | /** Movement of Spawn A, B and C |
jasper0712 | 40:3a0c66a0e10e | 43 | * |
jasper0712 | 40:3a0c66a0e10e | 44 | *Moving behavior of spawn A, B and C is just moving down a row |
jasper0712 | 40:3a0c66a0e10e | 45 | *@param Arr[][Rows] - the int Array in sync with the char Array to be scanned |
jasper0712 | 40:3a0c66a0e10e | 46 | *@param Arr2[][Rows] - int Array to be updated |
jasper0712 | 40:3a0c66a0e10e | 47 | *@param cArr[][Rows] - char Array to be scanned |
jasper0712 | 40:3a0c66a0e10e | 48 | *@param cArr2[][Rows] - char Array to be updated |
jasper0712 | 40:3a0c66a0e10e | 49 | */ |
jasper0712 | 30:2e2d48cbfec3 | 50 | void moveSpawnABC(int Arr[][Rows], int Arr2[][Rows], char cArr[][Rows], char cArr2[][Rows]); |
jasper0712 | 40:3a0c66a0e10e | 51 | |
jasper0712 | 40:3a0c66a0e10e | 52 | /**Movement of Spawn B |
jasper0712 | 40:3a0c66a0e10e | 53 | * |
jasper0712 | 40:3a0c66a0e10e | 54 | *Move spawn B down a row |
jasper0712 | 40:3a0c66a0e10e | 55 | *@param Arr[][Rows] - the int Array in sync with the char Array to be scanned |
jasper0712 | 40:3a0c66a0e10e | 56 | *@param Arr2[][Rows] - int Array to be updated |
jasper0712 | 40:3a0c66a0e10e | 57 | *@param cArr[][Rows] - char Array to be scanned |
jasper0712 | 40:3a0c66a0e10e | 58 | *@param cArr2[][Rows] - char Array to be updated |
jasper0712 | 40:3a0c66a0e10e | 59 | */ |
jasper0712 | 30:2e2d48cbfec3 | 60 | void moveSpawnB(int Arr[][Rows], int Arr2[][Rows], char cArr[][Rows], char cArr2[][Rows]); |
jasper0712 | 40:3a0c66a0e10e | 61 | |
jasper0712 | 40:3a0c66a0e10e | 62 | /**Movement of Spawn D&E |
jasper0712 | 40:3a0c66a0e10e | 63 | * |
jasper0712 | 40:3a0c66a0e10e | 64 | *Spawn D & E moves diagonally |
jasper0712 | 40:3a0c66a0e10e | 65 | *Spawn D - move left & down |
jasper0712 | 40:3a0c66a0e10e | 66 | *Spawn E - move right & down |
jasper0712 | 40:3a0c66a0e10e | 67 | *It moves in the other direction when hit 'L' or 'R' of spawnC and walls. |
jasper0712 | 40:3a0c66a0e10e | 68 | *It jumps over Spawn A and Spawn B |
jasper0712 | 40:3a0c66a0e10e | 69 | *@param Arr[][Rows] - the int Array in sync with the char Array to be scanned |
jasper0712 | 40:3a0c66a0e10e | 70 | *@param Arr2[][Rows] - int Array to be updated |
jasper0712 | 40:3a0c66a0e10e | 71 | *@param cArr[][Rows] - char Array to be scanned |
jasper0712 | 40:3a0c66a0e10e | 72 | *@param cArr2[][Rows] - char Array to be updated |
jasper0712 | 40:3a0c66a0e10e | 73 | */ |
jasper0712 | 30:2e2d48cbfec3 | 74 | void moveSpawnDE(int Arr[][Rows], int Arr2[][Rows], char cArr[][Rows], char cArr2[][Rows]); |
jasper0712 | 40:3a0c66a0e10e | 75 | |
jasper0712 | 40:3a0c66a0e10e | 76 | /**Update spawn |
jasper0712 | 40:3a0c66a0e10e | 77 | * |
jasper0712 | 40:3a0c66a0e10e | 78 | *This function to update spawn from secondary array to main array after taking damage & after moving spawn |
jasper0712 | 40:3a0c66a0e10e | 79 | * |
jasper0712 | 40:3a0c66a0e10e | 80 | *It also displays the spawn on LCD |
jasper0712 | 40:3a0c66a0e10e | 81 | *@param Arr[][Rows] - int Array to be updated |
jasper0712 | 40:3a0c66a0e10e | 82 | *@param Arr2[][Rows] - the int Array in sync with the char Array to be scanned |
jasper0712 | 40:3a0c66a0e10e | 83 | *@param cArr[][Rows] - char Array to be updated |
jasper0712 | 40:3a0c66a0e10e | 84 | *@param cArr2[][Rows] - char Array to be scanned |
jasper0712 | 40:3a0c66a0e10e | 85 | */ |
jasper0712 | 31:1c0e47931e84 | 86 | void updateSpawn(int Arr[][Rows], int Arr2[][Rows], char cArr[][Rows], char cArr2[][Rows], N5110 &lcd); |
jasper0712 | 6:a554424e4517 | 87 | |
jasper0712 | 40:3a0c66a0e10e | 88 | /*Delete spawn |
jasper0712 | 40:3a0c66a0e10e | 89 | * |
jasper0712 | 40:3a0c66a0e10e | 90 | *Spawn that has 0 health will be deleted (cleaning tool) |
jasper0712 | 40:3a0c66a0e10e | 91 | *http://stackoverflow.com/questions/10289197/how-to-empty-a-2d-char-array-in-c |
jasper0712 | 40:3a0c66a0e10e | 92 | *@param x - the x co-ordinate of the spawn (0 to 83) |
jasper0712 | 40:3a0c66a0e10e | 93 | *@param y - the y co-ordinate of the spawn (0 to 47) |
jasper0712 | 40:3a0c66a0e10e | 94 | *@param Arr[][Rows] - the int array that will be scanned |
jasper0712 | 40:3a0c66a0e10e | 95 | *@param cArr[][Rows] - the char array that will be cleaned/deleted if Arr[x][y] == 0 |
jasper0712 | 40:3a0c66a0e10e | 96 | */ |
jasper0712 | 40:3a0c66a0e10e | 97 | void deleteChar(int x, int y, int Arr[][Rows], char cArr[][Rows]); |
jasper0712 | 40:3a0c66a0e10e | 98 | |
jasper0712 | 31:1c0e47931e84 | 99 | private: |
jasper0712 | 34:6ac9541d4c31 | 100 | |
jasper0712 | 31:1c0e47931e84 | 101 | int stopSpawnA; |
jasper0712 | 34:6ac9541d4c31 | 102 | |
jasper0712 | 40:3a0c66a0e10e | 103 | //create structs to store the stats of the spawns |
jasper0712 | 34:6ac9541d4c31 | 104 | Stats A; |
jasper0712 | 34:6ac9541d4c31 | 105 | Stats B; |
jasper0712 | 34:6ac9541d4c31 | 106 | Stats C; |
jasper0712 | 34:6ac9541d4c31 | 107 | Stats DE; |
jasper0712 | 40:3a0c66a0e10e | 108 | |
jasper0712 | 40:3a0c66a0e10e | 109 | //Summon spawns |
jasper0712 | 40:3a0c66a0e10e | 110 | void spawnA(int Arr[][Rows],char cArr[][Rows]); //normal spawn |
jasper0712 | 40:3a0c66a0e10e | 111 | void spawnB(int x, int Arr[][Rows],char cArr[][Rows]); //fast moving spawn |
jasper0712 | 40:3a0c66a0e10e | 112 | void spawnC(int Arr[][Rows],char cArr[][Rows]); //tanky spawn |
jasper0712 | 40:3a0c66a0e10e | 113 | void spawnDE(int x, int Arr[][Rows],char cArr[][Rows]); //zigg-zag spawn (even faster than spawn B) |
jasper0712 | 40:3a0c66a0e10e | 114 | |
jasper0712 | 40:3a0c66a0e10e | 115 | //Movement of spawn D&E. |
jasper0712 | 40:3a0c66a0e10e | 116 | void movementD(int x, int y, int Arr[][Rows], int Arr2[][Rows], char cArr[][Rows], char cArr2[][Rows]); |
jasper0712 | 40:3a0c66a0e10e | 117 | void movementE(int x, int y, int Arr[][Rows], int Arr2[][Rows], char cArr[][Rows], char cArr2[][Rows]); |
jasper0712 | 40:3a0c66a0e10e | 118 | |
jasper0712 | 1:f5cda0674f24 | 119 | }; |
jasper0712 | 1:f5cda0674f24 | 120 | |
jasper0712 | 3:6b50fe9d3848 | 121 | #endif |