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
Graphics/Graphics.h@21:44e87d88afe2, 2019-05-09 (annotated)
- Committer:
- el17mcd
- Date:
- Thu May 09 13:10:16 2019 +0000
- Revision:
- 21:44e87d88afe2
- Parent:
- 17:cb39d9fa08dc
Doxygen comments added.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| el17mcd | 16:a2c945279b79 | 1 | #ifndef GRAPHICS_H |
| el17mcd | 16:a2c945279b79 | 2 | #define GRAPHICS_H |
| el17mcd | 12:9e6d5d0a0c82 | 3 | |
| el17mcd | 12:9e6d5d0a0c82 | 4 | #include "mbed.h" |
| el17mcd | 12:9e6d5d0a0c82 | 5 | #include "N5110.h" |
| el17mcd | 12:9e6d5d0a0c82 | 6 | #include "Gamepad.h" |
| el17mcd | 12:9e6d5d0a0c82 | 7 | |
| el17mcd | 21:44e87d88afe2 | 8 | /** Graphics Class |
| el17mcd | 21:44e87d88afe2 | 9 | * @brief Holds the sprites and governs their use. Governs the use of LEDs in the game. |
| el17mcd | 21:44e87d88afe2 | 10 | * @author Maxim C. Delacoe |
| el17mcd | 21:44e87d88afe2 | 11 | * @date April 2019 |
| el17mcd | 21:44e87d88afe2 | 12 | |
| el17mcd | 21:44e87d88afe2 | 13 | @code |
| el17mcd | 21:44e87d88afe2 | 14 | |
| el17mcd | 21:44e87d88afe2 | 15 | #include "mbed.h" |
| el17mcd | 21:44e87d88afe2 | 16 | #include "N5110.h" |
| el17mcd | 21:44e87d88afe2 | 17 | #include "Gamepad.h" |
| el17mcd | 21:44e87d88afe2 | 18 | #include "Graphics.h" |
| el17mcd | 21:44e87d88afe2 | 19 | |
| el17mcd | 21:44e87d88afe2 | 20 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
| el17mcd | 21:44e87d88afe2 | 21 | Gamepad pad; |
| el17mcd | 21:44e87d88afe2 | 22 | Graphics _graphics; |
| el17mcd | 21:44e87d88afe2 | 23 | |
| el17mcd | 21:44e87d88afe2 | 24 | |
| el17mcd | 21:44e87d88afe2 | 25 | int main() { |
| el17mcd | 21:44e87d88afe2 | 26 | |
| el17mcd | 21:44e87d88afe2 | 27 | lcd.init(); |
| el17mcd | 21:44e87d88afe2 | 28 | |
| el17mcd | 21:44e87d88afe2 | 29 | while (1) { |
| el17mcd | 21:44e87d88afe2 | 30 | |
| el17mcd | 21:44e87d88afe2 | 31 | int _mag = pad.get_mag(); |
| el17mcd | 21:44e87d88afe2 | 32 | int _angle = pad.get_angle(); |
| el17mcd | 21:44e87d88afe2 | 33 | |
| el17mcd | 21:44e87d88afe2 | 34 | lcd.clear(); |
| el17mcd | 21:44e87d88afe2 | 35 | _graphics.draw_tank_l(10, 0, lcd); // Draw tank in appropriate position. |
| el17mcd | 21:44e87d88afe2 | 36 | _graphics.draw_turret_l(10, 0, _angle, lcd); |
| el17mcd | 21:44e87d88afe2 | 37 | if (_mag >= 0.5) { // only draw the reticle if the joystick is not in |
| el17mcd | 21:44e87d88afe2 | 38 | _graphics.draw_reticle(10, 0, _angle, lcd); // a neutral position. |
| el17mcd | 21:44e87d88afe2 | 39 | } |
| el17mcd | 21:44e87d88afe2 | 40 | lcd.refresh(); |
| el17mcd | 21:44e87d88afe2 | 41 | } |
| el17mcd | 21:44e87d88afe2 | 42 | } |
| el17mcd | 21:44e87d88afe2 | 43 | @endcode |
| el17mcd | 21:44e87d88afe2 | 44 | */ |
| el17mcd | 21:44e87d88afe2 | 45 | |
| el17mcd | 12:9e6d5d0a0c82 | 46 | class Graphics |
| el17mcd | 12:9e6d5d0a0c82 | 47 | { |
| el17mcd | 16:a2c945279b79 | 48 | |
| el17mcd | 12:9e6d5d0a0c82 | 49 | public: |
| el17mcd | 21:44e87d88afe2 | 50 | // Constructor and destructor. |
| el17mcd | 21:44e87d88afe2 | 51 | /** |
| el17mcd | 21:44e87d88afe2 | 52 | * @brief Constructor |
| el17mcd | 21:44e87d88afe2 | 53 | * @details Non user specified. |
| el17mcd | 21:44e87d88afe2 | 54 | */ |
| el17mcd | 17:cb39d9fa08dc | 55 | Graphics(); |
| el17mcd | 21:44e87d88afe2 | 56 | /** |
| el17mcd | 21:44e87d88afe2 | 57 | * @brief Destructor |
| el17mcd | 21:44e87d88afe2 | 58 | * @details Non user specified. |
| el17mcd | 21:44e87d88afe2 | 59 | */ |
| el17mcd | 17:cb39d9fa08dc | 60 | ~Graphics(); |
| el17mcd | 17:cb39d9fa08dc | 61 | |
| el17mcd | 17:cb39d9fa08dc | 62 | // Left Tank |
| el17mcd | 21:44e87d88afe2 | 63 | /** |
| el17mcd | 21:44e87d88afe2 | 64 | * @brief Draw the left tank sprite. |
| el17mcd | 21:44e87d88afe2 | 65 | * @param x * @details The tank's position in the x direction |
| el17mcd | 21:44e87d88afe2 | 66 | * @param y * @details The tank's position in the y direction |
| el17mcd | 21:44e87d88afe2 | 67 | * @param lcd * @details The lcd object from N5110 class |
| el17mcd | 21:44e87d88afe2 | 68 | */ |
| el17mcd | 17:cb39d9fa08dc | 69 | void draw_tank_l(int x, int y, N5110 &lcd); |
| el17mcd | 21:44e87d88afe2 | 70 | /** |
| el17mcd | 21:44e87d88afe2 | 71 | * @brief Draw the left tank's turret sprite. |
| el17mcd | 21:44e87d88afe2 | 72 | * @param x * @details The left tank turret's position in the x direction |
| el17mcd | 21:44e87d88afe2 | 73 | * @param y * @details The left tank turret's position in the y direction |
| el17mcd | 21:44e87d88afe2 | 74 | * @param angle * @details The tank turret's angle |
| el17mcd | 21:44e87d88afe2 | 75 | * @param lcd * @details The lcd object from N5110 class |
| el17mcd | 21:44e87d88afe2 | 76 | */ |
| el17mcd | 17:cb39d9fa08dc | 77 | void draw_turret_l(int x, int y, int angle, N5110 &lcd); |
| el17mcd | 21:44e87d88afe2 | 78 | /** |
| el17mcd | 21:44e87d88afe2 | 79 | * @brief Show left tank victory screen. |
| el17mcd | 21:44e87d88afe2 | 80 | * @param x * @details The left tank turret's position in the x direction |
| el17mcd | 21:44e87d88afe2 | 81 | * @param y * @details The left tank turret's position in the y direction |
| el17mcd | 21:44e87d88afe2 | 82 | * @param angle * @details The tank turret's angle |
| el17mcd | 21:44e87d88afe2 | 83 | * @param lcd * @details The lcd object from N5110 class |
| el17mcd | 21:44e87d88afe2 | 84 | */ |
| el17mcd | 17:cb39d9fa08dc | 85 | void draw_left_victory(N5110 &lcd); |
| el17mcd | 17:cb39d9fa08dc | 86 | // Right Tank |
| el17mcd | 21:44e87d88afe2 | 87 | /** |
| el17mcd | 21:44e87d88afe2 | 88 | * @brief Draw the right tank sprite. |
| el17mcd | 21:44e87d88afe2 | 89 | * @param x * @details The tank's position in the x direction |
| el17mcd | 21:44e87d88afe2 | 90 | * @param y * @details The tank's position in the y direction |
| el17mcd | 21:44e87d88afe2 | 91 | * @param lcd * @details The lcd object from N5110 class |
| el17mcd | 21:44e87d88afe2 | 92 | */ |
| el17mcd | 17:cb39d9fa08dc | 93 | void draw_tank_r(int x, int y, N5110 &lcd); |
| el17mcd | 21:44e87d88afe2 | 94 | /** |
| el17mcd | 21:44e87d88afe2 | 95 | * @brief Draw the right tank's turret sprite. |
| el17mcd | 21:44e87d88afe2 | 96 | * @param x * @details The right tank turret's position in the x direction |
| el17mcd | 21:44e87d88afe2 | 97 | * @param y * @details The right tank turret's position in the y direction |
| el17mcd | 21:44e87d88afe2 | 98 | * @param angle * @details The tank turret's angle |
| el17mcd | 21:44e87d88afe2 | 99 | * @param lcd * @details The lcd object from N5110 class |
| el17mcd | 21:44e87d88afe2 | 100 | */ |
| el17mcd | 17:cb39d9fa08dc | 101 | void draw_turret_r(int x, int y, int angle, N5110 &lcd); |
| el17mcd | 21:44e87d88afe2 | 102 | /** |
| el17mcd | 21:44e87d88afe2 | 103 | * @brief Show right tank victory screen. |
| el17mcd | 21:44e87d88afe2 | 104 | * @param x * @details The right tank turret's position in the x direction |
| el17mcd | 21:44e87d88afe2 | 105 | * @param y * @details The right tank turret's position in the y direction |
| el17mcd | 21:44e87d88afe2 | 106 | * @param angle * @details The tank turret's angle |
| el17mcd | 21:44e87d88afe2 | 107 | * @param lcd * @details The lcd object from N5110 class |
| el17mcd | 21:44e87d88afe2 | 108 | */ |
| el17mcd | 17:cb39d9fa08dc | 109 | void draw_right_victory(N5110 &lcd); |
| el17mcd | 17:cb39d9fa08dc | 110 | // Projectile |
| el17mcd | 21:44e87d88afe2 | 111 | /** |
| el17mcd | 21:44e87d88afe2 | 112 | * @brief Draw the projectile sprite. |
| el17mcd | 21:44e87d88afe2 | 113 | * @param x * @details The projectile's position in the x direction |
| el17mcd | 21:44e87d88afe2 | 114 | * @param y * @details The projectile's position in the y direction |
| el17mcd | 21:44e87d88afe2 | 115 | * @param lcd * @details The lcd object from N5110 class |
| el17mcd | 21:44e87d88afe2 | 116 | */ |
| el17mcd | 17:cb39d9fa08dc | 117 | void draw_projectile(int x, int y, N5110 &lcd); |
| el17mcd | 17:cb39d9fa08dc | 118 | // Display |
| el17mcd | 21:44e87d88afe2 | 119 | /** |
| el17mcd | 21:44e87d88afe2 | 120 | * @brief Draws a bar/arrow that indicates the strength and direction of the wind. |
| el17mcd | 21:44e87d88afe2 | 121 | * @param wind * @details The acceleration due to wind in the x direction |
| el17mcd | 21:44e87d88afe2 | 122 | * @param lcd * @details The lcd object from N5110 class |
| el17mcd | 21:44e87d88afe2 | 123 | */ |
| el17mcd | 17:cb39d9fa08dc | 124 | void draw_wind_bar(float wind, N5110 &lcd); |
| el17mcd | 21:44e87d88afe2 | 125 | /** |
| el17mcd | 21:44e87d88afe2 | 126 | * @brief Draws a dot to indicate where the tank is aiming. |
| el17mcd | 21:44e87d88afe2 | 127 | * @param x * @details The left tank turret's position in the x direction |
| el17mcd | 21:44e87d88afe2 | 128 | * @param y * @details The left tank turret's position in the y direction |
| el17mcd | 21:44e87d88afe2 | 129 | * @param angle * @details The tank turret's angle |
| el17mcd | 21:44e87d88afe2 | 130 | * @param lcd * @details The lcd object from N5110 class |
| el17mcd | 21:44e87d88afe2 | 131 | */ |
| el17mcd | 17:cb39d9fa08dc | 132 | void draw_reticle(int x, int y, float angle, N5110 &lcd); |
| el17mcd | 17:cb39d9fa08dc | 133 | // Maps |
| el17mcd | 21:44e87d88afe2 | 134 | /** |
| el17mcd | 21:44e87d88afe2 | 135 | * @brief Draws a building obstacle on the map. |
| el17mcd | 21:44e87d88afe2 | 136 | * @param x * @details The map object's position in the x direction |
| el17mcd | 21:44e87d88afe2 | 137 | * @param y * @details The map object's position in the y direction |
| el17mcd | 21:44e87d88afe2 | 138 | * @param lcd * @details The lcd object from N5110 class |
| el17mcd | 21:44e87d88afe2 | 139 | */ |
| el17mcd | 17:cb39d9fa08dc | 140 | void draw_parkinson_map(int x, int y, N5110 &lcd); |
| el17mcd | 17:cb39d9fa08dc | 141 | // LEDs |
| el17mcd | 21:44e87d88afe2 | 142 | /** |
| el17mcd | 21:44e87d88afe2 | 143 | * @brief Lights LEDs equal to the input value. |
| el17mcd | 21:44e87d88afe2 | 144 | * @param current * @details The player's current health |
| el17mcd | 21:44e87d88afe2 | 145 | * @param pad * @details The pad object from Gamepad class |
| el17mcd | 21:44e87d88afe2 | 146 | */ |
| el17mcd | 17:cb39d9fa08dc | 147 | void show_health(int current, Gamepad &pad); |
| el17mcd | 21:44e87d88afe2 | 148 | /** |
| el17mcd | 21:44e87d88afe2 | 149 | * @brief Toggles three LEDS on at a time for the start up screen. |
| el17mcd | 21:44e87d88afe2 | 150 | * @param alt * @details The value of the alternator/incrementer |
| el17mcd | 21:44e87d88afe2 | 151 | * @param pad * @details The pad object from Gamepad class |
| el17mcd | 21:44e87d88afe2 | 152 | */ |
| el17mcd | 17:cb39d9fa08dc | 153 | void start_up(int alt, Gamepad &pad); |
| el17mcd | 21:44e87d88afe2 | 154 | // Start up Screen |
| el17mcd | 21:44e87d88afe2 | 155 | /** |
| el17mcd | 21:44e87d88afe2 | 156 | * @brief Draws the start up screen visuals. |
| el17mcd | 21:44e87d88afe2 | 157 | * @param lcd * @details The lcd object from N5110 class |
| el17mcd | 21:44e87d88afe2 | 158 | */ |
| el17mcd | 21:44e87d88afe2 | 159 | void draw_start_up_screen(N5110 &lcd); |
| el17mcd | 12:9e6d5d0a0c82 | 160 | |
| el17mcd | 12:9e6d5d0a0c82 | 161 | private: |
| el17mcd | 17:cb39d9fa08dc | 162 | // Left Tank |
| el17mcd | 17:cb39d9fa08dc | 163 | void _turret_angle_l1(int x, int y, N5110 &lcd); |
| el17mcd | 17:cb39d9fa08dc | 164 | void _turret_angle_l2(int x, int y, N5110 &lcd); |
| el17mcd | 17:cb39d9fa08dc | 165 | void _turret_angle_l3(int x, int y, N5110 &lcd); |
| el17mcd | 17:cb39d9fa08dc | 166 | void _turret_angle_l4(int x, int y, N5110 &lcd); |
| el17mcd | 17:cb39d9fa08dc | 167 | void _turret_angle_l5(int x, int y, N5110 &lcd); |
| el17mcd | 17:cb39d9fa08dc | 168 | // Right Tank |
| el17mcd | 17:cb39d9fa08dc | 169 | void _turret_angle_r1(int x, int y, N5110 &lcd); |
| el17mcd | 17:cb39d9fa08dc | 170 | void _turret_angle_r2(int x, int y, N5110 &lcd); |
| el17mcd | 17:cb39d9fa08dc | 171 | void _turret_angle_r3(int x, int y, N5110 &lcd); |
| el17mcd | 17:cb39d9fa08dc | 172 | void _turret_angle_r4(int x, int y, N5110 &lcd); |
| el17mcd | 17:cb39d9fa08dc | 173 | void _turret_angle_r5(int x, int y, N5110 &lcd); |
| el17mcd | 13:feadff02d3f7 | 174 | |
| el17mcd | 12:9e6d5d0a0c82 | 175 | }; |
| el17mcd | 12:9e6d5d0a0c82 | 176 | |
| el17mcd | 12:9e6d5d0a0c82 | 177 | #endif // GRAPHICS |