Marty Laverick / main

Dependents:   DCGame el14m2l_Dungeon_Crawler_Game

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.h Source File

main.h

Go to the documentation of this file.
00001 /**
00002 @file main.h
00003 @brief Header file containing function prototypes, defines and global variables for the main.cpp file.
00004 @brief Version 1.0.0
00005 @author Marty Laverick
00006 @date 5th May 2016
00007 */
00008 
00009 #ifndef _MAIN_H
00010 #define _MAIN_H
00011 
00012 #include "mbed.h"
00013 #include "N5110.h"
00014 #include "SDFileSystem.h"
00015 #include "drawings.h"
00016 #include "music.h"
00017 
00018 #define DIRECTION_TOLERANCE 0.05f
00019 #define NX 84
00020 #define NY 48
00021 
00022 /**
00023 @namespace r_led
00024 @brief GPIO output for the on-board red LED
00025 */
00026 DigitalOut r_led(LED_RED);
00027 /**
00028 @namespace g_led
00029 @brief GPIO output for the on-board green LED
00030 */
00031 DigitalOut g_led(LED_GREEN);
00032 /**
00033 @namespace b_led
00034 @brief GPIO output for the on-board blue LED
00035 */
00036 DigitalOut b_led(LED_BLUE);
00037 /**
00038 @namespace sw2
00039 @brief GPIO input for the on-board switch
00040 */
00041 InterruptIn sw2(SW2);
00042 /**
00043 @namespace sw3
00044 @brief GPIO input for the on-board switch
00045 */
00046 InterruptIn sw3(SW3);
00047 /**
00048 @namespace js_pot_x
00049 @brief GPIO input for the x-axis potentiometer on the joystick
00050 */
00051 AnalogIn js_pot_x(PTB2);
00052 /**
00053 @namespace js_pot_y
00054 @brief GPIO input for the y-axis potentiometer on the joystick
00055 */
00056 AnalogIn js_pot_y(PTB3);
00057 /**
00058 @namespace js_button
00059 @brief GPIO input for the button on the joystick
00060 */
00061 InterruptIn js_button(PTB11);
00062 /**
00063 @namespace b_button
00064 @brief GPIO input for the button on the PCB
00065 */
00066 InterruptIn b_button(PTB10);
00067 /**
00068 @namespace lcd
00069 @brief GPIO inputs and outputs for the visual display
00070 */
00071 N5110 lcd(PTE26, PTA0, PTC4, PTD0, PTD2, PTD1, PTC3);
00072 /**
00073 @namespace sd
00074 @brief GPIO inputs and outputs for the SD card
00075 */
00076 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
00077 /**
00078 @namespace update_flag
00079 @brief Ticker to execute the flag update
00080 */
00081 Ticker update_flag;
00082 /**
00083 @namespace *fp
00084 @brief FILE pointer to allow file access from the SD card
00085 */
00086 FILE *fp;
00087 
00088 float refresh_rate ; /*!< refresh_rate set in main */
00089 float g_dt ; /*!< g_dt set in main from refresh_rate */
00090 bool up_flag ;   /*!< up_flag set in ISR */
00091 bool js_button_previous ;    /*!< js_button_previous set and flipped in update_joystick */
00092 bool b_button_previous ; /*!< b_button_previous set and flipped in update_joystick */
00093 bool menu_viewed ;   /*!< menu_viewed set and flipped in menu */
00094 bool jumping ;   /*!< jumping set in init_game and flipped in start_game */
00095 bool spike1_there ;  /*!< spike1_there set in init_game and flipped in start_game */
00096 bool spike2_there ;  /*!< spike2_there set in init_game and flipped in start_game */
00097 bool spike3_there ;  /*!< spike3_there set in init_game and flipped in start_game */
00098 bool spike4_there ;  /*!< spike4_there set in init_game and flipped in start_game */
00099 bool spike5_there ;  /*!< spike5_there set in init_game and flipped in start_game */
00100 bool dead ;  /*!< dead set in init_game and flipped in start_game */
00101 int selector ;   /*!< selector set in menu */
00102 int option ; /*!< option set in menu */
00103 int health ; /*!< health set in init_game and start_game */
00104 int spike_x1 ;   /*!< spike_x1 set in init_game and start_game */
00105 int spike_x2 ;   /*!< spike_x2 set in init_game and start_game */
00106 int spike_x3 ;   /*!< spike_x3 set in init_game and start_game */
00107 int spike_x4 ;   /*!< spike_x4 set in init_game and start_game */
00108 int spike_x5 ;   /*!< spike_x5 set in init_game and start_game */
00109 int spike1_counter ; /*!< spike1_counter set in init_game and start_game */
00110 int spike2_counter ; /*!< spike2_counter set in init_game and start_game */
00111 int spike3_counter ; /*!< hspike3_counterealth set in init_game and start_game */
00112 int spike4_counter ; /*!< spike4_counter set in init_game and start_game */
00113 int spike5_counter ; /*!< spike5_counter set in init_game and start_game */
00114 int jump_counter ;   /*!< jump_counter set in init_game and start_game */
00115 int score_counter ;  /*!< score_counter set in init_game and start_game */
00116 int highscore1 ; /*!< highscore1 set in menu and new_highscore */
00117 int highscore2 ; /*!< highscore2 set in menu and new_highscore */
00118 int highscore3 ; /*!< highscore3 set in menu and new_highscore */
00119 int highscore4 ; /*!< highscore4 set in menu and new_highscore */
00120 int highscore5 ; /*!< highscore5 set in menu and new_highscore */
00121 int letter ; /*!< letter set in register_name */
00122 int letter1 ;    /*!< letter1 set in register_name */
00123 int letter2 ;    /*!< letter2 set in register_name */
00124 int letter3 ;    /*!< letter3 set in register_name */
00125 int letter_counter ; /*!< letter_counter set in register_name */
00126 char score [10]; /*!< score set in death */
00127 char score1 [10];    /*!< score1 set in highscores */
00128 char score2 [10];    /*!< score2 set in highscores */
00129 char score3 [10];    /*!< score3 set in highscores */
00130 char score4 [10];    /*!< score4 set in highscores */
00131 char score5 [10];    /*!< score5 set in highscores */
00132 char name [3];   /*!< name set in register_name */
00133 char name1 [4];  /*!< name1 set in menu and new_highscore */
00134 char name2 [4];  /*!< name2 set in menu and new_highscore */
00135 char name3 [4];  /*!< name3 set in menu and new_highscore */
00136 char name4 [4];  /*!< name4 set in menu and new_highscore */
00137 char name5 [4];  /*!< name5 set in menu and new_highscore */
00138 
00139 // enums
00140 enum DirectionName {
00141     UP,
00142     DOWN,
00143     LEFT,
00144     RIGHT,
00145     CENTRE,
00146     UPRIGHT,
00147     UPLEFT,
00148     DOWNRIGHT,
00149     DOWNLEFT,
00150     UNKNOWN
00151 };
00152 
00153 // structs
00154 struct vector_t {
00155     vector_t() {};
00156     float x;
00157     float y;
00158 };
00159 vector_t pos;  // player position
00160 vector_t vel;  // player velocity
00161 vector_t acc;  // player acceleration
00162 
00163 struct joystick {
00164     joystick() {};
00165     float x;    // current x value
00166     float x0;   // 'centred' x value
00167     float y;    // current y value
00168     float y0;   // 'centred' y value
00169     int button; // button selector (assume pull-down used, so 1 = pressed, 0 = unpressed)
00170     int bbutton;
00171     DirectionName direction;  // current direction
00172 };
00173 joystick joystick;
00174 
00175 /**
00176 Calibrates the joystick from it's initial position
00177 */
00178 void calibrate_joystick();
00179 /**
00180 Sets to up_flag to true
00181 */
00182 void update_flag_func();
00183 /**
00184 Sets the new values for the joystick struct variables
00185 */
00186 void update_joystick();
00187 /**
00188 Checks if the js_button has been held down
00189 @returns false if the button has already been registered as presed but is being held down else true
00190 */
00191 bool js_button_check();
00192 /**
00193 Checks if the b_button has been held down
00194 @returns false if the button has already been registered as presed but is being held down else true
00195 */
00196 bool b_button_check();
00197 /**
00198 Initialises the settings of on-board components for the K64F
00199 */
00200 void init_K64F();
00201 /**
00202 Initialises the settings of the N5110
00203 */
00204 void init_N5110();
00205 /**
00206 Initialises the objects with bitmaps
00207 */
00208 void init_obj();
00209 /**
00210 Runs the menu screen and allows for progression to further game functions
00211 */
00212 void menu();
00213 /**
00214 Runs the function as declared by the variable option set in th menu
00215 */
00216 void menu_select();
00217 /**
00218 Runs the game and calls all other functions relevant to the game
00219 */
00220 void start_game();
00221 /**
00222 Initialises all variables used in the game and sets the initial screen
00223 */
00224 void init_game();
00225 /**
00226 Initialises the players position and speed
00227 */
00228 void init_player();
00229 /**
00230 Sets the health animations in the HEALTH sub-array
00231 */
00232 void draw_health();
00233 /**
00234 Determines whether the player has collided with the spikes
00235 */
00236 void check_collisions();
00237 /**
00238 Updates the players position depending on the players current position, velocity and acceleration, all determined from SUVAT equations
00239 */
00240 void update_physics_engine();
00241 /**
00242 Updates the lcd to show the new game state
00243 */
00244 void redraw();
00245 /**
00246 Ends the game and shows the user their score when they run out of lives
00247 */
00248 void death();
00249 /**
00250 Displays the five highest scores and the name of the person who got the score
00251 */
00252 void highscores();
00253 /**
00254 Determines whether the latest score after death is higher than any current highscores and sets it accordingly
00255 */
00256 void new_highscore();
00257 /**
00258 Allows the user to resgister a name to accompany their new highscore
00259 */
00260 void register_name();
00261 /**
00262 Displays an overview of the games concept
00263 */
00264 void rules();
00265 /**
00266 Displays the details of the games creator
00267 */
00268 void credits();
00269 /**
00270 @namespace buzzer
00271 @brief GPIO output for music
00272 */
00273 speaker buzzer(PTA2);
00274 /**
00275 @namespace screen
00276 @brief A three dimensional array for allowing seperate sections of the two dimensional lcd
00277 */
00278 Screen screen;
00279 /**
00280 @namespace pointer_obj
00281 @brief Object for the pointer array
00282 */
00283 object pointer_obj(5,5);
00284 /**
00285 @namespace player_still_obj
00286 @brief Object for the player_still array
00287 */
00288 object player_still_obj(13,15);
00289 /**
00290 @namespace player_moving1_obj
00291 @brief Object for the player_moving1 array
00292 */
00293 object player_moving1_obj(13,15);
00294 /**
00295 @namespace player_moving2_obj
00296 @brief Object for the player_moving2 array
00297 */
00298 object player_moving2_obj(13,15);
00299 /**
00300 @namespace player_jumping_obj
00301 @brief Object for the player_jumping array
00302 */
00303 object player_jumping_obj(13,15);
00304 /**
00305 @namespace spike_small_obj1
00306 @brief Object for the spike_small array
00307 */
00308 object spike_small_obj1(5,5);
00309 /**
00310 @namespace spike_small_obj2
00311 @brief Object for the spike_small array
00312 */
00313 object spike_small_obj2(5,5);
00314 /**
00315 @namespace spike_small_obj3
00316 @brief Object for the spike_small array
00317 */
00318 object spike_small_obj3(5,5);
00319 /**
00320 @namespace spike_large_obj1
00321 @brief Object for the spike_large array
00322 */
00323 object spike_large_obj1(6,8);
00324 /**
00325 @namespace spike_large_obj2
00326 @brief Object for the spike_large array
00327 */
00328 object spike_large_obj2(6,8);
00329 /**
00330 @namespace player
00331 @brief Animation for the player_still array, player_moving1 array and player_moving2 array
00332 */
00333 animation player(13,15,player_still,player_moving1,player_moving2);
00334 /**
00335 @namespace bat1
00336 @brief Animation for the bat_middle array, bat_open array and bat_close array
00337 */
00338 animation bat1(13,7,bat_middle,bat_open,bat_close);
00339 /**
00340 @namespace bat2
00341 @brief Animation for the bat_middle array, bat_open array and bat_close array
00342 */
00343 animation bat2(13,7,bat_middle,bat_open,bat_close);
00344 /**
00345 @namespace bat3
00346 @brief Animation for the bat_middle array, bat_open array and bat_close array
00347 */
00348 animation bat3(13,7,bat_middle,bat_open,bat_close);
00349 /**
00350 @namespace bat4
00351 @brief Animation for the bat_middle array, bat_open array and bat_close array
00352 */
00353 animation bat4(13,7,bat_middle,bat_open,bat_close);
00354 /**
00355 @namespace bat5
00356 @brief Animation for the bat_middle array, bat_open array and bat_close array
00357 */
00358 animation bat5(13,7,bat_middle,bat_open,bat_close);
00359 /**
00360 @namespace background
00361 @brief Background to add scenery to the BG sub-array
00362 */
00363 Background background;
00364 
00365 #endif