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: Joystick N5110 SDFileSystem mbed
Diff: main.h
- Revision:
- 8:b2faec20ed8f
- Parent:
- 7:babc367a3333
- Child:
- 9:cbb982b7e353
--- a/main.h Mon May 02 16:28:07 2016 +0000
+++ b/main.h Tue May 03 20:16:06 2016 +0000
@@ -11,6 +11,7 @@
#include "mbed.h"
#include "N5110.h"
#include "Joystick.h"
+#include "SDFileSystem.h"
//Direction invaders are travelling
#define LEFT 0
@@ -44,6 +45,12 @@
InterruptIn sw3(SW3);
/**
+@namespace sd
+@brief Configures the sd card file system
+*/
+SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS
+
+/**
@namespace pc
@brief Serial output to USB for debugging
*/
@@ -63,6 +70,12 @@
InterruptIn shoot_button(PTB18);
/**
+@namespace buzzer
+@brief Configures the buzzer as a PwmOut
+*/
+PwmOut buzzer(PTA2);
+
+/**
@namespace lcd
@brief Interfaces the N5110 Screen with the mbed
<<library /users/eencae/code/N5110/>>
@@ -102,7 +115,19 @@
@brief Fires every 0.1s
*/
Ticker move_invader_normal_missile[2];
-
+/**
+@namespace move_ufo
+@brief Ticker object which moves the UFO across the screen
+@brief Is only attached when the UFO is on the screen
+@brief Fires every 0.1s
+*/
+Ticker move_ufo;
+/**
+@namespace fire_buzzer
+@brief Ticker object used to change buzzer output
+@brief Fires half the period in which move enemies does
+*/
+Ticker fire_buzzer;
/**
@namespace joystick_cursor_regulator
@@ -134,23 +159,36 @@
bool invader_direction = RIGHT; /*!< Direction the invaders are travalling */
//Cannon missile bool
bool cannon_missile_on_screen = false; /*!< Stores whether the cannon has a missile on screen */
+//UFO bool
+bool ufo_on_screen = false; /*!< Stores whether the UFO is on the screen */
+bool ufo_direction = RIGHT; /*!< Stores the direction of the UFO */
+bool ufo_bonus = false; /*!< Player has activated UFO bonus scoring */
+//Buzzer bool
+bool is_muted = true; /*!< Whether game is muted */
+bool play_sound = true; /*!< Whether the buzzer is in a sound playing state */
//Integers
int score = 0; /*!< Current score*/
int fsm_state = 0; /*!< Menu FSM state */
+int buzzer_state = 0; /*!< Buzzer FSM state */
int cursor_y_pos = 0; /*!< Cursor position */
+int shot_count; /*!< No of missiles player has fired for ufo bonus */
//Cannon related integers
int number_of_lives = 3; /*!< Number of lives remaining */
-int cannon_xpos = 24; /*!< X position of the cannon */
+int cannon_xpos = 15; /*!< X position of the cannon */
const int cannon_ypos = 43; /*!< Y position of the cannon */
//Cannon missile related integers
int cannon_missile_x_pos = 28; /*!< X position of the cannon's missile */
int cannon_missile_y_pos = 40; /*!< Y position of the cannon's missile */
//Invader related integers
int no_of_alive_invaders = 15; /*!< Number of alive invaders */
+int down_count = 0; /*!< Times invaders have gone down */
//Invader missile related integers
int invader_strong_missile_x_pos;
int invader_strong_missile_y_pos;
+//UFO integers
+int ufo_x_pos; /*!< X position of the UFO */
+const int ufo_y_pos = 1; /*!< Y position of the UFO */
//Floats
float ticker_period = 1; /*!< Time period the move enemies ticker refreshes */
@@ -359,8 +397,22 @@
{save, {2, 0}},
{menu, {0, 1}}
};
+/**
+@struct FSMBuzzer
+@brief Holds the transition infomation for the buzzer
+*/
+struct FSMBuzzer {
+ const float frequency;
+ const int next_state;
+};
+/*! 4 state FSM holding buzzer frequencies */
+FSMBuzzer fsm_buzzer[] = {
+ {235.0, 1},
+ {235.0, 2},
+ {196.0, 3},
+ {275.0, 0}
+};
-//ISR Flags
/** @name ISR Flags
* Flags set in ISR's
*/
@@ -374,6 +426,8 @@
volatile bool g_cannon_hit_flag = false; /*!< Cannon hit flag */
volatile bool g_joystick_cursor_regulator_flag = false; /*!< Joystick regulator flag */
volatile bool g_shoot_button_debounce_flag = false; /*!< Shoot button debounce flag */
+volatile bool g_move_ufo_flag = false; /*!< Move UFO flag */
+volatile bool g_fire_buzzer_flag = true; /*!< Fire Buzzer flag */
///@}
//Function prototypes
@@ -394,6 +448,8 @@
void (*move_invader_normal_missile_isr[2])(); /*!< Function pointer to help attach move invader normal missile isr's */
void move_invader_normal_missile_0_isr(); /*!< Sets the move invader normal missile [0] flag when called */
void move_invader_normal_missile_1_isr(); /*!< Sets the move invader normal missile [1] flag when called */
+void move_ufo_isr(); /*!< Sets the move ufo flag when called */
+void fire_buzzer_isr(); /*!< Sets the fire buzzer flag when called */
///@}
//Other functions
/** Hangs - flashing an LED
@@ -604,8 +660,21 @@
@param fsm - Finite State Machine for the current menu
*/
void MoveCursor(const struct FSMMenus *fsm);
-
-//void InitUFO();
+/** Prints the menu screen and draws the selection cursor
+*/
+void MenuScreen();
+/** Prints menu screen text
+*/
+void PrintMenuScreen();
+/** Attempts a 1/8 chance to spawn a UFO
+*/
+void AttemptToSpawnUFO();
+/** Clears the UFO
+*/
+void ClearUFO();
+/** Draws the UFO
+@brief If the coordinates extend past the screen the ticker is detached and the UFO is set to not on the screen
+*/
void DrawUFO();
#endif
\ No newline at end of file