An implementation of the classic Brick Breaker game designed to be displayed on a N5110 LCD display and controlled with a 2 axis joystick and buttons.

Dependencies:   N5110 PinDetect PowerControl mbed

Committer:
el13cj
Date:
Thu May 07 18:01:40 2015 +0000
Revision:
9:8447ce6f51ae
Parent:
8:7889867308d3
Child:
11:d9d5bad8f5e2
FIXED ball strike-through error; INTERMITTENT fail to destroy brick, persistent menu on game start; TODO (if can) spkr, clear high scores, ball speed select

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el13cj 8:7889867308d3 1 /**
el13cj 9:8447ce6f51ae 2 * @file BrickBreaker.h
el13cj 9:8447ce6f51ae 3 *
el13cj 9:8447ce6f51ae 4 * @brief Header file containg function prototypes and variables
el13cj 9:8447ce6f51ae 5 * @brief Credits to Craig A. Evans for his implementation of the 2-axis Joystick.
el13cj 9:8447ce6f51ae 6 *
el13cj 8:7889867308d3 7 */
el13cj 8:7889867308d3 8
el13cj 8:7889867308d3 9
el13cj 8:7889867308d3 10 #include "mbed.h"
el13cj 8:7889867308d3 11 #include "N5110.h"
el13cj 8:7889867308d3 12 #include "PinDetect.h"
el13cj 8:7889867308d3 13 #include "PowerControl/PowerControl.h"
el13cj 8:7889867308d3 14 #include "PowerControl/EthernetPowerControl.h"
el13cj 8:7889867308d3 15
el13cj 8:7889867308d3 16 #define USR_POWERDOWN (0x104)
el13cj 8:7889867308d3 17
el13cj 8:7889867308d3 18 // change this to alter tolerance of joystick direction
el13cj 8:7889867308d3 19 #define DIRECTION_TOLERANCE 0.05
el13cj 8:7889867308d3 20
el13cj 8:7889867308d3 21 //included for power control
el13cj 8:7889867308d3 22 int semihost_powerdown() {
el13cj 8:7889867308d3 23
el13cj 8:7889867308d3 24 uint32_t arg;
el13cj 8:7889867308d3 25 return __semihost(USR_POWERDOWN, &arg);
el13cj 8:7889867308d3 26 }
el13cj 8:7889867308d3 27
el13cj 8:7889867308d3 28
el13cj 8:7889867308d3 29
el13cj 8:7889867308d3 30
el13cj 8:7889867308d3 31 // connections for joystick
el13cj 8:7889867308d3 32
el13cj 8:7889867308d3 33 /** Joystick Button
el13cj 8:7889867308d3 34 *
el13cj 8:7889867308d3 35 * Button for menu navigation and other controls. PinDetect was used to overcome the inherent debounce of the buttons
el13cj 8:7889867308d3 36 */
el13cj 8:7889867308d3 37 PinDetect button(p17);
el13cj 8:7889867308d3 38
el13cj 8:7889867308d3 39 /** Joystick x-axis
el13cj 8:7889867308d3 40 *
el13cj 8:7889867308d3 41 * Horizontal motion of the joystick, read as a potentiometer.
el13cj 8:7889867308d3 42 */
el13cj 8:7889867308d3 43 AnalogIn xPot(p15);
el13cj 8:7889867308d3 44
el13cj 8:7889867308d3 45 /** Joystick y-axis
el13cj 8:7889867308d3 46 *
el13cj 8:7889867308d3 47 * Veritcal motion of the joystick, read as a potentiometer.
el13cj 8:7889867308d3 48 */
el13cj 8:7889867308d3 49 AnalogIn yPot(p16);
el13cj 8:7889867308d3 50
el13cj 8:7889867308d3 51 //connections for other controls
el13cj 8:7889867308d3 52
el13cj 8:7889867308d3 53 /** Play/Pause
el13cj 8:7889867308d3 54 *
el13cj 8:7889867308d3 55 * Button to pause and resume the game. PinDetect was used to overcome the inherent debounce of the buttons
el13cj 8:7889867308d3 56 */
el13cj 8:7889867308d3 57 PinDetect playPause(p12);
el13cj 8:7889867308d3 58
el13cj 8:7889867308d3 59 /** Volume
el13cj 8:7889867308d3 60 *
el13cj 8:7889867308d3 61 * Potentiometer to control the volume of the buzzer
el13cj 8:7889867308d3 62 */
el13cj 8:7889867308d3 63 AnalogIn volPot(p20);
el13cj 8:7889867308d3 64
el13cj 8:7889867308d3 65 /** Noise Pin
el13cj 8:7889867308d3 66 *
el13cj 8:7889867308d3 67 * Pin to create noise for the randomisation of the levels
el13cj 8:7889867308d3 68 */
el13cj 8:7889867308d3 69 AnalogIn noise(p19);
el13cj 8:7889867308d3 70
el13cj 8:7889867308d3 71
el13cj 8:7889867308d3 72 /** Local File System
el13cj 8:7889867308d3 73 *
el13cj 8:7889867308d3 74 * Create Local filesystem to store the highscores
el13cj 8:7889867308d3 75 */
el13cj 8:7889867308d3 76
el13cj 8:7889867308d3 77 LocalFileSystem local("local");
el13cj 8:7889867308d3 78
el13cj 8:7889867308d3 79 /** Direction Name
el13cj 8:7889867308d3 80 *
el13cj 8:7889867308d3 81 * Enum type to store the names of the joystick directions
el13cj 8:7889867308d3 82 */
el13cj 8:7889867308d3 83 enum DirectionName {
el13cj 8:7889867308d3 84 UP,
el13cj 8:7889867308d3 85 DOWN,
el13cj 8:7889867308d3 86 LEFT,
el13cj 8:7889867308d3 87 RIGHT,
el13cj 8:7889867308d3 88 CENTRE,
el13cj 8:7889867308d3 89 UPLEFT,
el13cj 8:7889867308d3 90 UPRIGHT,
el13cj 8:7889867308d3 91 DOWNLEFT,
el13cj 8:7889867308d3 92 DOWNRIGHT,
el13cj 8:7889867308d3 93 UNKNOWN
el13cj 8:7889867308d3 94 };
el13cj 8:7889867308d3 95
el13cj 8:7889867308d3 96 /** Joystick
el13cj 8:7889867308d3 97 *
el13cj 8:7889867308d3 98 * Struct for the Joystick
el13cj 8:7889867308d3 99 */
el13cj 8:7889867308d3 100 typedef struct JoyStick Joystick;
el13cj 8:7889867308d3 101 struct JoyStick {
el13cj 8:7889867308d3 102 float x; // current x value
el13cj 8:7889867308d3 103 float x0; // 'centred' x value
el13cj 8:7889867308d3 104 float y; // current y value
el13cj 8:7889867308d3 105 float y0; // 'centred' y value
el13cj 8:7889867308d3 106 int button; // button state (assume pull-down used, so 1 = pressed, 0 = unpressed)
el13cj 8:7889867308d3 107 DirectionName direction; // current direction
el13cj 8:7889867308d3 108 };
el13cj 8:7889867308d3 109
el13cj 8:7889867308d3 110 Joystick joystick;
el13cj 8:7889867308d3 111
el13cj 8:7889867308d3 112 /** High Score 1
el13cj 8:7889867308d3 113 *
el13cj 8:7889867308d3 114 * Variable to store the highscores from the memory while the program is running.
el13cj 8:7889867308d3 115 * This is compared with the player's score at the end of the game and overwritten if necessary.
el13cj 8:7889867308d3 116 */
el13cj 8:7889867308d3 117 int highscore1;
el13cj 8:7889867308d3 118
el13cj 8:7889867308d3 119 /** High Score 2
el13cj 8:7889867308d3 120 *
el13cj 8:7889867308d3 121 * Variable to store the highscores from the memory while the program is running.
el13cj 8:7889867308d3 122 * This is compared with the player's score at the end of the game and overwritten if necessary.
el13cj 8:7889867308d3 123 */
el13cj 8:7889867308d3 124 int highscore2;
el13cj 8:7889867308d3 125
el13cj 8:7889867308d3 126 /** High Score 3
el13cj 8:7889867308d3 127 *
el13cj 8:7889867308d3 128 * Variable to store the highscores from the memory while the program is running.
el13cj 8:7889867308d3 129 * This is compared with the player's score at the end of the game and overwritten if necessary.
el13cj 8:7889867308d3 130 */
el13cj 8:7889867308d3 131 int highscore3;
el13cj 8:7889867308d3 132
el13cj 8:7889867308d3 133
el13cj 8:7889867308d3 134 /** Score Flag
el13cj 8:7889867308d3 135 *
el13cj 8:7889867308d3 136 * Set to 1 on initial conditions, set to 0 if a score overwrites a high score.
el13cj 8:7889867308d3 137 * This is to stop the same score from overwriting multiple entries in the high scores.
el13cj 8:7889867308d3 138 */
el13cj 8:7889867308d3 139 int scoreFlag = 1;
el13cj 8:7889867308d3 140
el13cj 8:7889867308d3 141 /** Ball x-Position
el13cj 8:7889867308d3 142 *
el13cj 8:7889867308d3 143 * Stores the x-Position of the ball for passing to lcd.drawRect()
el13cj 8:7889867308d3 144 */
el13cj 8:7889867308d3 145 int bx = 42;
el13cj 8:7889867308d3 146
el13cj 8:7889867308d3 147 /** Ball y-Position
el13cj 8:7889867308d3 148 *
el13cj 8:7889867308d3 149 * Stores the y-position of the ball for passing to lcd.drawRect()
el13cj 8:7889867308d3 150 */
el13cj 8:7889867308d3 151 int by = 30;
el13cj 8:7889867308d3 152
el13cj 8:7889867308d3 153 /** Ball Width
el13cj 8:7889867308d3 154 *
el13cj 8:7889867308d3 155 * Stores the width of the ball for passing to lcd.drawRect()
el13cj 8:7889867308d3 156 */
el13cj 8:7889867308d3 157 int bw = 1;
el13cj 8:7889867308d3 158
el13cj 8:7889867308d3 159 /** Ball Height
el13cj 8:7889867308d3 160 *
el13cj 8:7889867308d3 161 * Stores the Height of the ball for passing to lcd.drawRect()
el13cj 8:7889867308d3 162 */
el13cj 8:7889867308d3 163 int bh = 1;
el13cj 8:7889867308d3 164
el13cj 8:7889867308d3 165 /** Ball Fill
el13cj 8:7889867308d3 166 *
el13cj 8:7889867308d3 167 * Stores the Fill State of the ball for passing to lcd.drawRect()
el13cj 8:7889867308d3 168 */
el13cj 8:7889867308d3 169 int bf = 1;
el13cj 8:7889867308d3 170
el13cj 8:7889867308d3 171 /** Ball Direction
el13cj 8:7889867308d3 172 *
el13cj 8:7889867308d3 173 * Direction of the ball, quantised into 16 directions of motion
el13cj 8:7889867308d3 174 */
el13cj 8:7889867308d3 175 int d = 0;
el13cj 8:7889867308d3 176
el13cj 8:7889867308d3 177 /** Paddle x-Position
el13cj 8:7889867308d3 178 *
el13cj 8:7889867308d3 179 * Stores the x-Position of the paddle for passing to lcd.drawRect()
el13cj 8:7889867308d3 180 */
el13cj 8:7889867308d3 181 int px = 38;
el13cj 8:7889867308d3 182
el13cj 8:7889867308d3 183 /** Paddle y-Position
el13cj 8:7889867308d3 184 *
el13cj 8:7889867308d3 185 * Stores the y-position of the paddle for passing to lcd.drawRect()
el13cj 8:7889867308d3 186 */
el13cj 8:7889867308d3 187 int py = 40;
el13cj 8:7889867308d3 188
el13cj 8:7889867308d3 189 /** Paddle Width
el13cj 8:7889867308d3 190 *
el13cj 8:7889867308d3 191 * Stores the width of the paddle for passing to lcd.drawRect()
el13cj 8:7889867308d3 192 */
el13cj 8:7889867308d3 193 int pw = 8;
el13cj 8:7889867308d3 194
el13cj 8:7889867308d3 195 /** Paddle Height
el13cj 8:7889867308d3 196 *
el13cj 8:7889867308d3 197 * Stores the Height of the paddle for passing to lcd.drawRect()
el13cj 8:7889867308d3 198 */
el13cj 8:7889867308d3 199 int ph = 2;
el13cj 8:7889867308d3 200
el13cj 8:7889867308d3 201
el13cj 8:7889867308d3 202 /** Ball Surround
el13cj 8:7889867308d3 203 *
el13cj 8:7889867308d3 204 * Array to store the active pixels around the ball
el13cj 8:7889867308d3 205 */
el13cj 8:7889867308d3 206 int surround[12] = {};
el13cj 8:7889867308d3 207
el13cj 8:7889867308d3 208 /** Touch Flag
el13cj 8:7889867308d3 209 *
el13cj 8:7889867308d3 210 * Set when the ball touches any set pixel on the screen to flag it for setAngle()
el13cj 8:7889867308d3 211 */
el13cj 8:7889867308d3 212 int touchFlag = 0;
el13cj 8:7889867308d3 213
el13cj 8:7889867308d3 214 /** Bricks x-Coordinates
el13cj 8:7889867308d3 215 *
el13cj 8:7889867308d3 216 * Array to index the x-positions of the bricks
el13cj 8:7889867308d3 217 */
el13cj 8:7889867308d3 218 int bricksx[8] = {3, 12, 21, 30, 39, 48, 57, 66};
el13cj 8:7889867308d3 219
el13cj 8:7889867308d3 220 /** Bricks y-Coordinates
el13cj 8:7889867308d3 221 *
el13cj 8:7889867308d3 222 * Array to index the y-positions of the bricks
el13cj 8:7889867308d3 223 */
el13cj 8:7889867308d3 224 int bricksy[4] = {3, 8, 13, 18};
el13cj 8:7889867308d3 225
el13cj 8:7889867308d3 226 /** State of Bricks
el13cj 8:7889867308d3 227 *
el13cj 8:7889867308d3 228 * Array to index the state of the bricks: 1 is set, 0 is cleared
el13cj 8:7889867308d3 229 */
el13cj 8:7889867308d3 230 int bricks[4][8];
el13cj 8:7889867308d3 231
el13cj 8:7889867308d3 232 /** Display Menu
el13cj 8:7889867308d3 233 *
el13cj 8:7889867308d3 234 * Display the menu - for passing to the main() function
el13cj 8:7889867308d3 235 * One of several variables to control what is displayed on the screen
el13cj 8:7889867308d3 236 */
el13cj 8:7889867308d3 237 int displayMenu = 1;
el13cj 8:7889867308d3 238
el13cj 8:7889867308d3 239 /** Display Help
el13cj 8:7889867308d3 240 *
el13cj 8:7889867308d3 241 * Display the Help - for passing to the main() function
el13cj 8:7889867308d3 242 * One of several variables to control what is displayed on the screen
el13cj 8:7889867308d3 243 */
el13cj 8:7889867308d3 244 int displayHelp = 0;
el13cj 8:7889867308d3 245
el13cj 8:7889867308d3 246 /** Display High Scores
el13cj 8:7889867308d3 247 *
el13cj 8:7889867308d3 248 * Display the High Scores - for passing to the main() function
el13cj 8:7889867308d3 249 * One of several variables to control what is displayed on the screen
el13cj 8:7889867308d3 250 */
el13cj 8:7889867308d3 251 int displayHighScores = 0;
el13cj 8:7889867308d3 252
el13cj 8:7889867308d3 253 /** Display Game
el13cj 8:7889867308d3 254 *
el13cj 8:7889867308d3 255 * Display the Game - for passing to the main() function
el13cj 8:7889867308d3 256 * One of several variables to control what is displayed on the screen
el13cj 8:7889867308d3 257 */
el13cj 8:7889867308d3 258 int displayGame = 0;
el13cj 8:7889867308d3 259
el13cj 8:7889867308d3 260 /** Display Game Over
el13cj 8:7889867308d3 261 *
el13cj 8:7889867308d3 262 * Display the Game Over - for passing to the main() function
el13cj 8:7889867308d3 263 * One of several variables to control what is displayed on the screen
el13cj 8:7889867308d3 264 */
el13cj 8:7889867308d3 265 int displayGameOver = 0;
el13cj 8:7889867308d3 266
el13cj 8:7889867308d3 267 /** Menu Select
el13cj 8:7889867308d3 268 *
el13cj 8:7889867308d3 269 * Used to control the position of the cursor on the screen
el13cj 8:7889867308d3 270 */
el13cj 8:7889867308d3 271 int menuSelect = 1;
el13cj 8:7889867308d3 272
el13cj 8:7889867308d3 273 /** Help Screen
el13cj 8:7889867308d3 274 *
el13cj 8:7889867308d3 275 * Used to select which of the help pages to load
el13cj 8:7889867308d3 276 */
el13cj 8:7889867308d3 277 int helpScreen = 0;
el13cj 8:7889867308d3 278
el13cj 8:7889867308d3 279 /** Help Select
el13cj 8:7889867308d3 280 *
el13cj 8:7889867308d3 281 * Used to control the position of the cursor on the help screen
el13cj 8:7889867308d3 282 */
el13cj 8:7889867308d3 283 int helpSelect = 35;
el13cj 8:7889867308d3 284
el13cj 8:7889867308d3 285 /** Level
el13cj 8:7889867308d3 286 *
el13cj 8:7889867308d3 287 * Used to set the level - for passing to initBricks()
el13cj 8:7889867308d3 288 */
el13cj 8:7889867308d3 289 int level = 0;
el13cj 8:7889867308d3 290
el13cj 8:7889867308d3 291 /** Start/Stop
el13cj 8:7889867308d3 292 *
el13cj 8:7889867308d3 293 * Variable to determine whether the game is paused - 1 is start, 0 is stop.
el13cj 8:7889867308d3 294 */
el13cj 8:7889867308d3 295 int startStop = 1;
el13cj 8:7889867308d3 296
el13cj 8:7889867308d3 297 /** Lives
el13cj 8:7889867308d3 298 *
el13cj 8:7889867308d3 299 * Variable to store the remaining number of player lives
el13cj 8:7889867308d3 300 */
el13cj 8:7889867308d3 301 int lives = 3;
el13cj 8:7889867308d3 302
el13cj 8:7889867308d3 303 /** Score
el13cj 8:7889867308d3 304 *
el13cj 8:7889867308d3 305 * Variable to store the current player score
el13cj 8:7889867308d3 306 */
el13cj 8:7889867308d3 307 int score = 0;
el13cj 8:7889867308d3 308
el13cj 8:7889867308d3 309 /** Border Flag
el13cj 8:7889867308d3 310 *
el13cj 8:7889867308d3 311 * Set when the borders have been drawn to stop multiple attempts
el13cj 8:7889867308d3 312 */
el13cj 8:7889867308d3 313 int borderFlag = 0;
el13cj 8:7889867308d3 314
el13cj 8:7889867308d3 315 /** Brick Clear Flag
el13cj 8:7889867308d3 316 *
el13cj 8:7889867308d3 317 * Set to 1 for the bricks to be cleared, set to 0 once cleared to stop blank space from being repeatedly cleared
el13cj 8:7889867308d3 318 */
el13cj 8:7889867308d3 319 int clearFlag[4][8];
el13cj 8:7889867308d3 320
el13cj 8:7889867308d3 321 /** Brick Draw Flag
el13cj 8:7889867308d3 322 *
el13cj 8:7889867308d3 323 * Set to 1 for the bricks to be drawn, set to 0 once drawn to stop unnecessary overwriting
el13cj 8:7889867308d3 324 */
el13cj 8:7889867308d3 325 int brickDrawFlag[4][8];
el13cj 8:7889867308d3 326
el13cj 8:7889867308d3 327 /** Poll Joystick
el13cj 8:7889867308d3 328 *
el13cj 8:7889867308d3 329 * Timer to regularly update the game joystick values
el13cj 8:7889867308d3 330 */
el13cj 8:7889867308d3 331 Ticker pollJoystick;
el13cj 8:7889867308d3 332
el13cj 8:7889867308d3 333 /** Move Paddle
el13cj 8:7889867308d3 334 *
el13cj 8:7889867308d3 335 * Timer to regularly move the paddle
el13cj 8:7889867308d3 336 */
el13cj 8:7889867308d3 337 Ticker movePaddle;
el13cj 8:7889867308d3 338
el13cj 8:7889867308d3 339 /** Select
el13cj 8:7889867308d3 340 *
el13cj 8:7889867308d3 341 * Timer to update the cursor throughout the game menus
el13cj 8:7889867308d3 342 */
el13cj 8:7889867308d3 343 Ticker select;
el13cj 8:7889867308d3 344
el13cj 8:7889867308d3 345 /** Read High Scores
el13cj 8:7889867308d3 346 *
el13cj 8:7889867308d3 347 * Reads the current values of the high scores from the internal memory
el13cj 8:7889867308d3 348 */
el13cj 8:7889867308d3 349 void readHighScores();
el13cj 8:7889867308d3 350
el13cj 8:7889867308d3 351 /** Write High Scores
el13cj 8:7889867308d3 352 *
el13cj 8:7889867308d3 353 * Writes the updated values of the high scores to the internal memory
el13cj 8:7889867308d3 354 */
el13cj 8:7889867308d3 355 void writeHighScores();
el13cj 8:7889867308d3 356
el13cj 8:7889867308d3 357
el13cj 8:7889867308d3 358 /** Initialise the Bricks
el13cj 8:7889867308d3 359 *
el13cj 8:7889867308d3 360 * Populate the array storing the state of the bricks for drawing
el13cj 8:7889867308d3 361 *
el13cj 8:7889867308d3 362 * @param l - The game level to be initialised. Predefined when l<2 and random afterwards.
el13cj 8:7889867308d3 363 */
el13cj 8:7889867308d3 364 void initBricks(int l);
el13cj 8:7889867308d3 365
el13cj 8:7889867308d3 366 /** Do the Bricks
el13cj 8:7889867308d3 367 *
el13cj 8:7889867308d3 368 * Does getBrickTouch() on all bricks, draws any that are set to be drawn and clears any that are set to be cleared
el13cj 8:7889867308d3 369 */
el13cj 8:7889867308d3 370 void doBricks();
el13cj 8:7889867308d3 371
el13cj 8:7889867308d3 372 /** Get Brick Touch
el13cj 8:7889867308d3 373 *
el13cj 8:7889867308d3 374 * Checks to see if any of the pixels surrounding a given brick are set - i.e. if something is touching one
el13cj 8:7889867308d3 375 *
el13cj 8:7889867308d3 376 * @param x - the horizontal index of the brick check
el13cj 8:7889867308d3 377 * @param y - the vertical index of the brick to check
el13cj 8:7889867308d3 378 */
el13cj 8:7889867308d3 379 void getBrickTouch(int x, int y);
el13cj 8:7889867308d3 380
el13cj 8:7889867308d3 381 /** Clear Bricks
el13cj 8:7889867308d3 382 *
el13cj 8:7889867308d3 383 * Loops through all bricks and clears any that are set to be cleared
el13cj 8:7889867308d3 384 */
el13cj 8:7889867308d3 385 void clearBricks();
el13cj 8:7889867308d3 386
el13cj 8:7889867308d3 387 /** Calibrate Joystick
el13cj 8:7889867308d3 388 *
el13cj 8:7889867308d3 389 * Initialises the built in button in the joystick in PullUp mode. Also reads the initial values of the
el13cj 8:7889867308d3 390 * joystick for reference.
el13cj 8:7889867308d3 391 */
el13cj 8:7889867308d3 392 void calibrateJoystick();
el13cj 8:7889867308d3 393
el13cj 8:7889867308d3 394 /** Update Joystick
el13cj 8:7889867308d3 395 *
el13cj 8:7889867308d3 396 * Checks the x and y values of the potentiometers and assigns the joystick a direction based on that.
el13cj 8:7889867308d3 397 */
el13cj 8:7889867308d3 398 void updateJoystick();
el13cj 8:7889867308d3 399
el13cj 8:7889867308d3 400 /** Menu
el13cj 8:7889867308d3 401 *
el13cj 8:7889867308d3 402 * Displays the menu screen and moves the cursor to the current position
el13cj 8:7889867308d3 403 */
el13cj 8:7889867308d3 404 void menu();
el13cj 8:7889867308d3 405
el13cj 8:7889867308d3 406 /** Get Menu Select
el13cj 8:7889867308d3 407 *
el13cj 8:7889867308d3 408 * Checks the joystick direction and assigns the cursor a new position based on that
el13cj 8:7889867308d3 409 */
el13cj 8:7889867308d3 410 void getMenuSelect();
el13cj 8:7889867308d3 411
el13cj 8:7889867308d3 412 /** New Screen
el13cj 8:7889867308d3 413 *
el13cj 8:7889867308d3 414 * Called on a click of the joystick from the menu, changes the information displayed on the screen.
el13cj 8:7889867308d3 415 * Depends on the position of the cursor
el13cj 8:7889867308d3 416 */
el13cj 8:7889867308d3 417 void newScreen();
el13cj 8:7889867308d3 418
el13cj 8:7889867308d3 419 /** Help
el13cj 8:7889867308d3 420 *
el13cj 8:7889867308d3 421 * Displays the various pages of help available, moves the cursor to the current position
el13cj 8:7889867308d3 422 */
el13cj 8:7889867308d3 423 void help();
el13cj 8:7889867308d3 424
el13cj 8:7889867308d3 425 /** High Scores
el13cj 8:7889867308d3 426 *
el13cj 8:7889867308d3 427 * Pulls the high score data from the internal memory and displays them on the screen
el13cj 8:7889867308d3 428 */
el13cj 8:7889867308d3 429 void highScores();
el13cj 8:7889867308d3 430
el13cj 8:7889867308d3 431 /** Game
el13cj 8:7889867308d3 432 *
el13cj 8:7889867308d3 433 * Pulls together various other functions to run the game
el13cj 8:7889867308d3 434 *
el13cj 8:7889867308d3 435 * @param g - If true, game runs. If false, game stops. Used to pause the game
el13cj 8:7889867308d3 436 */
el13cj 8:7889867308d3 437 void game(int g);
el13cj 8:7889867308d3 438
el13cj 8:7889867308d3 439 /** Ball
el13cj 8:7889867308d3 440 *
el13cj 8:7889867308d3 441 * @brief Move the ball
el13cj 8:7889867308d3 442 *
el13cj 8:7889867308d3 443 * 2-step movement for the ball - combines moveBall1() and moveBall2() with setAngle() and doBricks() to ensure game updates properly.
el13cj 8:7889867308d3 444 *
el13cj 8:7889867308d3 445 * NB: wait() functions were included to slow down the motion of the ball to a reasonable speed. A timer would have been preferable but the game
el13cj 8:7889867308d3 446 * ceased to function if this implementation was used.
el13cj 8:7889867308d3 447 */
el13cj 8:7889867308d3 448 void ball();
el13cj 8:7889867308d3 449
el13cj 8:7889867308d3 450 /** Paddle
el13cj 8:7889867308d3 451 *
el13cj 8:7889867308d3 452 * @brief Move the paddle left and right
el13cj 8:7889867308d3 453 *
el13cj 8:7889867308d3 454 * Checks the position of the joystick and updates the postion of the paddle based on that.
el13cj 8:7889867308d3 455 *
el13cj 8:7889867308d3 456 * NB: The entire row is cleared when in theory only the prior position should need to be. In practise this does not work and the row does not
el13cj 8:7889867308d3 457 * properly cleared.
el13cj 8:7889867308d3 458 */
el13cj 8:7889867308d3 459 void paddle();
el13cj 8:7889867308d3 460
el13cj 8:7889867308d3 461 /** Get Number of Bricks
el13cj 8:7889867308d3 462 *
el13cj 8:7889867308d3 463 * @return - Number of remaining bricks
el13cj 8:7889867308d3 464 *
el13cj 8:7889867308d3 465 * Finds the number of bricks remaining on the screen
el13cj 8:7889867308d3 466 */
el13cj 8:7889867308d3 467 int getNumBricks();
el13cj 8:7889867308d3 468
el13cj 8:7889867308d3 469 /** New Level
el13cj 8:7889867308d3 470 *
el13cj 8:7889867308d3 471 * @brief Updates the level and redraws the bricks
el13cj 8:7889867308d3 472 *
el13cj 8:7889867308d3 473 * Called when getNumBricks() returns 0
el13cj 8:7889867308d3 474 */
el13cj 8:7889867308d3 475 void newLevel();
el13cj 8:7889867308d3 476
el13cj 8:7889867308d3 477 /** Pause
el13cj 8:7889867308d3 478 *
el13cj 8:7889867308d3 479 * Reverses the value of StartStop to Pause/Unpause the game
el13cj 8:7889867308d3 480 */
el13cj 8:7889867308d3 481 void pause();
el13cj 8:7889867308d3 482
el13cj 8:7889867308d3 483 /** Move Ball (1)
el13cj 8:7889867308d3 484 *
el13cj 8:7889867308d3 485 * First iteration of ball motion
el13cj 8:7889867308d3 486 *
el13cj 8:7889867308d3 487 * @param d - The direction to move the ball in - quantised into 16 separate directions
el13cj 8:7889867308d3 488 */
el13cj 8:7889867308d3 489 void moveBall1(int d);
el13cj 8:7889867308d3 490
el13cj 8:7889867308d3 491 /** Move Ball (2)
el13cj 8:7889867308d3 492 *
el13cj 8:7889867308d3 493 * Second iteration of ball motion
el13cj 8:7889867308d3 494 *
el13cj 8:7889867308d3 495 * @param d - The direction to move the ball in - quantised into 16 separate directions
el13cj 8:7889867308d3 496 */
el13cj 8:7889867308d3 497 void moveBall2(int d);
el13cj 8:7889867308d3 498
el13cj 8:7889867308d3 499 /** Initialise the Borders
el13cj 8:7889867308d3 500 *
el13cj 8:7889867308d3 501 * Draws the boundaries so that the ball cannot leave the screen through the sides or top.
el13cj 8:7889867308d3 502 * Also draws some graphics for containing the scores and remaining lives.
el13cj 8:7889867308d3 503 */
el13cj 8:7889867308d3 504 void borderInit();
el13cj 8:7889867308d3 505
el13cj 8:7889867308d3 506 /** Get Ball Touch Flag
el13cj 8:7889867308d3 507 *
el13cj 8:7889867308d3 508 * Check to see if the ball is touching anything
el13cj 8:7889867308d3 509 */
el13cj 8:7889867308d3 510 void getTouchFlag();
el13cj 8:7889867308d3 511
el13cj 8:7889867308d3 512 /** Set Ball Angle
el13cj 8:7889867308d3 513 *
el13cj 8:7889867308d3 514 * @return d The direction that the ball is to move in
el13cj 8:7889867308d3 515 *
el13cj 8:7889867308d3 516 * Set the new direction of the ball based on what the edges of the ball are touching and the current angle of the ball
el13cj 8:7889867308d3 517 */
el13cj 8:7889867308d3 518 int setAngle();
el13cj 8:7889867308d3 519
el13cj 8:7889867308d3 520 /** Displays Score
el13cj 8:7889867308d3 521 *
el13cj 8:7889867308d3 522 * Displays the current score on the screen. The score is displayed vertical but the score is often multiple
el13cj 8:7889867308d3 523 * digits so modulus was used to split up the digits.
el13cj 8:7889867308d3 524 */
el13cj 8:7889867308d3 525 void dispScore();
el13cj 8:7889867308d3 526
el13cj 8:7889867308d3 527
el13cj 8:7889867308d3 528 /** Display Lives
el13cj 8:7889867308d3 529 *
el13cj 8:7889867308d3 530 * Displays the current number of remaining lives on the screen
el13cj 8:7889867308d3 531 */
el13cj 8:7889867308d3 532 void dispLives();
el13cj 8:7889867308d3 533
el13cj 8:7889867308d3 534 /** Lost Life
el13cj 8:7889867308d3 535 *
el13cj 8:7889867308d3 536 * @return 1 - If a life is lost. I think this was for debugging CHECK THIS LATER
el13cj 8:7889867308d3 537 */
el13cj 8:7889867308d3 538 int lifeLost();
el13cj 8:7889867308d3 539
el13cj 8:7889867308d3 540 /** Game Over
el13cj 8:7889867308d3 541 *
el13cj 8:7889867308d3 542 * Displays the dreaded Game Over screen. If the score is greater than any of the high scores they will be updated accordingly and the player informed.
el13cj 8:7889867308d3 543 */
el13cj 9:8447ce6f51ae 544 void gameOver();