Ikenna Adrian Ozoemena 201157039
Dependencies: mbed
Enemy/Enemy.h@53:3fdc4486f672, 2019-05-09 (annotated)
- Committer:
- ikenna1
- Date:
- Thu May 09 14:52:52 2019 +0000
- Revision:
- 53:3fdc4486f672
- Parent:
- 52:29772e31a620
Final Submission
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ikenna1 | 15:009ccc07bb57 | 1 | #ifndef ENEMY_H |
ikenna1 | 15:009ccc07bb57 | 2 | #define ENEMY_H |
ikenna1 | 15:009ccc07bb57 | 3 | |
ikenna1 | 15:009ccc07bb57 | 4 | #include "mbed.h" |
ikenna1 | 15:009ccc07bb57 | 5 | #include "N5110.h" |
ikenna1 | 15:009ccc07bb57 | 6 | #include "Gamepad.h" |
ikenna1 | 37:8d8c8cce0bc7 | 7 | #include <ctime> |
ikenna1 | 40:90c7a893d513 | 8 | #include <cmath> |
ikenna1 | 15:009ccc07bb57 | 9 | |
ikenna1 | 45:fe5fc85a5c73 | 10 | /** Enemy Class |
ikenna1 | 45:fe5fc85a5c73 | 11 | @brief Library that updates the position of all enemies and enemy weapons for rosen game |
ikenna1 | 45:fe5fc85a5c73 | 12 | @author Ozoemena Adrian Ikrnna |
ikenna1 | 45:fe5fc85a5c73 | 13 | @date 8th May 2019 |
ikenna1 | 45:fe5fc85a5c73 | 14 | */ |
ikenna1 | 15:009ccc07bb57 | 15 | class Enemy |
ikenna1 | 15:009ccc07bb57 | 16 | { |
ikenna1 | 15:009ccc07bb57 | 17 | public: |
ikenna1 | 45:fe5fc85a5c73 | 18 | /** constructor */ |
ikenna1 | 15:009ccc07bb57 | 19 | Enemy(); |
ikenna1 | 45:fe5fc85a5c73 | 20 | /** destructor */ |
ikenna1 | 15:009ccc07bb57 | 21 | ~Enemy(); |
ikenna1 | 15:009ccc07bb57 | 22 | |
ikenna1 | 45:fe5fc85a5c73 | 23 | /** A mutator method that initializes the number of enemies |
ikenna1 | 47:5ae8668af63f | 24 | *@param noShooters the number of enemy shooters on screen |
ikenna1 | 47:5ae8668af63f | 25 | *@param noSeekers the number of enemy seekers on screen |
ikenna1 | 48:dd529a86b5bc | 26 | *@<c>{note that these should not be confused with seno and shno which are used to |
ikenna1 | 48:dd529a86b5bc | 27 | *reference particular enemies i.e shooter1 and shooter2}</c> |
ikenna1 | 45:fe5fc85a5c73 | 28 | */ |
ikenna1 | 45:fe5fc85a5c73 | 29 | void init(int noShooters, int noSeekers); |
ikenna1 | 45:fe5fc85a5c73 | 30 | /** A mutator method that sets the number of shooters, used for increasing game difficulty |
ikenna1 | 47:5ae8668af63f | 31 | *@param noShooters the number of enemy shooters on screen |
ikenna1 | 45:fe5fc85a5c73 | 32 | */ |
ikenna1 | 45:fe5fc85a5c73 | 33 | void set_noshooters(int noShooters); |
ikenna1 | 45:fe5fc85a5c73 | 34 | /** A mutator method that sets the number of seekers, used for increasing game difficulty |
ikenna1 | 47:5ae8668af63f | 35 | *@param noSeekers the number of enemy seekers on screen |
ikenna1 | 45:fe5fc85a5c73 | 36 | */ |
ikenna1 | 45:fe5fc85a5c73 | 37 | void set_noseekers(int noSeekers); |
ikenna1 | 45:fe5fc85a5c73 | 38 | /** Draws the shooter on screen |
ikenna1 | 51:2231e2e141b9 | 39 | *@param &lcd address of the N5110 library used for the lcd display |
ikenna1 | 45:fe5fc85a5c73 | 40 | */ |
ikenna1 | 45:fe5fc85a5c73 | 41 | void draw_shooter(N5110 &lcd); |
ikenna1 | 45:fe5fc85a5c73 | 42 | /** Draws the seeker on screen |
ikenna1 | 51:2231e2e141b9 | 43 | *@param &lcd address of the N5110 library used for the lcd display |
ikenna1 | 45:fe5fc85a5c73 | 44 | */ |
ikenna1 | 15:009ccc07bb57 | 45 | void draw_seeker(N5110 &lcd); |
ikenna1 | 45:fe5fc85a5c73 | 46 | /** A mutator method that updates the shooter position according to the player ships position |
ikenna1 | 47:5ae8668af63f | 47 | *@param ship_xpos the ships x co-ordinate |
ikenna1 | 47:5ae8668af63f | 48 | *@param ship_ypos the ships y co-ordinate |
ikenna1 | 45:fe5fc85a5c73 | 49 | */ |
ikenna1 | 45:fe5fc85a5c73 | 50 | void update_shooter(int ship_xpos, int ship_ypos); |
ikenna1 | 45:fe5fc85a5c73 | 51 | /** A mutator method that updates the seekers position according to the player ships position |
ikenna1 | 47:5ae8668af63f | 52 | *@param ship_xpos the ships x co-ordinate |
ikenna1 | 47:5ae8668af63f | 53 | *@param ship_ypos the ships y co-ordinate |
ikenna1 | 45:fe5fc85a5c73 | 54 | */ |
ikenna1 | 15:009ccc07bb57 | 55 | void update_seeker(int ship_xpos, int ship_ypos); |
ikenna1 | 45:fe5fc85a5c73 | 56 | /** resets the shooter to the top of screen |
ikenna1 | 47:5ae8668af63f | 57 | *@param shno the shooter number used to reference the shooter of interest |
ikenna1 | 45:fe5fc85a5c73 | 58 | *Ranges from 0-3 as there can be a maximum of three shooters |
ikenna1 | 45:fe5fc85a5c73 | 59 | */ |
ikenna1 | 41:e1fa36c0492e | 60 | void reset_shooter(int shno); |
ikenna1 | 45:fe5fc85a5c73 | 61 | /** resets the seeker to the top of screen |
ikenna1 | 47:5ae8668af63f | 62 | *@param seno the seeker number used to reference the seekerr of interest |
ikenna1 | 45:fe5fc85a5c73 | 63 | *Ranges from 0-3 as there can be a maximum of three seekers |
ikenna1 | 45:fe5fc85a5c73 | 64 | */ |
ikenna1 | 45:fe5fc85a5c73 | 65 | void reset_seeker(int seno); |
ikenna1 | 45:fe5fc85a5c73 | 66 | /** draws the projectile fired from the shooter |
ikenna1 | 51:2231e2e141b9 | 67 | *@param &lcd address of the N5110 library used for the lcd display |
ikenna1 | 51:2231e2e141b9 | 68 | *@param &pad address of the gamepad library used to read inputs and send outputs to the gamepad |
ikenna1 | 45:fe5fc85a5c73 | 69 | */ |
ikenna1 | 34:6d0786582d81 | 70 | void draw_shw(N5110 &lcd,Gamepad &pad); |
ikenna1 | 45:fe5fc85a5c73 | 71 | /** A mutator method that updates the position of the projectile fired from the shooter |
ikenna1 | 45:fe5fc85a5c73 | 72 | */ |
ikenna1 | 32:098fbc1222cd | 73 | void update_shw(); |
ikenna1 | 45:fe5fc85a5c73 | 74 | /** An accessor method that gets the position of the projectile fired by the shooter |
ikenna1 | 47:5ae8668af63f | 75 | *@param shno the shooter number used to reference the shooter of interest |
ikenna1 | 45:fe5fc85a5c73 | 76 | *Ranges from 0-3 as there can be a maximum of three shooters |
ikenna1 | 45:fe5fc85a5c73 | 77 | */ |
ikenna1 | 37:8d8c8cce0bc7 | 78 | Vector2D get_shwpos(int shno); |
ikenna1 | 45:fe5fc85a5c73 | 79 | /** An accessor method that gets the position of any shooter on screen |
ikenna1 | 47:5ae8668af63f | 80 | *@param shno the shooter number used to reference the shooter of interest |
ikenna1 | 45:fe5fc85a5c73 | 81 | *Ranges from 0-3 as there can be a maximum of three shooters |
ikenna1 | 45:fe5fc85a5c73 | 82 | */ |
ikenna1 | 37:8d8c8cce0bc7 | 83 | Vector2D get_shooterpos(int shno); |
ikenna1 | 45:fe5fc85a5c73 | 84 | /** An accessor method that gets the position of any seeker on screen |
ikenna1 | 47:5ae8668af63f | 85 | *@param seno the seeker number used to reference the seekerr of interest |
ikenna1 | 45:fe5fc85a5c73 | 86 | *Ranges from 0-3 as there can be a maximum of three seekers |
ikenna1 | 45:fe5fc85a5c73 | 87 | */ |
ikenna1 | 45:fe5fc85a5c73 | 88 | Vector2D get_seekerpos(int seno); |
ikenna1 | 45:fe5fc85a5c73 | 89 | /** A random number generator that creates a random number that can be scaled |
ikenna1 | 45:fe5fc85a5c73 | 90 | *appropriately using the <ctime> library |
ikenna1 | 47:5ae8668af63f | 91 | *@param scale this will determine the maximum output of the function |
ikenna1 | 45:fe5fc85a5c73 | 92 | *@returns a random number between 0 and scale |
ikenna1 | 45:fe5fc85a5c73 | 93 | */ |
ikenna1 | 37:8d8c8cce0bc7 | 94 | int rand_no(int scale); |
ikenna1 | 45:fe5fc85a5c73 | 95 | /** A mutator function which changes enemy speed and number as time goes on |
ikenna1 | 47:5ae8668af63f | 96 | *@param time_elapsed the amount of time that has passed since a player pressed play in seconds |
ikenna1 | 45:fe5fc85a5c73 | 97 | */ |
ikenna1 | 39:7824f9080f59 | 98 | void sh_scaling(float time_elapsed); |
ikenna1 | 52:29772e31a620 | 99 | |
ikenna1 | 52:29772e31a620 | 100 | private: |
ikenna1 | 52:29772e31a620 | 101 | //_______________Private-Methods__________________________________________ |
ikenna1 | 45:fe5fc85a5c73 | 102 | /** Finds the average distance between two points on the 2D screen |
ikenna1 | 47:5ae8668af63f | 103 | *@param x1 the x co-ordinate of the first point |
ikenna1 | 47:5ae8668af63f | 104 | *@param y1 the y co-ordinate of the first point |
ikenna1 | 47:5ae8668af63f | 105 | *@param x2 the x co-ordinate of the second point |
ikenna1 | 47:5ae8668af63f | 106 | *@param y2 the y co-ordinate of the second point |
ikenna1 | 45:fe5fc85a5c73 | 107 | *@returns the distance between the two points |
ikenna1 | 52:29772e31a620 | 108 | */ |
ikenna1 | 45:fe5fc85a5c73 | 109 | int distance(int x1, int y1, int x2, int y2); |
ikenna1 | 45:fe5fc85a5c73 | 110 | /** Finds the closest enemy ship on screen |
ikenna1 | 49:aa204bf7ee2e | 111 | *used for the orions weapon tracking |
ikenna1 | 47:5ae8668af63f | 112 | *@param ship_xpos the ships x co-ordinate |
ikenna1 | 47:5ae8668af63f | 113 | *@param ship_ypos the ships y co-ordinate |
ikenna1 | 47:5ae8668af63f | 114 | *@param noShooters the number of enemy shooters on screen |
ikenna1 | 47:5ae8668af63f | 115 | *@param noSeekers the number of enemy seekers on screen |
ikenna1 | 45:fe5fc85a5c73 | 116 | */ |
ikenna1 | 45:fe5fc85a5c73 | 117 | Vector2D find_closest(int ship_xpos,int ship_ypos,int noSeekers, int noShooters); |
ikenna1 | 51:2231e2e141b9 | 118 | /** A mutator method that sets the position of the projectile fired from the first shooter and draws it on screen |
ikenna1 | 51:2231e2e141b9 | 119 | *@param &lcd address of the N5110 library used for the lcd display |
ikenna1 | 51:2231e2e141b9 | 120 | *@param &pad address of the gamepad library used to read inputs and send outputs to the gamepad |
ikenna1 | 51:2231e2e141b9 | 121 | */ |
ikenna1 | 32:098fbc1222cd | 122 | void draw_shw1(N5110 &lcd,Gamepad &pad); |
ikenna1 | 51:2231e2e141b9 | 123 | /** A mutator method that sets the position of the projectile fired from the second shooter and draws it on screen |
ikenna1 | 51:2231e2e141b9 | 124 | *@param &lcd address of the N5110 library used for the lcd display |
ikenna1 | 51:2231e2e141b9 | 125 | *@param &pad address of the gamepad library used to read inputs and send outputs to the gamepad |
ikenna1 | 51:2231e2e141b9 | 126 | */ |
ikenna1 | 32:098fbc1222cd | 127 | void draw_shw2(N5110 &lcd,Gamepad &pad); |
ikenna1 | 51:2231e2e141b9 | 128 | /** A mutator method that sets the position of the projectile fired from the third shooter and draws it on screen |
ikenna1 | 51:2231e2e141b9 | 129 | *@param &lcd address of the N5110 library used for the lcd display |
ikenna1 | 51:2231e2e141b9 | 130 | *@param &pad address of the gamepad library used to read inputs and send outputs to the gamepad |
ikenna1 | 51:2231e2e141b9 | 131 | */ |
ikenna1 | 32:098fbc1222cd | 132 | void draw_shw3(N5110 &lcd,Gamepad &pad); |
ikenna1 | 51:2231e2e141b9 | 133 | /** A mutator method determines how the shooters move in the game |
ikenna1 | 51:2231e2e141b9 | 134 | *@param shooter_xpos the x co-ordinate of the shooter |
ikenna1 | 51:2231e2e141b9 | 135 | *@param shooter_ypos the y co-ordinate of the shooter |
ikenna1 | 51:2231e2e141b9 | 136 | *@param ship_xpos the ships x co-ordinate |
ikenna1 | 51:2231e2e141b9 | 137 | *@param ship_ypos the ships y co-ordinate |
ikenna1 | 51:2231e2e141b9 | 138 | *@param projx the x co-ordinate of the projectile fired from the shooter |
ikenna1 | 51:2231e2e141b9 | 139 | *@param projy the y co-ordinate of the projectile fired from the shooter |
ikenna1 | 51:2231e2e141b9 | 140 | *@param vx the shooters x velocity |
ikenna1 | 51:2231e2e141b9 | 141 | *@param vy the shooters y velocity |
ikenna1 | 51:2231e2e141b9 | 142 | */ |
ikenna1 | 39:7824f9080f59 | 143 | Vector2D shooter_motion(int shooter_xpos,int shooter_ypos,int ship_xpos, int ship_ypos, int projx, int projy,int vx, int vy); |
ikenna1 | 51:2231e2e141b9 | 144 | /** A mutator method determines how the seekers move in the game |
ikenna1 | 51:2231e2e141b9 | 145 | *@param seeker_xpos the x co-ordinate of the seeker |
ikenna1 | 51:2231e2e141b9 | 146 | *@param seeker_ypos the y co-ordinate of the seeker |
ikenna1 | 51:2231e2e141b9 | 147 | *@param ship_xpos the ships x co-ordinate |
ikenna1 | 51:2231e2e141b9 | 148 | *@param ship_ypos the ships y co-ordinate |
ikenna1 | 51:2231e2e141b9 | 149 | *@param vx the seekers x velocity |
ikenna1 | 51:2231e2e141b9 | 150 | *@param vy the seekers y velocity |
ikenna1 | 51:2231e2e141b9 | 151 | */ |
ikenna1 | 52:29772e31a620 | 152 | Vector2D seeker_motion(int seeker_xpos,int seeker_ypos,int ship_xpos,int ship_ypos,int vx,int vy); |
ikenna1 | 45:fe5fc85a5c73 | 153 | //_______________Private-Variables__________________________________________ |
ikenna1 | 45:fe5fc85a5c73 | 154 | Vector2D _seekerPos[3]; //a 2D array of all the seekers position values |
ikenna1 | 45:fe5fc85a5c73 | 155 | Vector2D _shooterPos[3]; //a 2D array of all the shooters position values |
ikenna1 | 45:fe5fc85a5c73 | 156 | Vector2D _shooterSpeed[3]; //a 2D array of all the shooters speed values |
ikenna1 | 45:fe5fc85a5c73 | 157 | Vector2D _shooterWPos[3]; //a 2D array of all the shooters-projectile position position values |
ikenna1 | 45:fe5fc85a5c73 | 158 | Vector2D _shooterWSpeed[3]; //a 2D array of all the shooters-projectile speed position values |
ikenna1 | 45:fe5fc85a5c73 | 159 | int _reset[3]; //an array or reset values used to reset projectiles from the shooter weapon |
ikenna1 | 45:fe5fc85a5c73 | 160 | int _noShooters; //the number of shooters on the screen |
ikenna1 | 45:fe5fc85a5c73 | 161 | int _noSeekers; //the number of seekers on the screen |
ikenna1 | 15:009ccc07bb57 | 162 | |
ikenna1 | 15:009ccc07bb57 | 163 | }; |
ikenna1 | 15:009ccc07bb57 | 164 | #endif |