ELEC2645 (2018/19) / Mbed 2 deprecated el17aj

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Enemy.h Source File

Enemy.h

00001 #ifndef ENEMY_H
00002 #define ENEMY_H
00003 
00004 #include "mbed.h"
00005 #include "N5110.h"
00006 #include "Gamepad.h"
00007 #include <time.h>
00008 
00009 
00010 /** CrossHairs Class
00011 @author Adam Jones, University of Leeds
00012 @brief Controls the Enemy Sprites in the Wall Defence game
00013 @date April 2019
00014 @brief Revision 1.0
00015 
00016 @code
00017 #include "Enemy.h"
00018 #include "N5110.h"
00019 
00020 
00021 int main()
00022 { 
00023     //initialise
00024     float timeToAttack = 0.0;   //time at which the enemy will begin to move forwards
00025     float speed = 0.5;  //speed in pixels per frame at which enemy will move forwards
00026     Enemy _enemy;
00027     _enemy.init(timeToAttack, speed);
00028     
00029     //set action
00030     Action myAc = moving; //Action enumerator
00031     _enemy.set_current_action(myAc);  //set enemies current action
00032     
00033     //get action
00034     myAc = _enemy.get_current_action();
00035     
00036     //get position
00037     enemy.get_pos()
00038     
00039     //set position
00040     Vector2D p = {2, 2} //{x,y}
00041     enemy.set_pos(p);
00042     
00043     //get time at which enemy will begin moving
00044     float time = get_timeToAttack();
00045     
00046     //set enemies alive flag true/false
00047     enemy.set_alive(true);
00048     
00049     //get enemies alive flag true/false
00050     enemy.get_alive();
00051     
00052     
00053     //update enemy 
00054     int fps = 30;
00055     enemy.update(int fps);
00056     
00057     
00058     //draw enemy 
00059     N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
00060     lcd.init();
00061     _enemy.draw(lcd);  //draw enemy sprite to display 
00062     
00063     
00064     
00065     
00066     
00067     
00068 }
00069 
00070 @endcode
00071 
00072 
00073 */ 
00074 
00075 //action enumerator keeps track of enemies current state
00076 //and allows for quick routing to correct process via switch state
00077 enum Action { 
00078     waiting,    //enemy not yet attacking (off screen)
00079     moving,     //enemy moving towards players wall
00080     attacking,  //enemy damaging players wall
00081     dying       //enemy has been killed by player 
00082 };
00083 
00084 class Enemy
00085 {
00086 public:
00087     Enemy();
00088     ~Enemy();
00089     
00090     
00091     /** 
00092     * @brief Initialises an enemy with a time to attack and a set speed 
00093     * @param timeToAttack @details The time into the new level that the enemy will start moving forwards
00094     * @param speed @details The speed of the enemy in pixels per frame
00095     */
00096     void init(float timeToAttack, float speed);
00097     /** 
00098     * @brief Draws the enemy on the lcd
00099     * @param lcd @details the N5110 object
00100     */
00101     void draw(N5110 &lcd);
00102     /** 
00103     * @brief Updates the position of the enemy based on its state
00104     * @param fps @details the games frames per second as an integer
00105     */
00106     void update(int fps);
00107     
00108     /// accessors and mutators
00109     /** 
00110     * @brief Gets the enemies position
00111     * @return position @details a Vector2D object detailing enemies position
00112 
00113     */
00114     Vector2D get_pos();
00115     /** 
00116     * @brief Sets the enemies position
00117     * @param position @details a Vector2D position
00118     */
00119     void set_pos(Vector2D p);
00120     
00121     /** 
00122     * @brief Gets the enemies delay time to it starting to attack
00123     * @return time to attack @details returns a float value for the time in to the level the enemy begins to attack
00124     */
00125     float get_timeToAttack();
00126     
00127     /** 
00128     * @brief Sets enemies current action
00129     * @param Action @details an enumerator with 1 of the following values { waiting, moving, attacking, dying };
00130     */
00131     void set_current_action(Action act);
00132     /** 
00133     * @brief Returns enemies current action
00134     * @return Action @details an enumerator with 1 of the following values { waiting, moving, attacking, dying };
00135     */
00136     Action get_current_action();
00137     /** 
00138     * @brief Set Flag if enemy is alive
00139     * @param alive @details a boolean value detailing if the enemy is alive
00140     */
00141     void set_alive(bool alive);
00142     /** 
00143     * @brief Get Flag if enemy is alive
00144     * @return alive @details a boolean value detailing if the enemy is alive
00145     */
00146     bool get_alive();
00147     
00148     
00149 private:
00150 
00151     float _x;
00152     float _y;
00153     
00154     bool _attack;
00155     bool _alive;
00156     float _timeToAttack;
00157     float _speed;
00158         
00159     float _animationTick; 
00160     Action currentAction;
00161     
00162 
00163     
00164     
00165 };
00166 #endif