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:
Mon May 11 20:33:45 2015 +0000
Revision:
12:3bf924a5f948
Parent:
11:d9d5bad8f5e2
Final Version of the Brick Breaker program

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