ELEC2645 (2015/16) / Mbed 2 deprecated L2_SpaceInvaders

Dependencies:   Joystick N5110 SDFileSystem mbed

Committer:
avi23
Date:
Thu May 05 11:01:17 2016 +0000
Revision:
9:cbb982b7e353
Parent:
8:b2faec20ed8f
Added Splash Screen. Debounce Timeout set to attach on rising edge to button to prevent debounce when button is held and released

Who changed what in which revision?

UserRevisionLine numberNew contents of line
avi23 7:babc367a3333 1 /**
avi23 7:babc367a3333 2 @file main.h
avi23 7:babc367a3333 3 @brief Header file containing function prototypes, defines and global variables
avi23 7:babc367a3333 4 @author Avinash Patel
avi23 7:babc367a3333 5 @date April 2016
avi23 7:babc367a3333 6 */
avi23 7:babc367a3333 7
avi23 7:babc367a3333 8 #ifndef MAIN_H
avi23 7:babc367a3333 9 #define MAIN_H
avi23 7:babc367a3333 10
avi23 7:babc367a3333 11 #include "mbed.h"
avi23 7:babc367a3333 12 #include "N5110.h"
avi23 7:babc367a3333 13 #include "Joystick.h"
avi23 8:b2faec20ed8f 14 #include "SDFileSystem.h"
avi23 9:cbb982b7e353 15 #include <algorithm>
avi23 9:cbb982b7e353 16 #include <fstream>
avi23 7:babc367a3333 17
avi23 7:babc367a3333 18 //Direction invaders are travelling
avi23 7:babc367a3333 19 #define LEFT 0
avi23 7:babc367a3333 20 #define RIGHT 1
avi23 7:babc367a3333 21
avi23 7:babc367a3333 22 /**
avi23 7:babc367a3333 23 @namespace r_led
avi23 7:babc367a3333 24 @brief K64F Red LED
avi23 7:babc367a3333 25 */
avi23 7:babc367a3333 26 DigitalOut r_led(LED_RED);
avi23 7:babc367a3333 27 /**
avi23 7:babc367a3333 28 @namespace g_led
avi23 7:babc367a3333 29 @brief K64F Green LED
avi23 7:babc367a3333 30 */
avi23 7:babc367a3333 31 DigitalOut g_led(LED_GREEN);
avi23 7:babc367a3333 32 /**
avi23 7:babc367a3333 33 @namespace b_led
avi23 7:babc367a3333 34 @brief K64F Blue LED
avi23 7:babc367a3333 35 */
avi23 7:babc367a3333 36 DigitalOut b_led(LED_BLUE);
avi23 7:babc367a3333 37
avi23 7:babc367a3333 38 /**
avi23 7:babc367a3333 39 @namespace sw2
avi23 7:babc367a3333 40 @brief Connects SW2 on the K64F as an Interrupt
avi23 7:babc367a3333 41 */
avi23 7:babc367a3333 42 InterruptIn sw2(SW2);
avi23 7:babc367a3333 43 /**
avi23 7:babc367a3333 44 @namespace sw3
avi23 7:babc367a3333 45 @brief Connects SW3 on the K64F as an Interrupt
avi23 7:babc367a3333 46 */
avi23 7:babc367a3333 47 InterruptIn sw3(SW3);
avi23 7:babc367a3333 48
avi23 7:babc367a3333 49 /**
avi23 8:b2faec20ed8f 50 @namespace sd
avi23 8:b2faec20ed8f 51 @brief Configures the sd card file system
avi23 8:b2faec20ed8f 52 */
avi23 8:b2faec20ed8f 53 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS
avi23 8:b2faec20ed8f 54
avi23 8:b2faec20ed8f 55 /**
avi23 7:babc367a3333 56 @namespace pc
avi23 7:babc367a3333 57 @brief Serial output to USB for debugging
avi23 7:babc367a3333 58 */
avi23 7:babc367a3333 59 Serial pc(USBTX,USBRX);
avi23 7:babc367a3333 60
avi23 7:babc367a3333 61 /**
avi23 7:babc367a3333 62 @namespace Joystick
avi23 7:babc367a3333 63 @brief Creates the joystick object
avi23 7:babc367a3333 64 @brief X potentiometer, Y potentiometer, joystick button
avi23 7:babc367a3333 65 */
avi23 7:babc367a3333 66 Joystick joystick(PTB3, PTB2, PTB11);
avi23 7:babc367a3333 67
avi23 7:babc367a3333 68 /**
avi23 7:babc367a3333 69 @namespace shoot_button
avi23 7:babc367a3333 70 @brief Connects the shoot button as an Interrupt
avi23 7:babc367a3333 71 */
avi23 7:babc367a3333 72 InterruptIn shoot_button(PTB18);
avi23 7:babc367a3333 73
avi23 7:babc367a3333 74 /**
avi23 8:b2faec20ed8f 75 @namespace buzzer
avi23 8:b2faec20ed8f 76 @brief Configures the buzzer as a PwmOut
avi23 8:b2faec20ed8f 77 */
avi23 8:b2faec20ed8f 78 PwmOut buzzer(PTA2);
avi23 8:b2faec20ed8f 79
avi23 8:b2faec20ed8f 80 /**
avi23 7:babc367a3333 81 @namespace lcd
avi23 7:babc367a3333 82 @brief Interfaces the N5110 Screen with the mbed
avi23 7:babc367a3333 83 <<library /users/eencae/code/N5110/>>
avi23 7:babc367a3333 84 */
avi23 7:babc367a3333 85 // VCC, SCE, RST, D/C, MOSI, SCLK, LED
avi23 7:babc367a3333 86 N5110 lcd (PTE26 , PTA0 , PTC4 , PTD0 , PTD2 , PTD1 , PTC3);
avi23 7:babc367a3333 87
avi23 7:babc367a3333 88 /**
avi23 7:babc367a3333 89 @namespace update_screen
avi23 7:babc367a3333 90 @brief Ticker object which will be used to update the screen every 0.05s
avi23 7:babc367a3333 91 */
avi23 7:babc367a3333 92 Ticker update_screen;
avi23 7:babc367a3333 93 /**
avi23 7:babc367a3333 94 @namespace move_joystick
avi23 7:babc367a3333 95 @brief Ticker object which will query the status of the joystick
avi23 7:babc367a3333 96 @brief Fires every 0.05s
avi23 7:babc367a3333 97 */
avi23 7:babc367a3333 98 Ticker move_joystick;
avi23 7:babc367a3333 99 /**
avi23 7:babc367a3333 100 @namespace move_cannon_missile
avi23 7:babc367a3333 101 @brief Ticker object which will move the cannon's missile up the screen
avi23 7:babc367a3333 102 @brief Is only attached when a missile is on the screen
avi23 7:babc367a3333 103 @brief Fires every 0.05s
avi23 7:babc367a3333 104 */
avi23 7:babc367a3333 105 Ticker move_cannon_missile;
avi23 7:babc367a3333 106 /**
avi23 7:babc367a3333 107 @namespace move_enemies
avi23 7:babc367a3333 108 @brief Ticker object which moves the enemies across and down the screen
avi23 7:babc367a3333 109 @brief Inital firing speed is 1s - Decreses as no of invaders alive decreses up to 0.1s
avi23 7:babc367a3333 110 */
avi23 7:babc367a3333 111 Ticker move_enemies;
avi23 7:babc367a3333 112 /**
avi23 7:babc367a3333 113 @namespace move_invader_normal_missile
avi23 7:babc367a3333 114 @brief Array of tickers which move the invaders missiles down the screen
avi23 7:babc367a3333 115 @brief 1 Ticker per missile
avi23 7:babc367a3333 116 @brief Only attached when the ticker's missile is visible
avi23 7:babc367a3333 117 @brief Fires every 0.1s
avi23 7:babc367a3333 118 */
avi23 7:babc367a3333 119 Ticker move_invader_normal_missile[2];
avi23 8:b2faec20ed8f 120 /**
avi23 8:b2faec20ed8f 121 @namespace move_ufo
avi23 8:b2faec20ed8f 122 @brief Ticker object which moves the UFO across the screen
avi23 8:b2faec20ed8f 123 @brief Is only attached when the UFO is on the screen
avi23 8:b2faec20ed8f 124 @brief Fires every 0.1s
avi23 8:b2faec20ed8f 125 */
avi23 8:b2faec20ed8f 126 Ticker move_ufo;
avi23 8:b2faec20ed8f 127 /**
avi23 8:b2faec20ed8f 128 @namespace fire_buzzer
avi23 8:b2faec20ed8f 129 @brief Ticker object used to change buzzer output
avi23 8:b2faec20ed8f 130 @brief Fires half the period in which move enemies does
avi23 8:b2faec20ed8f 131 */
avi23 8:b2faec20ed8f 132 Ticker fire_buzzer;
avi23 7:babc367a3333 133
avi23 7:babc367a3333 134 /**
avi23 7:babc367a3333 135 @namespace joystick_cursor_regulator
avi23 7:babc367a3333 136 @brief Timeout object which is used to stop the menu cursor jumping
avi23 7:babc367a3333 137 @brief Fires 0.1s after being attached
avi23 7:babc367a3333 138 */
avi23 7:babc367a3333 139 Timeout joystick_cursor_regulator; //Stops the cursor from jumping
avi23 7:babc367a3333 140 /**
avi23 7:babc367a3333 141 @namespace shoot_button_debounce
avi23 7:babc367a3333 142 @brief Timeout object which is used to reduce noisy input from the shoot button
avi23 7:babc367a3333 143 @brief Fires 0.125s after being attached
avi23 7:babc367a3333 144 */
avi23 7:babc367a3333 145 Timeout shoot_button_debounce; //Stops the cannon from firing when transitioning from a menu to the game
avi23 9:cbb982b7e353 146 /**
avi23 9:cbb982b7e353 147 @namespace lp_wait
avi23 9:cbb982b7e353 148 @brief Timeout object to perform a low power wait
avi23 9:cbb982b7e353 149 @brief Fires at the users request
avi23 9:cbb982b7e353 150 */
avi23 9:cbb982b7e353 151 Timeout lp_wait;
avi23 9:cbb982b7e353 152 /**
avi23 9:cbb982b7e353 153 @namespace cannon_hit
avi23 9:cbb982b7e353 154 @brief Timeout object to keep cannon invunerable after it's been hit
avi23 9:cbb982b7e353 155 @brief Fires 1s after being attached
avi23 9:cbb982b7e353 156 */
avi23 9:cbb982b7e353 157 Timeout cannon_hit;
avi23 7:babc367a3333 158
avi23 7:babc367a3333 159 int screen_buffer[84][48]; /*!< Screen Buffer. Each object on the screen has a different integer assigned to it */
avi23 7:babc367a3333 160 const int empty_pixel = 0 ; /*!< Empty Pixels */
avi23 7:babc367a3333 161 const int cannon_pixel = 1; /*!< Pixel number for cannon */
avi23 7:babc367a3333 162 const int first_barrier_pixel = 2; /*!< Pixel number of barrier no 1 */
avi23 7:babc367a3333 163 const int first_large_invader_pixel = 5; /*!< Pixel number of large invader no 1 */
avi23 7:babc367a3333 164 const int first_medium_invader_pixel = 10; /*!< Pixel number of medium invader no 1 */
avi23 7:babc367a3333 165 const int first_small_invader_pixel = 15; /*!< Pixel number of large invader no 1 */
avi23 7:babc367a3333 166 const int ufo_pixel = 20; /*!< Pixel number for UFO */
avi23 7:babc367a3333 167 const int cannon_missile_pixel = 21; /*!< Pixel number for the cannon's missile */
avi23 7:babc367a3333 168 const int invader_normal_missile_pixel = 22; /*!< Pixel number for the invader's normal missile */
avi23 7:babc367a3333 169
avi23 7:babc367a3333 170 //Booleans
avi23 7:babc367a3333 171 //Invader related bools
avi23 7:babc367a3333 172 bool invaders_in_state2 = true; /*!< Viewing state the invaders are in */
avi23 7:babc367a3333 173 bool invader_direction = RIGHT; /*!< Direction the invaders are travalling */
avi23 7:babc367a3333 174 //Cannon missile bool
avi23 7:babc367a3333 175 bool cannon_missile_on_screen = false; /*!< Stores whether the cannon has a missile on screen */
avi23 8:b2faec20ed8f 176 //UFO bool
avi23 8:b2faec20ed8f 177 bool ufo_on_screen = false; /*!< Stores whether the UFO is on the screen */
avi23 8:b2faec20ed8f 178 bool ufo_direction = RIGHT; /*!< Stores the direction of the UFO */
avi23 8:b2faec20ed8f 179 bool ufo_bonus = false; /*!< Player has activated UFO bonus scoring */
avi23 8:b2faec20ed8f 180 //Buzzer bool
avi23 8:b2faec20ed8f 181 bool is_muted = true; /*!< Whether game is muted */
avi23 8:b2faec20ed8f 182 bool play_sound = true; /*!< Whether the buzzer is in a sound playing state */
avi23 7:babc367a3333 183
avi23 7:babc367a3333 184 //Integers
avi23 7:babc367a3333 185 int score = 0; /*!< Current score*/
avi23 7:babc367a3333 186 int fsm_state = 0; /*!< Menu FSM state */
avi23 9:cbb982b7e353 187 int brightness_state = 4; /*!< Brightness FSM state */
avi23 8:b2faec20ed8f 188 int buzzer_state = 0; /*!< Buzzer FSM state */
avi23 7:babc367a3333 189 int cursor_y_pos = 0; /*!< Cursor position */
avi23 8:b2faec20ed8f 190 int shot_count; /*!< No of missiles player has fired for ufo bonus */
avi23 7:babc367a3333 191 //Cannon related integers
avi23 7:babc367a3333 192 int number_of_lives = 3; /*!< Number of lives remaining */
avi23 8:b2faec20ed8f 193 int cannon_xpos = 15; /*!< X position of the cannon */
avi23 7:babc367a3333 194 const int cannon_ypos = 43; /*!< Y position of the cannon */
avi23 7:babc367a3333 195 //Cannon missile related integers
avi23 7:babc367a3333 196 int cannon_missile_x_pos = 28; /*!< X position of the cannon's missile */
avi23 7:babc367a3333 197 int cannon_missile_y_pos = 40; /*!< Y position of the cannon's missile */
avi23 7:babc367a3333 198 //Invader related integers
avi23 7:babc367a3333 199 int no_of_alive_invaders = 15; /*!< Number of alive invaders */
avi23 8:b2faec20ed8f 200 int down_count = 0; /*!< Times invaders have gone down */
avi23 7:babc367a3333 201 //Invader missile related integers
avi23 7:babc367a3333 202 int invader_strong_missile_x_pos;
avi23 7:babc367a3333 203 int invader_strong_missile_y_pos;
avi23 8:b2faec20ed8f 204 //UFO integers
avi23 8:b2faec20ed8f 205 int ufo_x_pos; /*!< X position of the UFO */
avi23 8:b2faec20ed8f 206 const int ufo_y_pos = 1; /*!< Y position of the UFO */
avi23 7:babc367a3333 207
avi23 7:babc367a3333 208 //Floats
avi23 7:babc367a3333 209 float ticker_period = 1; /*!< Time period the move enemies ticker refreshes */
avi23 7:babc367a3333 210
avi23 7:babc367a3333 211 //Enums
avi23 7:babc367a3333 212 /*! Enum containing invader status */
avi23 7:babc367a3333 213 enum Status {
avi23 7:babc367a3333 214 dead, /*!< Invader is dead - no longer on screen */
avi23 7:babc367a3333 215 dying, /*!< Invader is dying - has been hit with cannon missile but still on the screen */
avi23 7:babc367a3333 216 alive /*!< Invader is alive */
avi23 7:babc367a3333 217 };
avi23 7:babc367a3333 218 /*! Enum containing invader type */
avi23 7:babc367a3333 219 enum Invader {
avi23 7:babc367a3333 220 small, /*!< Small invader */
avi23 7:babc367a3333 221 medium, /*!< Medium invader */
avi23 7:babc367a3333 222 large, /*!< Large invader */
avi23 7:babc367a3333 223 none /*!< No invader */
avi23 7:babc367a3333 224 };
avi23 7:babc367a3333 225 /*! Enum containing game status */
avi23 7:babc367a3333 226 enum GameState {
avi23 7:babc367a3333 227 menu, /*!< Menu state */
avi23 7:babc367a3333 228 game, /*!< Game state */
avi23 7:babc367a3333 229 paused, /*!< Pause game state */
avi23 7:babc367a3333 230 save, /*!< Save game state */
avi23 7:babc367a3333 231 load, /*!< Load game state */
avi23 7:babc367a3333 232 scores, /*!< High scores state */
avi23 9:cbb982b7e353 233 settings, /*!< Setting screen state */
avi23 9:cbb982b7e353 234 over /*!< Game over state */
avi23 7:babc367a3333 235 };
avi23 7:babc367a3333 236 GameState game_state = menu; /*!< Holds what state the game is currently in */
avi23 7:babc367a3333 237
avi23 7:babc367a3333 238 //Bit-maps
avi23 7:babc367a3333 239 /*! Bitmap of cannon */
avi23 7:babc367a3333 240 const bool cannon_bitmap[5][9] = {
avi23 7:babc367a3333 241 {0, 0, 0, 0, 1, 0, 0, 0, 0},
avi23 7:babc367a3333 242 {0, 0, 0, 1, 1, 1, 0, 0, 0},
avi23 7:babc367a3333 243 {0, 1, 1, 1, 1, 1, 1, 1, 0},
avi23 7:babc367a3333 244 {1, 1, 1, 1, 1, 1, 1, 1, 1},
avi23 7:babc367a3333 245 {1, 1, 1, 1, 1, 1, 1, 1, 1}
avi23 7:babc367a3333 246 };
avi23 7:babc367a3333 247 //Bitmaps for small invaders
avi23 7:babc367a3333 248 /*! Bitmap of 1st state small invader */
avi23 7:babc367a3333 249 const bool small_invader_bitmap_1[6][8] = { //First state
avi23 7:babc367a3333 250 {0, 0, 0, 1, 1, 0, 0, 0},
avi23 7:babc367a3333 251 {0, 1, 1, 1, 1, 1, 1, 0},
avi23 7:babc367a3333 252 {1, 1, 0, 1, 1, 0, 1, 1},
avi23 7:babc367a3333 253 {1, 1, 1, 1, 1, 1, 1, 1},
avi23 7:babc367a3333 254 {0, 1, 0, 1, 1, 0, 1, 0},
avi23 7:babc367a3333 255 {1, 0, 1, 0, 0, 1, 0, 1}
avi23 7:babc367a3333 256 };
avi23 7:babc367a3333 257 /*! Bitmap of 2nd state small invader */
avi23 7:babc367a3333 258 const bool small_invader_bitmap_2[6][8] = { //Second state
avi23 7:babc367a3333 259 {0, 0, 0, 1, 1, 0, 0, 0},
avi23 7:babc367a3333 260 {0, 1, 1, 1, 1, 1, 1, 0},
avi23 7:babc367a3333 261 {1, 1, 0, 1, 1, 0, 1, 1},
avi23 7:babc367a3333 262 {1, 1, 1, 1, 1, 1, 1, 1},
avi23 7:babc367a3333 263 {1, 0, 0, 0, 0, 0, 0, 1},
avi23 7:babc367a3333 264 {0, 1, 0, 0, 0, 0, 1, 0}
avi23 7:babc367a3333 265 };
avi23 7:babc367a3333 266 //Bitmaps for medium invaders
avi23 7:babc367a3333 267 /*! Bitmap of 1st state medium invader */
avi23 7:babc367a3333 268 const bool medium_invader_bitmap_1[6][10] = { //First state
avi23 7:babc367a3333 269 {1, 0, 0, 1, 0, 0, 1, 0, 0, 1},
avi23 7:babc367a3333 270 {1, 0, 1, 1, 1, 1, 1, 1, 0, 1},
avi23 7:babc367a3333 271 {1, 1, 1, 0, 1, 1, 0, 1, 1, 1},
avi23 7:babc367a3333 272 {0, 1, 1, 1, 1, 1, 1, 1, 1, 0},
avi23 7:babc367a3333 273 {0, 0, 1, 0, 0, 0, 0, 1, 0, 0},
avi23 7:babc367a3333 274 {0, 1, 0, 0, 0, 0, 0, 0, 1, 0}
avi23 7:babc367a3333 275 };
avi23 7:babc367a3333 276 /*! Bitmap of 2nd state medium invader */
avi23 7:babc367a3333 277 const bool medium_invader_bitmap_2[6][10] = { //Second state
avi23 7:babc367a3333 278 {0, 0, 0, 1, 0, 0, 1, 0, 0, 0},
avi23 7:babc367a3333 279 {0, 0, 1, 1, 1, 1, 1, 1, 0, 0},
avi23 7:babc367a3333 280 {0, 1, 1, 0, 1, 1, 0, 1, 1, 0},
avi23 7:babc367a3333 281 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
avi23 7:babc367a3333 282 {1, 0, 1, 0, 0, 0, 0, 1, 0, 1},
avi23 7:babc367a3333 283 {0, 0, 0, 1, 1, 1, 1, 0, 0, 0}
avi23 7:babc367a3333 284 };
avi23 7:babc367a3333 285 //Bitmaps for large invaders
avi23 7:babc367a3333 286 /*! Bitmap of 1st state large invader */
avi23 7:babc367a3333 287 const bool large_invader_bitmap_1[6][12] = { //First state
avi23 7:babc367a3333 288 {0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0},
avi23 7:babc367a3333 289 {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
avi23 7:babc367a3333 290 {1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1},
avi23 7:babc367a3333 291 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
avi23 7:babc367a3333 292 {0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0},
avi23 7:babc367a3333 293 {0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0}
avi23 7:babc367a3333 294 };
avi23 7:babc367a3333 295 /*! Bitmap of 2nd state large invader */
avi23 7:babc367a3333 296 const bool large_invader_bitmap_2[6][12] = { //Second state
avi23 7:babc367a3333 297 {0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0},
avi23 7:babc367a3333 298 {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
avi23 7:babc367a3333 299 {1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1},
avi23 7:babc367a3333 300 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
avi23 7:babc367a3333 301 {0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0},
avi23 7:babc367a3333 302 {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}
avi23 7:babc367a3333 303 };
avi23 7:babc367a3333 304 /*! Bitmap of invaders normal missile */
avi23 7:babc367a3333 305 const bool invader_normal_missile_bitmap[4][3] = {
avi23 7:babc367a3333 306 {0, 1, 0},
avi23 7:babc367a3333 307 {1, 1, 1},
avi23 7:babc367a3333 308 {0, 1, 0},
avi23 7:babc367a3333 309 {0, 1, 0}
avi23 7:babc367a3333 310 };
avi23 7:babc367a3333 311 /*! Bitmap of barriers */
avi23 7:babc367a3333 312 const bool barrier_bitmap[8][14] = {
avi23 7:babc367a3333 313 {0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0},
avi23 7:babc367a3333 314 {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
avi23 7:babc367a3333 315 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
avi23 7:babc367a3333 316 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
avi23 7:babc367a3333 317 {1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1},
avi23 7:babc367a3333 318 {1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1},
avi23 7:babc367a3333 319 {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1},
avi23 7:babc367a3333 320 {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1}
avi23 7:babc367a3333 321 };
avi23 7:babc367a3333 322 /*! Damage bitmap applied when cannon missile hits barrier */
avi23 7:babc367a3333 323 const bool barrier_cannon_missile_damage_bitmap[3][3] = {
avi23 7:babc367a3333 324 {0, 1, 0},
avi23 7:babc367a3333 325 {1, 0, 0},
avi23 7:babc367a3333 326 {1, 0, 1}
avi23 7:babc367a3333 327 };
avi23 7:babc367a3333 328 /*! Damage bitmap applied when normal invader missile hits barrier */
avi23 7:babc367a3333 329 const bool barrier_invader_normal_missile_damage_bitmap[2][3] = {
avi23 7:babc367a3333 330 {1, 0, 1},
avi23 7:babc367a3333 331 {0, 1, 0}
avi23 7:babc367a3333 332 };
avi23 7:babc367a3333 333 /*! UFO bitmap */
avi23 7:babc367a3333 334 const bool ufo_bitmap[5][14] = {
avi23 7:babc367a3333 335 {0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0},
avi23 7:babc367a3333 336 {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
avi23 7:babc367a3333 337 {0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0},
avi23 7:babc367a3333 338 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
avi23 7:babc367a3333 339 {0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0}
avi23 7:babc367a3333 340 };
avi23 7:babc367a3333 341
avi23 7:babc367a3333 342 /**
avi23 7:babc367a3333 343 @struct Invaders
avi23 7:babc367a3333 344 @brief Holds data for each invader
avi23 7:babc367a3333 345 */
avi23 7:babc367a3333 346 struct Invaders {
avi23 7:babc367a3333 347 int x_pos; /*!< X position of invader */
avi23 7:babc367a3333 348 int y_pos; /*!< Y position of invader */
avi23 7:babc367a3333 349 enum Status status; /*!< Status of invader */
avi23 7:babc367a3333 350 };
avi23 7:babc367a3333 351 Invaders small_invader[5]; /*!< Declares 5 Small Invaders */
avi23 7:babc367a3333 352 Invaders medium_invader[5]; /*!< Declares 5 Medium Invaders */
avi23 7:babc367a3333 353 Invaders large_invader[5]; /*!< Declairs 5 Large Invaders */
avi23 7:babc367a3333 354 /**
avi23 7:babc367a3333 355 @struct InvaderNormalMissiles
avi23 7:babc367a3333 356 @brief Hold data for normal invader missiles
avi23 7:babc367a3333 357 */
avi23 7:babc367a3333 358 struct InvaderNormalMissiles {
avi23 7:babc367a3333 359 int x_pos; /*!< X position of missile */
avi23 7:babc367a3333 360 int y_pos; /*!< Y position of missile */
avi23 7:babc367a3333 361 bool fired; /*!< Whether missile is on the screen */
avi23 7:babc367a3333 362 };
avi23 7:babc367a3333 363 InvaderNormalMissiles invader_normal_missile[2]; /*!< Declares 2 normal invaders */
avi23 7:babc367a3333 364 /**
avi23 7:babc367a3333 365 @struct Barriers
avi23 7:babc367a3333 366 @brief Holds barrier data
avi23 7:babc367a3333 367 */
avi23 7:babc367a3333 368 struct Barriers {
avi23 7:babc367a3333 369 int x_pos; /*!< X position of barrier */
avi23 7:babc367a3333 370 int y_pos; /*!< Y position of barrier */
avi23 7:babc367a3333 371 bool before_bitmap[8][14]; /*!< State of the displayed barrier */
avi23 7:babc367a3333 372 bool after_bitmap[8][14]; /*!< State of barrier to be displayed */
avi23 7:babc367a3333 373 };
avi23 7:babc367a3333 374 Barriers barrier[3]; /*!< Declares 3 barriers */
avi23 7:babc367a3333 375 /**
avi23 9:cbb982b7e353 376 @struct HighScores
avi23 9:cbb982b7e353 377 @brief Holds leaderboard data
avi23 9:cbb982b7e353 378 */
avi23 9:cbb982b7e353 379 struct HighScores {
avi23 9:cbb982b7e353 380 char name[3];
avi23 9:cbb982b7e353 381 int score;
avi23 9:cbb982b7e353 382 };
avi23 9:cbb982b7e353 383 HighScores high_scores[3]; /*!< Holds data for 5 scores */
avi23 9:cbb982b7e353 384 /**
avi23 7:babc367a3333 385 @struct FSMMenus
avi23 7:babc367a3333 386 @brief Hold the transition data for menus
avi23 7:babc367a3333 387 */
avi23 7:babc367a3333 388 struct FSMMenus {
avi23 7:babc367a3333 389 const GameState output; /*!< Output of the current state */
avi23 7:babc367a3333 390 /**
avi23 7:babc367a3333 391 @var next_state
avi23 7:babc367a3333 392 @brief Stores the next state of the FSM
avi23 7:babc367a3333 393 @brief Index 0 is when joystick is down
avi23 7:babc367a3333 394 @brief Index 1 is when joystick is up
avi23 7:babc367a3333 395 */
avi23 7:babc367a3333 396 const int next_state[2];
avi23 7:babc367a3333 397 };
avi23 7:babc367a3333 398 /*! 4 state FSM for main menu */
avi23 7:babc367a3333 399 FSMMenus fsm_main_menu[4] = {
avi23 7:babc367a3333 400 {game, {1, 3}},
avi23 7:babc367a3333 401 {load, {2, 0}},
avi23 7:babc367a3333 402 {scores, {3, 1}},
avi23 7:babc367a3333 403 {settings, {0, 2}}
avi23 7:babc367a3333 404 };
avi23 7:babc367a3333 405 /*! 3 state FSM for pause menu */
avi23 7:babc367a3333 406 FSMMenus fsm_paused[3] = {
avi23 7:babc367a3333 407 {game, {1, 2}},
avi23 7:babc367a3333 408 {save, {2, 0}},
avi23 7:babc367a3333 409 {menu, {0, 1}}
avi23 7:babc367a3333 410 };
avi23 9:cbb982b7e353 411
avi23 9:cbb982b7e353 412 /*! 4 state fsm for settings menu */
avi23 9:cbb982b7e353 413 FSMMenus fsm_settings[4] = {
avi23 9:cbb982b7e353 414 {settings, {1, 3}},
avi23 9:cbb982b7e353 415 {settings, {2, 0}},
avi23 9:cbb982b7e353 416 {settings, {3, 1}},
avi23 9:cbb982b7e353 417 {settings, {0, 2}}
avi23 9:cbb982b7e353 418 };
avi23 9:cbb982b7e353 419 /**
avi23 9:cbb982b7e353 420 @struct FSMBrightness
avi23 9:cbb982b7e353 421 @brief Holds the brightness transition data
avi23 9:cbb982b7e353 422 */
avi23 9:cbb982b7e353 423 struct FSMBrightness {
avi23 9:cbb982b7e353 424 float output;
avi23 9:cbb982b7e353 425 int next_state;
avi23 9:cbb982b7e353 426 };
avi23 9:cbb982b7e353 427 /*! 5 state fsm for brightness storage */
avi23 9:cbb982b7e353 428 FSMBrightness fsm_brightness[5] = {
avi23 9:cbb982b7e353 429 {0.00, 1},
avi23 9:cbb982b7e353 430 {0.25, 2},
avi23 9:cbb982b7e353 431 {0.50, 3},
avi23 9:cbb982b7e353 432 {0.75, 4},
avi23 9:cbb982b7e353 433 {1.00, 0}
avi23 9:cbb982b7e353 434 };
avi23 8:b2faec20ed8f 435 /**
avi23 8:b2faec20ed8f 436 @struct FSMBuzzer
avi23 8:b2faec20ed8f 437 @brief Holds the transition infomation for the buzzer
avi23 8:b2faec20ed8f 438 */
avi23 8:b2faec20ed8f 439 struct FSMBuzzer {
avi23 8:b2faec20ed8f 440 const float frequency;
avi23 8:b2faec20ed8f 441 const int next_state;
avi23 8:b2faec20ed8f 442 };
avi23 8:b2faec20ed8f 443 /*! 4 state FSM holding buzzer frequencies */
avi23 8:b2faec20ed8f 444 FSMBuzzer fsm_buzzer[] = {
avi23 8:b2faec20ed8f 445 {235.0, 1},
avi23 8:b2faec20ed8f 446 {235.0, 2},
avi23 8:b2faec20ed8f 447 {196.0, 3},
avi23 8:b2faec20ed8f 448 {275.0, 0}
avi23 8:b2faec20ed8f 449 };
avi23 7:babc367a3333 450
avi23 7:babc367a3333 451 /** @name ISR Flags
avi23 7:babc367a3333 452 * Flags set in ISR's
avi23 7:babc367a3333 453 */
avi23 7:babc367a3333 454 ///@{
avi23 7:babc367a3333 455 volatile bool g_update_screen_flag = true; /*!< Update screen flag */
avi23 7:babc367a3333 456 volatile bool g_move_joystick_flag = true; /*!< Move joystick flag */
avi23 7:babc367a3333 457 volatile bool g_move_enemies_flag = true; /*!< Move enemies flag */
avi23 7:babc367a3333 458 volatile bool g_shoot_pressed_flag = false; /*!< Shoot pressed flag */
avi23 7:babc367a3333 459 volatile bool g_move_cannon_missile_flag = false; /*!< Move cannon missile flag */
avi23 7:babc367a3333 460 volatile bool g_move_invader_normal_missile_flag[2] = {false, false}; /*!< Move invader normal missile flags */
avi23 7:babc367a3333 461 volatile bool g_cannon_hit_flag = false; /*!< Cannon hit flag */
avi23 7:babc367a3333 462 volatile bool g_joystick_cursor_regulator_flag = false; /*!< Joystick regulator flag */
avi23 7:babc367a3333 463 volatile bool g_shoot_button_debounce_flag = false; /*!< Shoot button debounce flag */
avi23 8:b2faec20ed8f 464 volatile bool g_move_ufo_flag = false; /*!< Move UFO flag */
avi23 8:b2faec20ed8f 465 volatile bool g_fire_buzzer_flag = true; /*!< Fire Buzzer flag */
avi23 9:cbb982b7e353 466 volatile bool g_lp_wait_flag = false; /*!< LP Wait flag */
avi23 7:babc367a3333 467 ///@}
avi23 7:babc367a3333 468
avi23 7:babc367a3333 469 //Function prototypes
avi23 7:babc367a3333 470 //ISR's
avi23 7:babc367a3333 471 /** @name ISR Functions
avi23 7:babc367a3333 472 * Functions to set ISR values
avi23 7:babc367a3333 473 */
avi23 7:babc367a3333 474 ///@{
avi23 7:babc367a3333 475 void update_screen_isr(); /*!< Sets the update screen flag when called */
avi23 7:babc367a3333 476 void move_joystick_isr(); /*!< Sets the move joystick flag when called */
avi23 7:babc367a3333 477 void move_enemies_isr(); /*!< Sets the move enemies flag when called */
avi23 7:babc367a3333 478 void shoot_pressed_isr(); /*!< Sets the shoot pressed flag when called */
avi23 7:babc367a3333 479 void move_cannon_missile_isr(); /*!< Sets the move cannon missile flag when called */
avi23 9:cbb982b7e353 480 void cannon_hit_isr(); /*!< Clears the cannon hit flag when called */
avi23 7:babc367a3333 481 void joystick_cursor_regulator_isr(); /*!< Sets the joystick regulator flag when called */
avi23 7:babc367a3333 482 void shoot_button_debounce_isr(); /*!< Sets the shoot button debounce flag when called */
avi23 7:babc367a3333 483 //Function pointer to move invader normal missile isr
avi23 7:babc367a3333 484 void (*move_invader_normal_missile_isr[2])(); /*!< Function pointer to help attach move invader normal missile isr's */
avi23 7:babc367a3333 485 void move_invader_normal_missile_0_isr(); /*!< Sets the move invader normal missile [0] flag when called */
avi23 7:babc367a3333 486 void move_invader_normal_missile_1_isr(); /*!< Sets the move invader normal missile [1] flag when called */
avi23 8:b2faec20ed8f 487 void move_ufo_isr(); /*!< Sets the move ufo flag when called */
avi23 8:b2faec20ed8f 488 void fire_buzzer_isr(); /*!< Sets the fire buzzer flag when called */
avi23 9:cbb982b7e353 489 void lp_wait_isr(); /*!< Clear the lp wait flag when called */
avi23 9:cbb982b7e353 490 void shoot_pressed_rise_isr(); /*!< Attaches shoot button debounce timeout */
avi23 7:babc367a3333 491 ///@}
avi23 7:babc367a3333 492 //Other functions
avi23 7:babc367a3333 493 /** Hangs - flashing an LED
avi23 7:babc367a3333 494 */
avi23 7:babc367a3333 495 void error();
avi23 7:babc367a3333 496 /** Sets up serial port to 115200 baud
avi23 7:babc367a3333 497 */
avi23 7:babc367a3333 498 void init_serial();
avi23 7:babc367a3333 499 /** Set-up the on-board LEDs and switches
avi23 7:babc367a3333 500 */
avi23 7:babc367a3333 501 void init_K64F();
avi23 7:babc367a3333 502 /** Configures the shoot button
avi23 7:babc367a3333 503 @brief Sets the shoot button to PullUp mode.
avi23 7:babc367a3333 504 @brief Sets the falling edge of the swich to call the shoot_pressed_isr
avi23 7:babc367a3333 505 */
avi23 7:babc367a3333 506 void init_shoot();
avi23 7:babc367a3333 507 /** Seeds the random number generator with noise from an analog in pin
avi23 7:babc367a3333 508 */
avi23 7:babc367a3333 509 void init_rng();
avi23 7:babc367a3333 510 /** Clears the screen buffer and runs invader and barrier initalisation functions
avi23 7:babc367a3333 511 @brief Sets the flags so invaders show up straight away.
avi23 7:babc367a3333 512 @brief Clears the missile fired flags
avi23 7:babc367a3333 513 */
avi23 7:babc367a3333 514 void InitaliseGame();
avi23 7:babc367a3333 515 /** Contains game logic
avi23 7:babc367a3333 516 @brief Calls screen refresh, cannon movement, barrier drawing, invader movement, missile movement, pause and game over transition functions
avi23 7:babc367a3333 517 @brief Only calls functions when ISR flags are set
avi23 7:babc367a3333 518 */
avi23 7:babc367a3333 519 void Game();
avi23 7:babc367a3333 520 /** Loops through the screen buffer
avi23 7:babc367a3333 521 @brief If pixels are set in the screen buffer set them on the lcd
avi23 7:babc367a3333 522 @brief Otherwise clear them
avi23 7:babc367a3333 523 */
avi23 7:babc367a3333 524 void UpdateScreen();
avi23 7:babc367a3333 525 /** Clears the cannon from the buffer
avi23 7:babc367a3333 526 @brief Increments or decrements the x coordinate of the cannon depending on joystick position - Capped between 0 and 75
avi23 7:babc367a3333 527 @brief Redraws the cannon onto the buffer
avi23 7:babc367a3333 528 */
avi23 7:babc367a3333 529 void MoveCannon();
avi23 7:babc367a3333 530 /** @fn Sets the position and status of the small invaders
avi23 7:babc367a3333 531 */
avi23 7:babc367a3333 532 void InitSmallInvaders();
avi23 7:babc367a3333 533 /** @fn Cycles through small invaders
avi23 7:babc367a3333 534 @brief If their status is not equal to dead clear them from the buffer
avi23 7:babc367a3333 535 */
avi23 7:babc367a3333 536 void ClearSmallInvaders();
avi23 7:babc367a3333 537 /** Cycles through the small invader current bitmap and sets the pixels it occupys in the buffer to empty
avi23 7:babc367a3333 538 @param invader_no - Small invader object number between 0-4
avi23 7:babc367a3333 539 */
avi23 7:babc367a3333 540 void ClearSingleSmallInvader(int invader_no);
avi23 7:babc367a3333 541 /** Cycles through small invaders
avi23 7:babc367a3333 542 @brief If their status is equal to alive set them in the buffer
avi23 7:babc367a3333 543 */
avi23 7:babc367a3333 544 void DrawSmallInvaders();
avi23 7:babc367a3333 545 /** Cycles through the small invader current bitmap and sets the pixels it occupys in the buffer to first_small_invader_pixel + invader_no
avi23 7:babc367a3333 546 @param invader_no - Small invader object number between 0-4
avi23 7:babc367a3333 547 */
avi23 7:babc367a3333 548 void DrawSingleSmallInvader(int invader_no);
avi23 7:babc367a3333 549 /** Sets the position and status of the medium invaders
avi23 7:babc367a3333 550 */
avi23 7:babc367a3333 551 void InitMediumInvaders();
avi23 7:babc367a3333 552 /** Cycles through medium invaders
avi23 7:babc367a3333 553 @brief If their status is not equal to dead clear them from the buffer
avi23 7:babc367a3333 554 */
avi23 7:babc367a3333 555 void ClearMediumInvaders();
avi23 7:babc367a3333 556 /** Cycles through the medium invader current bitmap and sets the pixels it occupys in the buffer to empty
avi23 7:babc367a3333 557 @param invader_no - Medium invader object number between 0-4
avi23 7:babc367a3333 558 */
avi23 7:babc367a3333 559 void ClearSingleMediumInvader(int invader_no);
avi23 7:babc367a3333 560 /** Cycles through medium invaders
avi23 7:babc367a3333 561 @brief If their status is equal to alive set them in the buffer
avi23 7:babc367a3333 562 */
avi23 7:babc367a3333 563 void DrawMediumInvaders();
avi23 7:babc367a3333 564 /** Cycles through the medium invader current bitmap and sets the pixels it occupys in the buffer to first_medium_invader_pixel + invader_no
avi23 7:babc367a3333 565 @param invader_no - Medium invader object number between 0-4
avi23 7:babc367a3333 566 */
avi23 7:babc367a3333 567 void DrawSingleMediumInvader(int invader_no);
avi23 7:babc367a3333 568 /** Sets the position and status of the large invaders
avi23 7:babc367a3333 569 */
avi23 7:babc367a3333 570 void InitLargeInvaders();
avi23 7:babc367a3333 571 /** Cycles through large invaders
avi23 7:babc367a3333 572 @brief If their status is not equal to dead clear them from the buffer
avi23 7:babc367a3333 573 */
avi23 7:babc367a3333 574 void ClearLargeInvaders();
avi23 7:babc367a3333 575 /** Cycles through the large invader current bitmap and sets the pixels it occupys in the buffer to empty
avi23 7:babc367a3333 576 @param invader_no - Large invader object number between 0-4
avi23 7:babc367a3333 577 */
avi23 7:babc367a3333 578 void ClearSingleLargeInvader(int invader_no);
avi23 7:babc367a3333 579 /** Cycles through large invaders
avi23 7:babc367a3333 580 @brief If their status is equal to alive set them in the buffer
avi23 7:babc367a3333 581 */
avi23 7:babc367a3333 582 void DrawLargeInvaders();
avi23 7:babc367a3333 583 /** Cycles through the large invader current bitmap and sets the pixels it occupys in the buffer to first_large_invader_pixel + invader_no
avi23 7:babc367a3333 584 @param invader_no - Large invader object number between 0-4
avi23 7:babc367a3333 585 */
avi23 7:babc367a3333 586 void DrawSingleLargeInvader(int invader_no);
avi23 7:babc367a3333 587 /** Sets the position and loads the bitmap into the barrier objects
avi23 7:babc367a3333 588 */
avi23 7:babc367a3333 589 void InitBarriers();
avi23 7:babc367a3333 590 /** Clears the barrier with the before bitmap and redraw it from the after bitmap which has the damage applied
avi23 7:babc367a3333 591 @brief Copies the after bitmap to the before bitmap
avi23 7:babc367a3333 592 */
avi23 7:babc367a3333 593 void DrawBarriers();
avi23 7:babc367a3333 594 /** If the invader direction is right, calculate the right limit and move the invaders right
avi23 7:babc367a3333 595 @brief Otherwise calculate the left limit and move the invaders left
avi23 7:babc367a3333 596 */
avi23 7:babc367a3333 597 void MoveInvaderXPositions();
avi23 7:babc367a3333 598 /** Checks the status off the invaders per column, starting from the left
avi23 7:babc367a3333 599 @brief If they're alive return the row number
avi23 7:babc367a3333 600 @returns The left-most column invaders are alive
avi23 7:babc367a3333 601 */
avi23 7:babc367a3333 602 int CalculateInvaderLeftLimit();
avi23 7:babc367a3333 603 /** Checks the status off the invaders per column, starting from the right
avi23 7:babc367a3333 604 @brief If they're alive return the row number
avi23 7:babc367a3333 605 @returns The right-most column invaders are alive
avi23 7:babc367a3333 606 */
avi23 7:babc367a3333 607 int CalculateInvaderRightLimit();
avi23 7:babc367a3333 608 /** If there is still room for the invaders to move, move them 2 to the left
avi23 7:babc367a3333 609 @brief Otherwise move them down
avi23 7:babc367a3333 610 @param limit - Large invader object to check for space against
avi23 7:babc367a3333 611 */
avi23 7:babc367a3333 612 void MoveInvadersLeft(int limit);
avi23 7:babc367a3333 613 /** If there is still room for the invaders to move, move them 2 to the right
avi23 7:babc367a3333 614 @brief Otherwise move them down
avi23 7:babc367a3333 615 @param limit - Large invader object to check for space against
avi23 7:babc367a3333 616 */
avi23 7:babc367a3333 617 void MoveInvadersRight(int limit);
avi23 7:babc367a3333 618 /** Calculates the lowest alive invader
avi23 7:babc367a3333 619 @brief If there is still space for the invader to move, move them 3 pixels down
avi23 7:babc367a3333 620 @brief Otherwise end the game
avi23 7:babc367a3333 621 */
avi23 7:babc367a3333 622 void MoveInvaderYPositions(bool new_direction);
avi23 7:babc367a3333 623 /** Checks each row of invaders to find the lowest row which has an alive invader
avi23 7:babc367a3333 624 @returns The lowest row which has an alive invader
avi23 7:babc367a3333 625 */
avi23 7:babc367a3333 626 Invader CalculateInvaderYLimit();
avi23 7:babc367a3333 627 /** Queries the invaders on their status in the specified column
avi23 7:babc367a3333 628 @param column - The column to query
avi23 7:babc367a3333 629 @returns The lowest invader alive in that column
avi23 7:babc367a3333 630 */
avi23 7:babc367a3333 631 Invader LowestInvaderInColumn(int column);
avi23 7:babc367a3333 632 /** Sets the cannon fired flag to true
avi23 7:babc367a3333 633 @brief Configures the start coordinates
avi23 7:babc367a3333 634 @brief Attaches the move cannon missile ticker to fire every 0.05s
avi23 7:babc367a3333 635 */
avi23 7:babc367a3333 636 void FireCannonMissile();
avi23 7:babc367a3333 637 /** If the missile is not beyond the bounds of the screen, clear it, increment the shot and run collision detection
avi23 7:babc367a3333 638 @brief Otherwise clear the last 3 pixels of the missile, mark it as no longer on the screen and detach the ticker
avi23 7:babc367a3333 639 */
avi23 7:babc367a3333 640 void MoveCannonMissile();
avi23 7:babc367a3333 641 /** If the missile hits an invader it will clear it and increment the score or if it hits a barrier apply the appropiate damage to it
avi23 7:babc367a3333 642 @brief Otherwise push the missile to the screen buffer
avi23 7:babc367a3333 643 */
avi23 7:babc367a3333 644 void CollisionDetectionCannonMissile();
avi23 7:babc367a3333 645 /** Finds the invader number the missile hits, sets the hit invader to dying, decrements the no_of_alive_invaders
avi23 7:babc367a3333 646 @brief Stops the missile from travalling up the screen
avi23 7:babc367a3333 647 @param first_pixel - Start no of invader group hit
avi23 7:babc367a3333 648 @param row - What part of the missile hit the invader
avi23 7:babc367a3333 649 @param invader[5] - Struct of the invader group which was hit
avi23 7:babc367a3333 650 @returns The invader number which was hit
avi23 7:babc367a3333 651 */
avi23 7:babc367a3333 652 int CannonMissileHitInvader(int first_pixel, int row, struct Invaders (&invader)[5]);
avi23 7:babc367a3333 653 /** Calculates where to start drawing the damage bitmap over the barrier bitmap and performs the operation
avi23 7:babc367a3333 654 @param row - Which part of the missile hit the barrier
avi23 7:babc367a3333 655 */
avi23 7:babc367a3333 656 void CannonMissileHitBarrier(int row);
avi23 7:babc367a3333 657 /** Random chance of 1/18, decrementing to a 1/3 depending on no of alive invaders, to fire a missile
avi23 7:babc367a3333 658 @brief Only fires if they're are less than 2 on the screen
avi23 7:babc367a3333 659 */
avi23 7:babc367a3333 660 void AttemptToFireInvaderNormalMissiles();
avi23 7:babc367a3333 661 /** Finds the centre point of the chosen invader and fires the missile
avi23 7:babc367a3333 662 @brief Attaches the ticker to move the missile every 0.05s
avi23 7:babc367a3333 663 @param missile_no - Which missile will be fired
avi23 7:babc367a3333 664 @param source - Type of invader which missile will be fired from (Used to calculate start position)
avi23 7:babc367a3333 665 @param invader - Invader which missile will orginiate from
avi23 7:babc367a3333 666 */
avi23 7:babc367a3333 667 void FireNormalInvaderMissile(int missile_no, Invader source, const struct Invaders (&invader));
avi23 7:babc367a3333 668 /** Clears the missile from the screen buffer
avi23 7:babc367a3333 669 @brief Increments the missile up the screen and runs collision detection if within screen bounds, otherwise set fired flag as false and detach the ticker
avi23 7:babc367a3333 670 @param missile_no - Which missile is being moved
avi23 7:babc367a3333 671 */
avi23 7:babc367a3333 672 void MoveInvaderNormalMissile(int missile_no);
avi23 7:babc367a3333 673 /** Checks the bottom centre point for a collision. If it hasn't push the missile to the screen buffer
avi23 7:babc367a3333 674 @param missile_no - Which missile is being checked
avi23 7:babc367a3333 675 */
avi23 7:babc367a3333 676 void CollisionDetectionInvaderNormalMissile(int missile_no);
avi23 7:babc367a3333 677 /** Decrements the number of lives and pauses the game for 2 seconds
avi23 7:babc367a3333 678 */
avi23 7:babc367a3333 679 void InvaderNormalMissileHitCannon();
avi23 7:babc367a3333 680 /** Calculates where to start drawing the damage bitmap over the barrier bitmap and performs the operation
avi23 7:babc367a3333 681 @param missile - Missile which hit the barrier
avi23 7:babc367a3333 682 */
avi23 7:babc367a3333 683 void InvaderNormalMissileHitBarrier(const struct InvaderNormalMissiles (&missile));
avi23 7:babc367a3333 684 /** Detaches game related tickers
avi23 7:babc367a3333 685 */
avi23 7:babc367a3333 686 void DetachTickers();
avi23 7:babc367a3333 687 /** Attaches game related tickers
avi23 7:babc367a3333 688 */
avi23 7:babc367a3333 689 void AttachTickers();
avi23 7:babc367a3333 690 /** Prints the pause screen and draws the selection cursor
avi23 7:babc367a3333 691 */
avi23 7:babc367a3333 692 void PauseScreen();
avi23 7:babc367a3333 693 /** Prints the text on the pause screen
avi23 7:babc367a3333 694 */
avi23 7:babc367a3333 695 void PrintPauseScreen();
avi23 7:babc367a3333 696 /** Clears the cursor and sets the next state of the supplied fsm
avi23 7:babc367a3333 697 @brief Next state depends on joystick value
avi23 7:babc367a3333 698 @param fsm - Finite State Machine for the current menu
avi23 7:babc367a3333 699 */
avi23 7:babc367a3333 700 void MoveCursor(const struct FSMMenus *fsm);
avi23 8:b2faec20ed8f 701 /** Prints the menu screen and draws the selection cursor
avi23 8:b2faec20ed8f 702 */
avi23 8:b2faec20ed8f 703 void MenuScreen();
avi23 8:b2faec20ed8f 704 /** Prints menu screen text
avi23 8:b2faec20ed8f 705 */
avi23 8:b2faec20ed8f 706 void PrintMenuScreen();
avi23 8:b2faec20ed8f 707 /** Attempts a 1/8 chance to spawn a UFO
avi23 8:b2faec20ed8f 708 */
avi23 8:b2faec20ed8f 709 void AttemptToSpawnUFO();
avi23 8:b2faec20ed8f 710 /** Clears the UFO
avi23 8:b2faec20ed8f 711 */
avi23 8:b2faec20ed8f 712 void ClearUFO();
avi23 8:b2faec20ed8f 713 /** Draws the UFO
avi23 8:b2faec20ed8f 714 @brief If the coordinates extend past the screen the ticker is detached and the UFO is set to not on the screen
avi23 8:b2faec20ed8f 715 */
avi23 7:babc367a3333 716 void DrawUFO();
avi23 9:cbb982b7e353 717 /** Predicate function to sort high scores struct
avi23 9:cbb982b7e353 718 @param lhs - Object to be sorted
avi23 9:cbb982b7e353 719 @param rhs - Object to be sorted
avi23 9:cbb982b7e353 720 @returns lhs.score > rhs.score
avi23 9:cbb982b7e353 721 */
avi23 9:cbb982b7e353 722 bool high_scores_sorter(const struct HighScores (&lhs), const struct HighScores (&rhs));
avi23 9:cbb982b7e353 723 /** Prints the score screen
avi23 9:cbb982b7e353 724 */
avi23 9:cbb982b7e353 725 void ScoreScreen();
avi23 9:cbb982b7e353 726 /** Prints scores to screen
avi23 9:cbb982b7e353 727 */
avi23 9:cbb982b7e353 728 void PrintHighScores();
avi23 9:cbb982b7e353 729 /** Prints the game over screen
avi23 9:cbb982b7e353 730 @brief Name on the left, scores on the right
avi23 9:cbb982b7e353 731 */
avi23 9:cbb982b7e353 732 void GameOverScreen();
avi23 9:cbb982b7e353 733 /** Asks the user to input 3 charactors for name
avi23 9:cbb982b7e353 734 @param name[3] - Name to go with high score
avi23 9:cbb982b7e353 735 */
avi23 9:cbb982b7e353 736 void GetNameForScore(int (&name)[3]);
avi23 9:cbb982b7e353 737 /** Saves the high score structs to file
avi23 9:cbb982b7e353 738 @param name[3] - Name to go with high score
avi23 9:cbb982b7e353 739 */
avi23 9:cbb982b7e353 740 void SaveHighScore(const int (&name)[3]);
avi23 9:cbb982b7e353 741 /** Saves the status of the game to the sd card
avi23 9:cbb982b7e353 742 @brief File is called game_save.dat
avi23 9:cbb982b7e353 743 */
avi23 9:cbb982b7e353 744 void SaveGameData();
avi23 9:cbb982b7e353 745 /** Loads the status of the game to the sd card
avi23 9:cbb982b7e353 746 @brief File is called game_save.dat
avi23 9:cbb982b7e353 747 */
avi23 9:cbb982b7e353 748 void LoadGameData();
avi23 9:cbb982b7e353 749 /**Loads High scores
avi23 9:cbb982b7e353 750 */
avi23 9:cbb982b7e353 751 void LoadHighScores();
avi23 9:cbb982b7e353 752 /** Prints the settings screen
avi23 9:cbb982b7e353 753 */
avi23 9:cbb982b7e353 754 void SettingsScreen();
avi23 9:cbb982b7e353 755 /** Prints static text on screen
avi23 9:cbb982b7e353 756 */
avi23 9:cbb982b7e353 757 void PrintSettingsText();
avi23 9:cbb982b7e353 758 /** Prints changing options on screen
avi23 9:cbb982b7e353 759 */
avi23 9:cbb982b7e353 760 void PrintSettingsOptions();
avi23 9:cbb982b7e353 761 /** Changes requested value on settings screen
avi23 9:cbb982b7e353 762 */
avi23 9:cbb982b7e353 763 void EditOption();
avi23 9:cbb982b7e353 764 /** Deletes game data
avi23 9:cbb982b7e353 765 */
avi23 9:cbb982b7e353 766 void DeleteGameData();
avi23 9:cbb982b7e353 767 /** Attaches a timeout then sets the MCU to sleep until it fires
avi23 9:cbb982b7e353 768 @param t - Time to sleep
avi23 9:cbb982b7e353 769 */
avi23 9:cbb982b7e353 770 void LPWait(float t);
avi23 9:cbb982b7e353 771 /** Prints a splash screen and uses LPWait to wait for 3 seconds
avi23 9:cbb982b7e353 772 */
avi23 9:cbb982b7e353 773 void SplashScreen();
avi23 9:cbb982b7e353 774 /** Sets the buzzer frequency and activates or deactivates it
avi23 9:cbb982b7e353 775 */
avi23 9:cbb982b7e353 776 void PlayBuzzer();
avi23 7:babc367a3333 777
avi23 7:babc367a3333 778 #endif