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@14:f5760f76fe83, 2015-05-01 (annotated)
- Committer:
 - AppleJuice
 - Date:
 - Fri May 01 16:17:27 2015 +0000
 - Revision:
 - 14:f5760f76fe83
 - Child:
 - 18:0e8b1cc24706
 
commented all files using Doxygen;
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| AppleJuice | 14:f5760f76fe83 | 1 | /** | 
| AppleJuice | 14:f5760f76fe83 | 2 | @file main.h | 
| AppleJuice | 14:f5760f76fe83 | 3 | @brief Header file for main game containing function prototypes, namespaces and global variables. | 
| AppleJuice | 14:f5760f76fe83 | 4 | @autor Thomas Davies | 
| AppleJuice | 14:f5760f76fe83 | 5 | @date May 2015 | 
| AppleJuice | 14:f5760f76fe83 | 6 | */ | 
| AppleJuice | 14:f5760f76fe83 | 7 | |
| AppleJuice | 14:f5760f76fe83 | 8 | #ifndef main_H | 
| AppleJuice | 14:f5760f76fe83 | 9 | #define main_H | 
| AppleJuice | 14:f5760f76fe83 | 10 | |
| AppleJuice | 14:f5760f76fe83 | 11 | #include "mbed.h" | 
| AppleJuice | 14:f5760f76fe83 | 12 | #include "GameScreen.h" | 
| AppleJuice | 14:f5760f76fe83 | 13 | |
| AppleJuice | 14:f5760f76fe83 | 14 | /** | 
| AppleJuice | 14:f5760f76fe83 | 15 | @namespace serial | 
| AppleJuice | 14:f5760f76fe83 | 16 | @brief serial communication with host | 
| AppleJuice | 14:f5760f76fe83 | 17 | */ | 
| AppleJuice | 14:f5760f76fe83 | 18 | Serial serial(USBTX,USBRX); | 
| AppleJuice | 14:f5760f76fe83 | 19 | |
| AppleJuice | 14:f5760f76fe83 | 20 | /** | 
| AppleJuice | 14:f5760f76fe83 | 21 | @namespace lcd | 
| AppleJuice | 14:f5760f76fe83 | 22 | @brief game screen controller | 
| AppleJuice | 14:f5760f76fe83 | 23 | */ | 
| AppleJuice | 14:f5760f76fe83 | 24 | GameScreen lcd(p7,p8,p9,p10,p11,p13,p21); | 
| AppleJuice | 14:f5760f76fe83 | 25 | |
| AppleJuice | 14:f5760f76fe83 | 26 | /** | 
| AppleJuice | 14:f5760f76fe83 | 27 | @namespace leds | 
| AppleJuice | 14:f5760f76fe83 | 28 | @brief Output for onboard LEDs | 
| AppleJuice | 14:f5760f76fe83 | 29 | */ | 
| AppleJuice | 14:f5760f76fe83 | 30 | BusOut leds(LED4,LED3,LED2,LED1); | 
| AppleJuice | 14:f5760f76fe83 | 31 | |
| AppleJuice | 14:f5760f76fe83 | 32 | /** | 
| AppleJuice | 14:f5760f76fe83 | 33 | @namespace joystickX | 
| AppleJuice | 14:f5760f76fe83 | 34 | @brief input from joystick X, on p15 | 
| AppleJuice | 14:f5760f76fe83 | 35 | */ | 
| AppleJuice | 14:f5760f76fe83 | 36 | AnalogIn joystickX(p15); | 
| AppleJuice | 14:f5760f76fe83 | 37 | |
| AppleJuice | 14:f5760f76fe83 | 38 | /** | 
| AppleJuice | 14:f5760f76fe83 | 39 | @namespace joystickY | 
| AppleJuice | 14:f5760f76fe83 | 40 | @brief input from joystick Y, on p16 | 
| AppleJuice | 14:f5760f76fe83 | 41 | */ | 
| AppleJuice | 14:f5760f76fe83 | 42 | AnalogIn joystickY(p16); | 
| AppleJuice | 14:f5760f76fe83 | 43 | |
| AppleJuice | 14:f5760f76fe83 | 44 | /** | 
| AppleJuice | 14:f5760f76fe83 | 45 | @namespace joystickButton | 
| AppleJuice | 14:f5760f76fe83 | 46 | @brief input from joystick button, on p17 | 
| AppleJuice | 14:f5760f76fe83 | 47 | */ | 
| AppleJuice | 14:f5760f76fe83 | 48 | DigitalIn joystickButton(p17); | 
| AppleJuice | 14:f5760f76fe83 | 49 | |
| AppleJuice | 14:f5760f76fe83 | 50 | /** | 
| AppleJuice | 14:f5760f76fe83 | 51 | @namespace buzzer | 
| AppleJuice | 14:f5760f76fe83 | 52 | @brief digital output to buzzer on p5 | 
| AppleJuice | 14:f5760f76fe83 | 53 | */ | 
| AppleJuice | 14:f5760f76fe83 | 54 | DigitalOut buzzer(p5); | 
| AppleJuice | 14:f5760f76fe83 | 55 | |
| AppleJuice | 14:f5760f76fe83 | 56 | /** | 
| AppleJuice | 14:f5760f76fe83 | 57 | @namespace local | 
| AppleJuice | 14:f5760f76fe83 | 58 | @brief local file system | 
| AppleJuice | 14:f5760f76fe83 | 59 | */ | 
| AppleJuice | 14:f5760f76fe83 | 60 | LocalFileSystem local("local"); | 
| AppleJuice | 14:f5760f76fe83 | 61 | |
| AppleJuice | 14:f5760f76fe83 | 62 | /** | 
| AppleJuice | 14:f5760f76fe83 | 63 | @namespace gameClock | 
| AppleJuice | 14:f5760f76fe83 | 64 | @brief the master clock of game operation. All animation timings are based on this clock. | 
| AppleJuice | 14:f5760f76fe83 | 65 | */ | 
| AppleJuice | 14:f5760f76fe83 | 66 | Ticker gameClock; | 
| AppleJuice | 14:f5760f76fe83 | 67 | |
| AppleJuice | 14:f5760f76fe83 | 68 | //##############GLOBAL VARIABLES##################// | 
| AppleJuice | 14:f5760f76fe83 | 69 | |
| AppleJuice | 14:f5760f76fe83 | 70 | int clockCount = 0; ///< master clock counter | 
| AppleJuice | 14:f5760f76fe83 | 71 | bool isFirstCheck = true; ///< first check in clock cycle? | 
| AppleJuice | 14:f5760f76fe83 | 72 | bool isFirstHit = true; ///< first hit on a platform? | 
| AppleJuice | 14:f5760f76fe83 | 73 | int gameLevel = 1; ///< current game level | 
| AppleJuice | 14:f5760f76fe83 | 74 | int gameSpeed = 50; ///< current game speed | 
| AppleJuice | 14:f5760f76fe83 | 75 | |
| AppleJuice | 14:f5760f76fe83 | 76 | //#############FUNCTION PROTOTYPES##################// | 
| AppleJuice | 14:f5760f76fe83 | 77 | |
| AppleJuice | 14:f5760f76fe83 | 78 | /** Reset Mbed */ | 
| AppleJuice | 14:f5760f76fe83 | 79 | extern "C" void mbed_reset(); | 
| AppleJuice | 14:f5760f76fe83 | 80 | |
| AppleJuice | 14:f5760f76fe83 | 81 | /** Advance Platforms | 
| AppleJuice | 14:f5760f76fe83 | 82 | * | 
| AppleJuice | 14:f5760f76fe83 | 83 | * animate platforms shift up n pixels | 
| AppleJuice | 14:f5760f76fe83 | 84 | * | 
| AppleJuice | 14:f5760f76fe83 | 85 | * @param n - number of pixels to shift | 
| AppleJuice | 14:f5760f76fe83 | 86 | */ | 
| AppleJuice | 14:f5760f76fe83 | 87 | void advancePlatforms(int n=1); | 
| AppleJuice | 14:f5760f76fe83 | 88 | |
| AppleJuice | 14:f5760f76fe83 | 89 | /** Check if ball falling | 
| AppleJuice | 14:f5760f76fe83 | 90 | * | 
| AppleJuice | 14:f5760f76fe83 | 91 | * Falling if bal is in free space, not on platform | 
| AppleJuice | 14:f5760f76fe83 | 92 | * @param bY - ball Y coordinate | 
| AppleJuice | 14:f5760f76fe83 | 93 | * @return 1 if falling 0 if not. | 
| AppleJuice | 14:f5760f76fe83 | 94 | */ | 
| AppleJuice | 14:f5760f76fe83 | 95 | bool isBallFalling(int bY); | 
| AppleJuice | 14:f5760f76fe83 | 96 | |
| AppleJuice | 14:f5760f76fe83 | 97 | /** Is Joystick Right? | 
| AppleJuice | 14:f5760f76fe83 | 98 | * | 
| AppleJuice | 14:f5760f76fe83 | 99 | * reads joystickX value and check direction | 
| AppleJuice | 14:f5760f76fe83 | 100 | *@returns 1 if right 0 if not. | 
| AppleJuice | 14:f5760f76fe83 | 101 | */ | 
| AppleJuice | 14:f5760f76fe83 | 102 | bool isRight(); | 
| AppleJuice | 14:f5760f76fe83 | 103 | |
| AppleJuice | 14:f5760f76fe83 | 104 | /** Is Joystick Left? | 
| AppleJuice | 14:f5760f76fe83 | 105 | * | 
| AppleJuice | 14:f5760f76fe83 | 106 | * reads joystickX value and check direction | 
| AppleJuice | 14:f5760f76fe83 | 107 | *@returns 1 if left 0 if not. | 
| AppleJuice | 14:f5760f76fe83 | 108 | */ | 
| AppleJuice | 14:f5760f76fe83 | 109 | bool isLeft(); | 
| AppleJuice | 14:f5760f76fe83 | 110 | |
| AppleJuice | 14:f5760f76fe83 | 111 | /** Is Joystick Up? | 
| AppleJuice | 14:f5760f76fe83 | 112 | * | 
| AppleJuice | 14:f5760f76fe83 | 113 | * reads joystickY value and check direction | 
| AppleJuice | 14:f5760f76fe83 | 114 | *@returns 1 if up 0 if not. | 
| AppleJuice | 14:f5760f76fe83 | 115 | */ | 
| AppleJuice | 14:f5760f76fe83 | 116 | bool isUp(); | 
| AppleJuice | 14:f5760f76fe83 | 117 | |
| AppleJuice | 14:f5760f76fe83 | 118 | /** Is Joystick Down? | 
| AppleJuice | 14:f5760f76fe83 | 119 | * | 
| AppleJuice | 14:f5760f76fe83 | 120 | * reads joystickY value and checks direction | 
| AppleJuice | 14:f5760f76fe83 | 121 | *@returns 1 if down 0 if not. | 
| AppleJuice | 14:f5760f76fe83 | 122 | */ | 
| AppleJuice | 14:f5760f76fe83 | 123 | bool isDown(); | 
| AppleJuice | 14:f5760f76fe83 | 124 | |
| AppleJuice | 14:f5760f76fe83 | 125 | /** ISR - Clock Counter | 
| AppleJuice | 14:f5760f76fe83 | 126 | * | 
| AppleJuice | 14:f5760f76fe83 | 127 | *increments number of clock cycles | 
| AppleJuice | 14:f5760f76fe83 | 128 | */ | 
| AppleJuice | 14:f5760f76fe83 | 129 | void clockCounter (); | 
| AppleJuice | 14:f5760f76fe83 | 130 | |
| AppleJuice | 14:f5760f76fe83 | 131 | /** Is Ball Direction Clear? | 
| AppleJuice | 14:f5760f76fe83 | 132 | * | 
| AppleJuice | 14:f5760f76fe83 | 133 | *given ball direction determines if path is clear to move. | 
| AppleJuice | 14:f5760f76fe83 | 134 | *@param dir - direction ball is travelling in (0 for left 1 for right) | 
| AppleJuice | 14:f5760f76fe83 | 135 | *@returns 1 if clear 0 if not | 
| AppleJuice | 14:f5760f76fe83 | 136 | */ | 
| AppleJuice | 14:f5760f76fe83 | 137 | bool isBallDirClear(int dir); | 
| AppleJuice | 14:f5760f76fe83 | 138 | |
| AppleJuice | 14:f5760f76fe83 | 139 | /** Game Over Controller | 
| AppleJuice | 14:f5760f76fe83 | 140 | * | 
| AppleJuice | 14:f5760f76fe83 | 141 | * Displays end game screen, and allows user interaction with options via joystick. | 
| AppleJuice | 14:f5760f76fe83 | 142 | * Also controls option selection and next screens. | 
| AppleJuice | 14:f5760f76fe83 | 143 | */ | 
| AppleJuice | 14:f5760f76fe83 | 144 | void endScreenController(); | 
| AppleJuice | 14:f5760f76fe83 | 145 | |
| AppleJuice | 14:f5760f76fe83 | 146 | /** Record Entry Controller | 
| AppleJuice | 14:f5760f76fe83 | 147 | * | 
| AppleJuice | 14:f5760f76fe83 | 148 | * Displays initial entry screen, allows user to scroll through letters and select initials. | 
| AppleJuice | 14:f5760f76fe83 | 149 | * @return intitials entered by user. | 
| AppleJuice | 14:f5760f76fe83 | 150 | */ | 
| AppleJuice | 14:f5760f76fe83 | 151 | char* recordEntryController(); | 
| AppleJuice | 14:f5760f76fe83 | 152 | |
| AppleJuice | 14:f5760f76fe83 | 153 | /** is Record? | 
| AppleJuice | 14:f5760f76fe83 | 154 | * | 
| AppleJuice | 14:f5760f76fe83 | 155 | * check if score achieved by player is a record | 
| AppleJuice | 14:f5760f76fe83 | 156 | * @return 1 if gameLevel is a record 0 if not | 
| AppleJuice | 14:f5760f76fe83 | 157 | */ | 
| AppleJuice | 14:f5760f76fe83 | 158 | bool isRecord (); | 
| AppleJuice | 14:f5760f76fe83 | 159 | |
| AppleJuice | 14:f5760f76fe83 | 160 | /** High Score Editor | 
| AppleJuice | 14:f5760f76fe83 | 161 | * | 
| AppleJuice | 14:f5760f76fe83 | 162 | * Manages highscore file and recordEntryController(). | 
| AppleJuice | 14:f5760f76fe83 | 163 | */ | 
| AppleJuice | 14:f5760f76fe83 | 164 | void highScoreEditor(char *playerInitials,bool isRecord); | 
| AppleJuice | 14:f5760f76fe83 | 165 | |
| AppleJuice | 14:f5760f76fe83 | 166 | |
| AppleJuice | 14:f5760f76fe83 | 167 | #endif | 
| AppleJuice | 14:f5760f76fe83 | 168 |