JianWei Lee
/
project_game
Meteor defense project
Spawn/Spawn.h@50:082feedcdd22, 2017-05-04 (annotated)
- Committer:
- jasper0712
- Date:
- Thu May 04 16:55:26 2017 +0000
- Revision:
- 50:082feedcdd22
- Parent:
- 46:abb046536524
converted library to folder
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 | 45:1a013017ae92 | 19 | /** Spawn Class |
jasper0712 | 45:1a013017ae92 | 20 | @brief Library that contain all the enemy in the game |
jasper0712 | 45:1a013017ae92 | 21 | @author JianWei Lee |
jasper0712 | 45:1a013017ae92 | 22 | @date April 2017 |
jasper0712 | 45:1a013017ae92 | 23 | */ |
jasper0712 | 1:f5cda0674f24 | 24 | class Spawn |
jasper0712 | 1:f5cda0674f24 | 25 | { |
jasper0712 | 1:f5cda0674f24 | 26 | public: |
jasper0712 | 1:f5cda0674f24 | 27 | Spawn(); |
jasper0712 | 1:f5cda0674f24 | 28 | ~Spawn(); |
jasper0712 | 40:3a0c66a0e10e | 29 | |
jasper0712 | 40:3a0c66a0e10e | 30 | /**Initialise Spawn |
jasper0712 | 40:3a0c66a0e10e | 31 | * |
jasper0712 | 46:abb046536524 | 32 | *@brief The health and spawn rate of the spawn depends on the number of level \n |
jasper0712 | 45:1a013017ae92 | 33 | *@brief Randomise the seed to make the spawning pattern different for every level |
jasper0712 | 40:3a0c66a0e10e | 34 | *@param w - the number of level |
jasper0712 | 40:3a0c66a0e10e | 35 | */ |
jasper0712 | 32:580d74825810 | 36 | void init(int w); |
jasper0712 | 34:6ac9541d4c31 | 37 | |
jasper0712 | 40:3a0c66a0e10e | 38 | /**Summon Spawn |
jasper0712 | 40:3a0c66a0e10e | 39 | * |
jasper0712 | 46:abb046536524 | 40 | *@brief Spawn A and C takes turn to be summoned to prevent collision (summon spawn A this row and spawn C the next row) \n |
jasper0712 | 45:1a013017ae92 | 41 | *@brief Spawn B and DE will be summoned randomly depends solely on the spawn rate |
jasper0712 | 40:3a0c66a0e10e | 42 | *@param Arr[][Rows] - int Array to store spawn health |
jasper0712 | 40:3a0c66a0e10e | 43 | *@param cArr2[][Rows] - char Array to store the spawn character |
jasper0712 | 40:3a0c66a0e10e | 44 | */ |
jasper0712 | 40:3a0c66a0e10e | 45 | void summon_spawn(int Arr[][Rows], char cArr[][Rows]); |
jasper0712 | 40:3a0c66a0e10e | 46 | |
jasper0712 | 40:3a0c66a0e10e | 47 | /** Movement of Spawn A, B and C |
jasper0712 | 40:3a0c66a0e10e | 48 | * |
jasper0712 | 45:1a013017ae92 | 49 | *@brief Moving behavior of spawn A, B and C is just moving down a row |
jasper0712 | 40:3a0c66a0e10e | 50 | *@param Arr[][Rows] - the int Array in sync with the char Array to be scanned |
jasper0712 | 40:3a0c66a0e10e | 51 | *@param Arr2[][Rows] - int Array to be updated |
jasper0712 | 40:3a0c66a0e10e | 52 | *@param cArr[][Rows] - char Array to be scanned |
jasper0712 | 40:3a0c66a0e10e | 53 | *@param cArr2[][Rows] - char Array to be updated |
jasper0712 | 40:3a0c66a0e10e | 54 | */ |
jasper0712 | 30:2e2d48cbfec3 | 55 | void moveSpawnABC(int Arr[][Rows], int Arr2[][Rows], char cArr[][Rows], char cArr2[][Rows]); |
jasper0712 | 40:3a0c66a0e10e | 56 | |
jasper0712 | 40:3a0c66a0e10e | 57 | /**Movement of Spawn B |
jasper0712 | 40:3a0c66a0e10e | 58 | * |
jasper0712 | 45:1a013017ae92 | 59 | *@brief Move spawn B down a row |
jasper0712 | 40:3a0c66a0e10e | 60 | *@param Arr[][Rows] - the int Array in sync with the char Array to be scanned |
jasper0712 | 40:3a0c66a0e10e | 61 | *@param Arr2[][Rows] - int Array to be updated |
jasper0712 | 40:3a0c66a0e10e | 62 | *@param cArr[][Rows] - char Array to be scanned |
jasper0712 | 40:3a0c66a0e10e | 63 | *@param cArr2[][Rows] - char Array to be updated |
jasper0712 | 40:3a0c66a0e10e | 64 | */ |
jasper0712 | 30:2e2d48cbfec3 | 65 | void moveSpawnB(int Arr[][Rows], int Arr2[][Rows], char cArr[][Rows], char cArr2[][Rows]); |
jasper0712 | 40:3a0c66a0e10e | 66 | |
jasper0712 | 40:3a0c66a0e10e | 67 | /**Movement of Spawn D&E |
jasper0712 | 40:3a0c66a0e10e | 68 | * |
jasper0712 | 46:abb046536524 | 69 | *@brief Spawn D & E moves diagonally \n |
jasper0712 | 46:abb046536524 | 70 | *@brief Spawn D - move left & down \n |
jasper0712 | 46:abb046536524 | 71 | *@brief Spawn E - move right & down \n |
jasper0712 | 46:abb046536524 | 72 | *@brief It moves in the other direction when hit 'L' or 'R' of spawnC and walls. \n |
jasper0712 | 45:1a013017ae92 | 73 | *@brief It jumps over Spawn A and Spawn B |
jasper0712 | 40:3a0c66a0e10e | 74 | *@param Arr[][Rows] - the int Array in sync with the char Array to be scanned |
jasper0712 | 40:3a0c66a0e10e | 75 | *@param Arr2[][Rows] - int Array to be updated |
jasper0712 | 40:3a0c66a0e10e | 76 | *@param cArr[][Rows] - char Array to be scanned |
jasper0712 | 40:3a0c66a0e10e | 77 | *@param cArr2[][Rows] - char Array to be updated |
jasper0712 | 40:3a0c66a0e10e | 78 | */ |
jasper0712 | 30:2e2d48cbfec3 | 79 | void moveSpawnDE(int Arr[][Rows], int Arr2[][Rows], char cArr[][Rows], char cArr2[][Rows]); |
jasper0712 | 40:3a0c66a0e10e | 80 | |
jasper0712 | 40:3a0c66a0e10e | 81 | /**Update spawn |
jasper0712 | 40:3a0c66a0e10e | 82 | * |
jasper0712 | 46:abb046536524 | 83 | *@brief This function to update spawn from secondary array to main array after taking damage & after moving spawn \n |
jasper0712 | 45:1a013017ae92 | 84 | *@brief It also prints the spawn on LCD |
jasper0712 | 40:3a0c66a0e10e | 85 | *@param Arr[][Rows] - int Array to be updated |
jasper0712 | 40:3a0c66a0e10e | 86 | *@param Arr2[][Rows] - the int Array in sync with the char Array to be scanned |
jasper0712 | 40:3a0c66a0e10e | 87 | *@param cArr[][Rows] - char Array to be updated |
jasper0712 | 40:3a0c66a0e10e | 88 | *@param cArr2[][Rows] - char Array to be scanned |
jasper0712 | 40:3a0c66a0e10e | 89 | */ |
jasper0712 | 31:1c0e47931e84 | 90 | void updateSpawn(int Arr[][Rows], int Arr2[][Rows], char cArr[][Rows], char cArr2[][Rows], N5110 &lcd); |
jasper0712 | 6:a554424e4517 | 91 | |
jasper0712 | 40:3a0c66a0e10e | 92 | /*Delete spawn |
jasper0712 | 40:3a0c66a0e10e | 93 | * |
jasper0712 | 46:abb046536524 | 94 | *@brief Spawn that has 0 health will be deleted (cleaning tool) \n |
jasper0712 | 40:3a0c66a0e10e | 95 | *http://stackoverflow.com/questions/10289197/how-to-empty-a-2d-char-array-in-c |
jasper0712 | 40:3a0c66a0e10e | 96 | *@param x - the x co-ordinate of the spawn (0 to 83) |
jasper0712 | 40:3a0c66a0e10e | 97 | *@param y - the y co-ordinate of the spawn (0 to 47) |
jasper0712 | 40:3a0c66a0e10e | 98 | *@param Arr[][Rows] - the int array that will be scanned |
jasper0712 | 40:3a0c66a0e10e | 99 | *@param cArr[][Rows] - the char array that will be cleaned/deleted if Arr[x][y] == 0 |
jasper0712 | 40:3a0c66a0e10e | 100 | */ |
jasper0712 | 40:3a0c66a0e10e | 101 | void deleteChar(int x, int y, int Arr[][Rows], char cArr[][Rows]); |
jasper0712 | 40:3a0c66a0e10e | 102 | |
jasper0712 | 31:1c0e47931e84 | 103 | private: |
jasper0712 | 34:6ac9541d4c31 | 104 | |
jasper0712 | 31:1c0e47931e84 | 105 | int stopSpawnA; |
jasper0712 | 34:6ac9541d4c31 | 106 | |
jasper0712 | 40:3a0c66a0e10e | 107 | //create structs to store the stats of the spawns |
jasper0712 | 34:6ac9541d4c31 | 108 | Stats A; |
jasper0712 | 34:6ac9541d4c31 | 109 | Stats B; |
jasper0712 | 34:6ac9541d4c31 | 110 | Stats C; |
jasper0712 | 34:6ac9541d4c31 | 111 | Stats DE; |
jasper0712 | 40:3a0c66a0e10e | 112 | |
jasper0712 | 40:3a0c66a0e10e | 113 | //Summon spawns |
jasper0712 | 40:3a0c66a0e10e | 114 | void spawnA(int Arr[][Rows],char cArr[][Rows]); //normal spawn |
jasper0712 | 40:3a0c66a0e10e | 115 | void spawnB(int x, int Arr[][Rows],char cArr[][Rows]); //fast moving spawn |
jasper0712 | 40:3a0c66a0e10e | 116 | void spawnC(int Arr[][Rows],char cArr[][Rows]); //tanky spawn |
jasper0712 | 40:3a0c66a0e10e | 117 | void spawnDE(int x, int Arr[][Rows],char cArr[][Rows]); //zigg-zag spawn (even faster than spawn B) |
jasper0712 | 40:3a0c66a0e10e | 118 | |
jasper0712 | 40:3a0c66a0e10e | 119 | //Movement of spawn D&E. |
jasper0712 | 40:3a0c66a0e10e | 120 | void movementD(int x, int y, int Arr[][Rows], int Arr2[][Rows], char cArr[][Rows], char cArr2[][Rows]); |
jasper0712 | 40:3a0c66a0e10e | 121 | void movementE(int x, int y, int Arr[][Rows], int Arr2[][Rows], char cArr[][Rows], char cArr2[][Rows]); |
jasper0712 | 40:3a0c66a0e10e | 122 | |
jasper0712 | 1:f5cda0674f24 | 123 | }; |
jasper0712 | 1:f5cda0674f24 | 124 | |
jasper0712 | 3:6b50fe9d3848 | 125 | #endif |