Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: Enemy/Enemy.h
- Revision:
- 5:8bd09c675f28
- Parent:
- 3:97cd7b3d89d0
- Child:
- 6:f06ce4cf068a
--- a/Enemy/Enemy.h Sun May 05 20:46:26 2019 +0000
+++ b/Enemy/Enemy.h Wed May 08 19:41:10 2019 +0000
@@ -11,44 +11,118 @@
@author Adam Jones, University of Leeds
@brief Controls the Enemy Sprites in the Wall Defence game
@date April 2017
+@brief Revision 1.0
+
+@code
+#include "Enemy.h"
+#include "N5110.h"
+
+
+int main()
+{
+ //initialise
+ float timeToAttack = 0.0; //time at which the enemy will begin to move forwards
+ float speed = 0.5; //speed in pixels per frame at which enemy will move forwards
+ Enemy _enemy;
+ _enemy.init(timeToAttack, speed);
+
+ //set action
+ Action myAc = moving; //Action enumerator
+ _enemy.set_current_action(myAc); //set enemies current action
+
+ //draw enemy
+ N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
+ lcd.init();
+ _enemy.draw(lcd); //draw enemy sprite to display
+
+
+
+
+}
+
+@endcode
+
+
*/
-
-enum Action { waiting, moving, attacking, dying };
+//action enumerator keeps track of enemies current state
+//and allows for quick routing to correct process via switch state
+enum Action {
+ waiting, //enemy not yet attacking (off screen)
+ moving, //enemy moving towards players wall
+ attacking, //enemy damaging players wall
+ dying //enemy has been killed by player
+};
class Enemy
{
-
-
-
-
public:
Enemy();
~Enemy();
-
- Action enemAction;
+ /**
+ * @brief Initialises an enemy with a time to attack and a set speed
+ * @param timeToAttack @details The time into the new level that the enemy will start moving forwards
+ * @param speed @details The speed of the enemy in pixels per frame
+ */
void init(float timeToAttack, float speed);
+ /**
+ * @brief Draws the enemy on the lcd
+ * @param lcd @details the N5110 object
+ */
void draw(N5110 &lcd);
+ /**
+ * @brief Updates the position of the enemy based on its state
+ * @param fps @details the games frames per second as an integer
+ */
void update(int fps);
+
/// accessors and mutators
+ /**
+ * @brief Gets the enemies position
+ * @return position @details a Vector2D object detailing enemies position
+
+ */
Vector2D get_pos();
+ /**
+ * @brief Sets the enemies position
+ * @param position @details a Vector2D position
+ */
void set_pos(Vector2D p);
-
- void set_attack(bool attack);
+ /**
+ * @brief sets a flag on the enemy showing it is attacking
+ * @param attack @details a boolean value showing if the enemy is attacking
+ */
+ //void set_attack(bool attack);
+ /**
+ * @brief Gets the enemies delay time to it starting to attack
+ * @return time to attack @details returns a float value for the time in to the level the enemy begins to attack
+ */
float get_timeToAttack();
-
+ /**
+ * @brief Sets enemies current action
+ * @param Action @details an enumerator with 1 of the following values { waiting, moving, attacking, dying };
+ */
void set_current_action(Action act);
+ /**
+ * @brief Returns enemies current action
+ * @return Action @details an enumerator with 1 of the following values { waiting, moving, attacking, dying };
+ */
Action get_current_action();
-
+ /**
+ * @brief Set Flag if enemy is alive
+ * @param alive @details a boolean value detailing if the enemy is alive
+ */
void set_alive(bool alive);
+ /**
+ * @brief Get Flag if enemy is alive
+ * @return alive @details a boolean value detailing if the enemy is alive
+ */
bool get_alive();
- void set_value(float value);
- float get_value();
private:
@@ -62,7 +136,6 @@
float _animationTick;
Action currentAction;
- float _value;