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: N5110 mbed PowerControl
main.h
00001 /** 00002 @file main.h 00003 @brief Header file for main game containing function prototypes, namespaces and global variables. 00004 @autor Thomas Davies 00005 @date May 2015 00006 */ 00007 00008 #ifndef main_H 00009 #define main_H 00010 00011 #include "mbed.h" 00012 #include "GameScreen.h" 00013 #include "PowerControl/PowerControl.h" 00014 #include "PowerControl/EthernetPowerControl.h" 00015 00016 /** 00017 @namespace serial 00018 @brief serial communication with host 00019 */ 00020 Serial serial(USBTX,USBRX); 00021 00022 /** 00023 @namespace lcd 00024 @brief game screen controller 00025 */ 00026 GameScreen lcd(p7,p8,p9,p10,p11,p13,p21); 00027 00028 /** 00029 @namespace leds 00030 @brief Output for onboard LEDs 00031 */ 00032 BusOut leds(LED4,LED3,LED2,LED1); 00033 00034 /** 00035 @namespace joystickX 00036 @brief input from joystick X, on p15 00037 */ 00038 AnalogIn joystickX(p15); 00039 00040 /** 00041 @namespace joystickY 00042 @brief input from joystick Y, on p16 00043 */ 00044 AnalogIn joystickY(p16); 00045 00046 /** 00047 @namespace joystickButton 00048 @brief input from joystick button, on p17 00049 */ 00050 DigitalIn joystickButton(p17); 00051 00052 /** 00053 @namespace buzzer 00054 @brief digital output to buzzer on p5 00055 */ 00056 DigitalOut buzzer(p5); 00057 00058 /** 00059 @namespace local 00060 @brief local file system 00061 */ 00062 LocalFileSystem local("local"); 00063 00064 /** 00065 @namespace gameClock 00066 @brief the master clock of game operation. All animation timings are based on this clock. 00067 */ 00068 Ticker gameClock; 00069 00070 /** 00071 @namespace lowFlipper 00072 @brief used for PWM speaker control, triggers pin low. 00073 */ 00074 Timeout lowFlipper; 00075 00076 /** 00077 @namespace highFlipper 00078 @brief used for PWM speaker control, triggers pin high. 00079 */ 00080 Timeout highFlipper; 00081 00082 //##############GLOBAL VARIABLES##################// 00083 00084 int clockCount = 0; ///< master clock counter 00085 bool isFirstCheck = true; ///< first check in clock cycle? 00086 bool isFirstHit = true; ///< first hit on a platform? 00087 bool isFirstSpeedUp = true; ///< first game speed up? 00088 int gameLevel = 0; ///< current game level 00089 int gameSpeed = 41; ///< current game speed 00090 int numPixelsToJump = 1; ///< number of pixels ball/plat moves per animation 00091 int numPlatformShifts = 0; ///< number of times platforms shifted, used for score calculation 00092 int pwmCount = 1000; ///< pwm count for platform collision sound 00093 char isSound = 'Y'; ///< sound toggle, 'Y' for sound enabled. 00094 00095 //#############FUNCTION PROTOTYPES##################// 00096 00097 /** Reset Mbed */ 00098 extern "C" void mbed_reset(); 00099 00100 /** Advance Platforms 00101 * 00102 * animate platforms shift up n pixels 00103 * 00104 * @param n - number of pixels to shift 00105 */ 00106 void advancePlatforms(int n=1); 00107 00108 /** Check if ball falling 00109 * 00110 * Falling if bal is in free space, not on platform 00111 * @param bY - ball Y coordinate 00112 * @return 1 if falling 0 if not. 00113 */ 00114 bool isBallFalling(int bY); 00115 00116 /** Is Joystick Right? 00117 * 00118 * reads joystickX value and check direction 00119 *@returns 1 if right 0 if not. 00120 */ 00121 bool isRight(); 00122 00123 /** Is Joystick Left? 00124 * 00125 * reads joystickX value and check direction 00126 *@returns 1 if left 0 if not. 00127 */ 00128 bool isLeft(); 00129 00130 /** Is Joystick Up? 00131 * 00132 * reads joystickY value and check direction 00133 *@returns 1 if up 0 if not. 00134 */ 00135 bool isUp(); 00136 00137 /** Is Joystick Down? 00138 * 00139 * reads joystickY value and checks direction 00140 *@returns 1 if down 0 if not. 00141 */ 00142 bool isDown(); 00143 00144 /** ISR - Clock Counter 00145 * 00146 *increments number of clock cycles 00147 */ 00148 void clockCounter (); 00149 00150 /** Is Ball Direction Clear? 00151 * 00152 *given ball direction determines if path is clear to move. 00153 *@param dir - direction ball is travelling in (0 for left 1 for right) 00154 *@returns 1 if clear 0 if not 00155 */ 00156 bool isBallDirClear(int dir); 00157 00158 /** Game Over Controller 00159 * 00160 * Displays end game screen, and allows user interaction with options via joystick. 00161 * Also controls option selection and next screens. 00162 */ 00163 void endScreenController(); 00164 00165 /** Record Entry Controller 00166 * 00167 * Displays initial entry screen, allows user to scroll through letters and select initials. 00168 * @return intitials entered by user. 00169 */ 00170 char* recordEntryController(); 00171 00172 /** is Record? 00173 * 00174 * check if score achieved by player is a record 00175 * @return 1 if gameLevel is a record 0 if not 00176 */ 00177 bool isRecord (); 00178 00179 /** High Score Editor 00180 * 00181 * Manages highscore file and recordEntryController(). 00182 */ 00183 void highScoreEditor(char *playerInitials,bool isRecord); 00184 00185 /** Pause Screen Controller 00186 * 00187 * Displays pause screen and allows user interaction to toggle sound,restart, and resume game. 00188 */ 00189 void pauseScreenController(); 00190 00191 /** PWM speaker control function 00192 * 00193 * makes a boop sound used for collisions with platforms. 00194 */ 00195 void boop (); 00196 00197 /** Boop Helper function 00198 * 00199 * sets pin low when called, then starts timer to recall Boop(); 00200 */ 00201 void pwmLow(); 00202 00203 /** Power Saving Mode 00204 * 00205 * Powers down unused peripherals & ethernet 00206 */ 00207 void powerSave(); 00208 00209 00210 #endif 00211
Generated on Thu Jul 14 2022 20:38:02 by
1.7.2