ELEC2645 (2018/19) / Mbed 2 deprecated EL17MCD

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Graphics.h Source File

Graphics.h

00001 #ifndef GRAPHICS_H
00002 #define GRAPHICS_H
00003 
00004 #include "mbed.h"
00005 #include "N5110.h"
00006 #include "Gamepad.h"
00007 
00008 /** Graphics Class
00009 * @brief Holds the sprites and governs their use. Governs the use of LEDs in the game.
00010 * @author Maxim C. Delacoe
00011 * @date April 2019
00012  
00013 @code
00014 
00015 #include "mbed.h"
00016 #include "N5110.h"
00017 #include "Gamepad.h"
00018 #include "Graphics.h"
00019  
00020 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
00021 Gamepad pad;
00022 Graphics _graphics;
00023  
00024  
00025 int main() {
00026     
00027   lcd.init();
00028   
00029   while (1) {
00030     
00031     int _mag = pad.get_mag(); 
00032     int _angle = pad.get_angle();
00033     
00034     lcd.clear();
00035     _graphics.draw_tank_l(10, 0, lcd); // Draw tank in appropriate position.                                                          
00036     _graphics.draw_turret_l(10, 0, _angle, lcd); 
00037     if (_mag >= 0.5) {                           // only draw the reticle if the joystick is not in
00038       _graphics.draw_reticle(10, 0, _angle, lcd);    // a neutral position.
00039     } 
00040     lcd.refresh();  
00041   }                
00042 } 
00043 @endcode
00044 */
00045 
00046 class Graphics
00047 {
00048     
00049 public:
00050   // Constructor and destructor.
00051   /**
00052   * @brief Constructor 
00053   * @details Non user specified.
00054   */        
00055   Graphics();
00056   /**
00057   * @brief Destructor 
00058   * @details Non user specified.
00059   */
00060   ~Graphics();
00061    
00062   // Left Tank
00063   /**
00064   * @brief Draw the left tank sprite.
00065   * @param x * @details The tank's position in the x direction
00066   * @param y * @details The tank's position in the y direction
00067   * @param lcd * @details The lcd object from N5110 class
00068   */
00069   void draw_tank_l(int x, int y, N5110 &lcd);
00070   /**
00071   * @brief Draw the left tank's turret sprite.
00072   * @param x * @details The left tank turret's position in the x direction
00073   * @param y * @details The left tank turret's position in the y direction
00074   * @param angle * @details The tank turret's angle
00075   * @param lcd * @details The lcd object from N5110 class
00076   */
00077   void draw_turret_l(int x, int y, int angle, N5110 &lcd);
00078   /**
00079   * @brief Show left tank victory screen.
00080   * @param x * @details The left tank turret's position in the x direction
00081   * @param y * @details The left tank turret's position in the y direction
00082   * @param angle * @details The tank turret's angle
00083   * @param lcd * @details The lcd object from N5110 class
00084   */
00085   void draw_left_victory(N5110 &lcd);
00086   // Right Tank
00087   /**
00088   * @brief Draw the right tank sprite.
00089   * @param x * @details The tank's position in the x direction
00090   * @param y * @details The tank's position in the y direction
00091   * @param lcd * @details The lcd object from N5110 class
00092   */
00093   void draw_tank_r(int x, int y, N5110 &lcd);
00094   /**
00095   * @brief Draw the right tank's turret sprite.
00096   * @param x * @details The right tank turret's position in the x direction
00097   * @param y * @details The right tank turret's position in the y direction
00098   * @param angle * @details The tank turret's angle
00099   * @param lcd * @details The lcd object from N5110 class
00100   */
00101   void draw_turret_r(int x, int y, int angle, N5110 &lcd);
00102   /**
00103   * @brief Show right tank victory screen.
00104   * @param x * @details The right tank turret's position in the x direction
00105   * @param y * @details The right tank turret's position in the y direction
00106   * @param angle * @details The tank turret's angle
00107   * @param lcd * @details The lcd object from N5110 class
00108   */
00109   void draw_right_victory(N5110 &lcd);
00110   // Projectile
00111   /**
00112   * @brief Draw the projectile sprite.
00113   * @param x * @details The projectile's position in the x direction
00114   * @param y * @details The projectile's position in the y direction
00115   * @param lcd * @details The lcd object from N5110 class
00116   */
00117   void draw_projectile(int x, int y, N5110 &lcd);
00118   // Display
00119   /**
00120   * @brief Draws a bar/arrow that indicates the strength and direction of the wind.
00121   * @param wind * @details The acceleration due to wind in the x direction
00122   * @param lcd * @details The lcd object from N5110 class
00123   */
00124   void draw_wind_bar(float wind, N5110 &lcd);
00125   /**
00126   * @brief Draws a dot to indicate where the tank is aiming.
00127   * @param x * @details The left tank turret's position in the x direction
00128   * @param y * @details The left tank turret's position in the y direction
00129   * @param angle * @details The tank turret's angle
00130   * @param lcd * @details The lcd object from N5110 class
00131   */
00132   void draw_reticle(int x, int y, float angle, N5110 &lcd);
00133   // Maps
00134   /**
00135   * @brief Draws a building obstacle on the map.
00136   * @param x * @details The map object's position in the x direction
00137   * @param y * @details The map object's position in the y direction
00138   * @param lcd * @details The lcd object from N5110 class
00139   */
00140   void draw_parkinson_map(int x, int y, N5110 &lcd);
00141   // LEDs
00142   /**
00143   * @brief Lights LEDs equal to the input value.
00144   * @param current * @details The player's current health
00145   * @param pad * @details The pad object from Gamepad class
00146   */
00147   void show_health(int current, Gamepad &pad);
00148   /**
00149   * @brief Toggles three LEDS on at a time for the start up screen.
00150   * @param alt * @details The value of the alternator/incrementer
00151   * @param pad * @details The pad object from Gamepad class
00152   */
00153   void start_up(int alt, Gamepad &pad);
00154   // Start up Screen
00155   /**
00156   * @brief Draws the start up screen visuals.
00157   * @param lcd * @details The lcd object from N5110 class
00158   */
00159   void draw_start_up_screen(N5110 &lcd);
00160     
00161 private:
00162   // Left Tank
00163   void _turret_angle_l1(int x, int y, N5110 &lcd);
00164   void _turret_angle_l2(int x, int y, N5110 &lcd);
00165   void _turret_angle_l3(int x, int y, N5110 &lcd);
00166   void _turret_angle_l4(int x, int y, N5110 &lcd);
00167   void _turret_angle_l5(int x, int y, N5110 &lcd);
00168   // Right Tank
00169   void _turret_angle_r1(int x, int y, N5110 &lcd);
00170   void _turret_angle_r2(int x, int y, N5110 &lcd);
00171   void _turret_angle_r3(int x, int y, N5110 &lcd);
00172   void _turret_angle_r4(int x, int y, N5110 &lcd);
00173   void _turret_angle_r5(int x, int y, N5110 &lcd);
00174 
00175 };
00176 
00177 #endif // GRAPHICS