Code for the space evader game.

Dependencies:   N5110 PowerControl mbed

Committer:
domplatypus
Date:
Sun May 10 16:48:46 2015 +0000
Revision:
0:dd6685f1343e
Child:
1:225522d0dd77
version 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
domplatypus 0:dd6685f1343e 1 /**
domplatypus 0:dd6685f1343e 2 @file main.h
domplatypus 0:dd6685f1343e 3 @brief Header file containing functions prototypes, defines and global variables.
domplatypus 0:dd6685f1343e 4 @brief Main code for the running of the game with external libraries of the joystick and the lcd screen
domplatypus 0:dd6685f1343e 5 @author Dominic J. Platt
domplatypus 0:dd6685f1343e 6 @date April 2015
domplatypus 0:dd6685f1343e 7 */
domplatypus 0:dd6685f1343e 8
domplatypus 0:dd6685f1343e 9 #include "mbed.h"
domplatypus 0:dd6685f1343e 10 #include "N5110.h" //importing Craig Evans library for LCD pixel manipulation functions
domplatypus 0:dd6685f1343e 11 #include "joystick.h" //external joystick files defined for simplification within the main file
domplatypus 0:dd6685f1343e 12 //external variables printFlag,joystick,pollJoystick,serial and button used
domplatypus 0:dd6685f1343e 13 //button(p18),xPot(p19),yPot(p20) used with external joystick
domplatypus 0:dd6685f1343e 14 #include "PowerControl/PowerControl.h"
domplatypus 0:dd6685f1343e 15 #include "PowerControl/EthernetPowerControl.h" // power control header files
domplatypus 0:dd6685f1343e 16
domplatypus 0:dd6685f1343e 17 LocalFileSystem local("local"); // create local filesystem
domplatypus 0:dd6685f1343e 18 /**
domplatypus 0:dd6685f1343e 19 @namespace serialTime
domplatypus 0:dd6685f1343e 20 @brief serial data used to declare the program to set the time
domplatypus 0:dd6685f1343e 21 */
domplatypus 0:dd6685f1343e 22 Serial serialTime (USBTX,USBRX);
domplatypus 0:dd6685f1343e 23 /**
domplatypus 0:dd6685f1343e 24 @brief Initialises the programs variables, the joystick initialisation and calibration, the LCD initialisation, button interrupts, serial interrupts, seeds the rand() function from time and sets the lcd brightness
domplatypus 0:dd6685f1343e 25 */
domplatypus 0:dd6685f1343e 26 void init();
domplatypus 0:dd6685f1343e 27 /**
domplatypus 0:dd6685f1343e 28 @namespace buzzer
domplatypus 0:dd6685f1343e 29 @brief pwm output to control the piezo buzzer
domplatypus 0:dd6685f1343e 30 */
domplatypus 0:dd6685f1343e 31 PwmOut buzzer(p21);
domplatypus 0:dd6685f1343e 32 //! an array of different frequencies for control of the buzzer
domplatypus 0:dd6685f1343e 33 float frequency[20] = {50,100,150,200,250,300,350,400,450,500,550,600,650,700,750,800,900,950,1000,1050};;
domplatypus 0:dd6685f1343e 34 //!declares whether sound is turned on
domplatypus 0:dd6685f1343e 35 bool soundOn;
domplatypus 0:dd6685f1343e 36 //! how many 'frames' the sound has been active for
domplatypus 0:dd6685f1343e 37 int soundCounter;
domplatypus 0:dd6685f1343e 38 //!Declares the sound type played through the pwm
domplatypus 0:dd6685f1343e 39 int soundType;
domplatypus 0:dd6685f1343e 40 //!declares whether sound is active
domplatypus 0:dd6685f1343e 41 bool sound =1;
domplatypus 0:dd6685f1343e 42 /**
domplatypus 0:dd6685f1343e 43 @brief Activates the PWM for the buzzer and sets sound to be on
domplatypus 0:dd6685f1343e 44 */
domplatypus 0:dd6685f1343e 45 void initSound();
domplatypus 0:dd6685f1343e 46 /**
domplatypus 0:dd6685f1343e 47 @brief manipulates the buzzer PWM frequency for different sounds depending on the soundType variable. This variable is global due new sounds overriding older sounds.
domplatypus 0:dd6685f1343e 48 */
domplatypus 0:dd6685f1343e 49 void soundActivate();
domplatypus 0:dd6685f1343e 50
domplatypus 0:dd6685f1343e 51 /**
domplatypus 0:dd6685f1343e 52 @namespace lcd
domplatypus 0:dd6685f1343e 53 @brief The lcd instance and the pins connected to it
domplatypus 0:dd6685f1343e 54 */
domplatypus 0:dd6685f1343e 55 N5110 lcd(p7,p8,p9,p10,p11,p13,p26); // pwm for led backlight
domplatypus 0:dd6685f1343e 56
domplatypus 0:dd6685f1343e 57 //!The 'master' matrix which holds all of the pixel values on our lcd screen
domplatypus 0:dd6685f1343e 58 //!Array to be modified by functions
domplatypus 0:dd6685f1343e 59 bool cellsCurrent[48][84];
domplatypus 0:dd6685f1343e 60 //!Buffer array to store the LCDs previous state
domplatypus 0:dd6685f1343e 61 //!Supplies information to decide whether a pixel needs to be changed or not
domplatypus 0:dd6685f1343e 62 bool cellsBuffer[48][84];
domplatypus 0:dd6685f1343e 63 /**
domplatypus 0:dd6685f1343e 64 @brief Clears the cellCurrent ‘master’ array, all elements set to 0.
domplatypus 0:dd6685f1343e 65 */
domplatypus 0:dd6685f1343e 66 void clearArray();
domplatypus 0:dd6685f1343e 67 //! The matrix shape which holds the ship pixels
domplatypus 0:dd6685f1343e 68 bool playerShape1[5][5] = {0,1,1,1,0,
domplatypus 0:dd6685f1343e 69 1,1,1,0,0,
domplatypus 0:dd6685f1343e 70 0,1,1,1,1,
domplatypus 0:dd6685f1343e 71 1,1,1,0,0,
domplatypus 0:dd6685f1343e 72 0,1,1,1,0
domplatypus 0:dd6685f1343e 73 };
domplatypus 0:dd6685f1343e 74 //! The matrix shape which holds the ship pixels
domplatypus 0:dd6685f1343e 75 bool playerShape2[5][5] = {0,1,1,0,0,
domplatypus 0:dd6685f1343e 76 1,1,0,0,0,
domplatypus 0:dd6685f1343e 77 0,1,1,1,1,
domplatypus 0:dd6685f1343e 78 1,1,0,0,0,
domplatypus 0:dd6685f1343e 79 0,1,1,0,0
domplatypus 0:dd6685f1343e 80 };
domplatypus 0:dd6685f1343e 81 int explotionStage;
domplatypus 0:dd6685f1343e 82 bool explotion1[5][5] = {0,0,0,0,0,
domplatypus 0:dd6685f1343e 83 0,0,1,0,0,
domplatypus 0:dd6685f1343e 84 0,1,0,1,0,
domplatypus 0:dd6685f1343e 85 0,0,1,0,0,
domplatypus 0:dd6685f1343e 86 0,0,0,0,0
domplatypus 0:dd6685f1343e 87 };
domplatypus 0:dd6685f1343e 88 bool explotion2[5][5] = {0,0,1,0,0,
domplatypus 0:dd6685f1343e 89 0,0,1,0,0,
domplatypus 0:dd6685f1343e 90 1,1,0,1,1,
domplatypus 0:dd6685f1343e 91 0,0,1,0,0,
domplatypus 0:dd6685f1343e 92 0,0,1,0,0
domplatypus 0:dd6685f1343e 93 };
domplatypus 0:dd6685f1343e 94 bool explotion3[5][5] = {0,0,1,0,0,
domplatypus 0:dd6685f1343e 95 0,0,0,0,0,
domplatypus 0:dd6685f1343e 96 1,0,0,0,1,
domplatypus 0:dd6685f1343e 97 0,0,0,0,0,
domplatypus 0:dd6685f1343e 98 0,0,1,0,0
domplatypus 0:dd6685f1343e 99 };
domplatypus 0:dd6685f1343e 100 bool itemShape[5][5] = { 0,0,1,0,0,
domplatypus 0:dd6685f1343e 101 0,0,1,0,0,
domplatypus 0:dd6685f1343e 102 1,1,1,1,1,
domplatypus 0:dd6685f1343e 103 0,0,1,0,0,
domplatypus 0:dd6685f1343e 104 0,0,1,0,0
domplatypus 0:dd6685f1343e 105 };
domplatypus 0:dd6685f1343e 106 //!Variable to store which round the user is on
domplatypus 0:dd6685f1343e 107 int roundNumber;
domplatypus 0:dd6685f1343e 108 //!Number of asteroids active on screen
domplatypus 0:dd6685f1343e 109 int asteroids;
domplatypus 0:dd6685f1343e 110 //!variable to declare that our ship is in the explotion stage
domplatypus 0:dd6685f1343e 111 int shipExplodeFlag;
domplatypus 0:dd6685f1343e 112 /**
domplatypus 0:dd6685f1343e 113 @brief Runs the destroySelf function from the player class and switches to the game over screen when explosion has finished.
domplatypus 0:dd6685f1343e 114 */
domplatypus 0:dd6685f1343e 115 void shipExplode();
domplatypus 0:dd6685f1343e 116 /**
domplatypus 0:dd6685f1343e 117 @brief array of spawn coordinates
domplatypus 0:dd6685f1343e 118 @brief spawnLocation[i][j] where i represents the number assigned to the coordinate location and j hold 3 elements and represents the x,y position and whether it is active
domplatypus 0:dd6685f1343e 119 */
domplatypus 0:dd6685f1343e 120 int spawnLocation[32][3];
domplatypus 0:dd6685f1343e 121 /**
domplatypus 0:dd6685f1343e 122 Initiates the spawn locations for asteroids and marks the segment that the player is within as occupied.
domplatypus 0:dd6685f1343e 123 */
domplatypus 0:dd6685f1343e 124 void initSpawn();
domplatypus 0:dd6685f1343e 125 /**
domplatypus 0:dd6685f1343e 126 @brief Gets a random spawn location for the asteroid to spawn. Once the position is given to an asteroid that position is marked as occupied. If a position given is already occupied then another random number is generated until an available position is given.
domplatypus 0:dd6685f1343e 127 */
domplatypus 0:dd6685f1343e 128 int getSpawnLocation();
domplatypus 0:dd6685f1343e 129 /**
domplatypus 0:dd6685f1343e 130 @brief To be used with rand() function so that an asteroids movement is randomised
domplatypus 0:dd6685f1343e 131 */
domplatypus 0:dd6685f1343e 132 int directionMatrix[2];
domplatypus 0:dd6685f1343e 133 /**
domplatypus 0:dd6685f1343e 134 @brief asteroid's pixel array within a 5x5 array
domplatypus 0:dd6685f1343e 135 */
domplatypus 0:dd6685f1343e 136 bool asteroidShape[5][5] = {0,0,1,0,0,
domplatypus 0:dd6685f1343e 137 0,1,1,1,0,
domplatypus 0:dd6685f1343e 138 1,1,1,1,1,
domplatypus 0:dd6685f1343e 139 0,1,1,1,0,
domplatypus 0:dd6685f1343e 140 0,0,1,0,0
domplatypus 0:dd6685f1343e 141 };
domplatypus 0:dd6685f1343e 142 /**
domplatypus 0:dd6685f1343e 143 @brief Declares new laser can be fired
domplatypus 0:dd6685f1343e 144 */
domplatypus 0:dd6685f1343e 145 bool laserClear;
domplatypus 0:dd6685f1343e 146 /**
domplatypus 0:dd6685f1343e 147 @brief Declares how many 'frames' it takes until a new laser can be fired
domplatypus 0:dd6685f1343e 148 */
domplatypus 0:dd6685f1343e 149 int laserCoolDown;
domplatypus 0:dd6685f1343e 150 /**
domplatypus 0:dd6685f1343e 151 @brief Declares whether the rapid fire power up has been activated
domplatypus 0:dd6685f1343e 152 */
domplatypus 0:dd6685f1343e 153 bool rapidFire;
domplatypus 0:dd6685f1343e 154 /**
domplatypus 0:dd6685f1343e 155 @brief Declares how many 'frames' the abilityCounter has been active for
domplatypus 0:dd6685f1343e 156 */
domplatypus 0:dd6685f1343e 157 int abilityCounter;
domplatypus 0:dd6685f1343e 158 /**
domplatypus 0:dd6685f1343e 159 @brief Counts how many moves a laser has been active for
domplatypus 0:dd6685f1343e 160 */
domplatypus 0:dd6685f1343e 161 int laserCounter;
domplatypus 0:dd6685f1343e 162 /**
domplatypus 0:dd6685f1343e 163 @brief Activates an available laser object if the laserClearFlag is activated.
domplatypus 0:dd6685f1343e 164 */
domplatypus 0:dd6685f1343e 165 void laserActivate();
domplatypus 0:dd6685f1343e 166 /**
domplatypus 0:dd6685f1343e 167 @brief Moves any active lasers and increments a laser cool down if laser is not clear to fire again.
domplatypus 0:dd6685f1343e 168 */
domplatypus 0:dd6685f1343e 169 void laserMove();
domplatypus 0:dd6685f1343e 170 /**
domplatypus 0:dd6685f1343e 171 @brief timer variable to count through the frame rates
domplatypus 0:dd6685f1343e 172 */
domplatypus 0:dd6685f1343e 173 Ticker timer;
domplatypus 0:dd6685f1343e 174 /**
domplatypus 0:dd6685f1343e 175 @brief timer variable to count how long since last buttonFlag was set
domplatypus 0:dd6685f1343e 176 @brief used to prevent button bounce problem
domplatypus 0:dd6685f1343e 177 */
domplatypus 0:dd6685f1343e 178 Timer debounce;
domplatypus 0:dd6685f1343e 179 /**
domplatypus 0:dd6685f1343e 180 @brief Flag to control the timer loops
domplatypus 0:dd6685f1343e 181 */
domplatypus 0:dd6685f1343e 182 int timerFlag;
domplatypus 0:dd6685f1343e 183 /**
domplatypus 0:dd6685f1343e 184 @brief Function called every time a specified amount of time has passed for the menu modes this is set every 0.01s but in game mode it is set to 0.005s as fast logic is required. Controls the frame rate, enemy speed, player speed and laser speed primarily.
domplatypus 0:dd6685f1343e 185 */
domplatypus 0:dd6685f1343e 186 void timerExpired();
domplatypus 0:dd6685f1343e 187 /**
domplatypus 0:dd6685f1343e 188 @brief Sets screen according to the current matrix enabled. If the element is one set the pixel, if the element is 0 clear the pixel. The new array is compared with the last array so that any pixels which are the same as before are not set or cleared unnecessarily.
domplatypus 0:dd6685f1343e 189 */
domplatypus 0:dd6685f1343e 190 void setScreen();
domplatypus 0:dd6685f1343e 191 /**
domplatypus 0:dd6685f1343e 192 @brief Checks the asteroid against laser positions and removes them if they touch , Player positions against asteroids and shields down or game over if this happens, asteroids position against each other and alter the direction so they bounce and checks if the asteroids collide with a boundary if walls are active then asteroid bounces off wall if not the asteroid appears on opposite end of screen.
domplatypus 0:dd6685f1343e 193 */
domplatypus 0:dd6685f1343e 194 void check();
domplatypus 0:dd6685f1343e 195 /**
domplatypus 0:dd6685f1343e 196 @brief declares the program is in the game mode
domplatypus 0:dd6685f1343e 197 */
domplatypus 0:dd6685f1343e 198 bool gameMode;
domplatypus 0:dd6685f1343e 199 /**
domplatypus 0:dd6685f1343e 200 @brief score gained by the user
domplatypus 0:dd6685f1343e 201 */
domplatypus 0:dd6685f1343e 202 int score;
domplatypus 0:dd6685f1343e 203 /**
domplatypus 0:dd6685f1343e 204 @brief declares the program is in the menu mode
domplatypus 0:dd6685f1343e 205 */
domplatypus 0:dd6685f1343e 206 bool menuMode;
domplatypus 0:dd6685f1343e 207 /**
domplatypus 0:dd6685f1343e 208 @brief Flag to trigger next round
domplatypus 0:dd6685f1343e 209 */
domplatypus 0:dd6685f1343e 210 bool roundFlag;
domplatypus 0:dd6685f1343e 211 /**
domplatypus 0:dd6685f1343e 212 @brief function to initialise the next round and spawn the required number of asteroids. If round has surpassed 8 then speed is turned up, the rounds restart from one and shields of the player are restored.
domplatypus 0:dd6685f1343e 213 */
domplatypus 0:dd6685f1343e 214 void roundInit();
domplatypus 0:dd6685f1343e 215 /**
domplatypus 0:dd6685f1343e 216 @brief Initialises the game mode, clearing array, LCD screen, variables, initialisation of classes and adding to the array.
domplatypus 0:dd6685f1343e 217 */
domplatypus 0:dd6685f1343e 218 void gameStart();
domplatypus 0:dd6685f1343e 219 /**
domplatypus 0:dd6685f1343e 220 @brief Initialises the menu mode by initialising variables and clearing array.
domplatypus 0:dd6685f1343e 221 */
domplatypus 0:dd6685f1343e 222 void menuInit();
domplatypus 0:dd6685f1343e 223 /**
domplatypus 0:dd6685f1343e 224 @brief Runs the menu frame, the options, the selector and the title.
domplatypus 0:dd6685f1343e 225 */
domplatypus 0:dd6685f1343e 226 void menuSet();
domplatypus 0:dd6685f1343e 227 /**
domplatypus 0:dd6685f1343e 228 @brief declares which option on the menu the user is currently selecting
domplatypus 0:dd6685f1343e 229 */
domplatypus 0:dd6685f1343e 230 int titleSelected;
domplatypus 0:dd6685f1343e 231 /**
domplatypus 0:dd6685f1343e 232 @brief declares gameOver mode screen
domplatypus 0:dd6685f1343e 233 */
domplatypus 0:dd6685f1343e 234 bool gameOverMode;
domplatypus 0:dd6685f1343e 235
domplatypus 0:dd6685f1343e 236 /**
domplatypus 0:dd6685f1343e 237 Initialises the gameOverScreen, displaying text and the players score.
domplatypus 0:dd6685f1343e 238 An integer to string converter process is used taken from http://developer.mbed.org/questions/249/float-or-integer-to-char-or-string-conve/
domplatypus 0:dd6685f1343e 239 */
domplatypus 0:dd6685f1343e 240 void gameOverInit();
domplatypus 0:dd6685f1343e 241 /**
domplatypus 0:dd6685f1343e 242 @brief User can scroll through 3 characters and change them to present their own ID. Saves player ID to flash in descending score order when user selects if the score is within the top 5.
domplatypus 0:dd6685f1343e 243 */
domplatypus 0:dd6685f1343e 244 void gameOverSet();
domplatypus 0:dd6685f1343e 245 /**
domplatypus 0:dd6685f1343e 246 @brief counts how many 'frames' the intro screen has been active for
domplatypus 0:dd6685f1343e 247 */
domplatypus 0:dd6685f1343e 248 int introCounter;
domplatypus 0:dd6685f1343e 249 /**
domplatypus 0:dd6685f1343e 250 @brief declares game is in intro mode
domplatypus 0:dd6685f1343e 251 */
domplatypus 0:dd6685f1343e 252 bool introMode;
domplatypus 0:dd6685f1343e 253 /**
domplatypus 0:dd6685f1343e 254 @brief Initialises the variables and clears screen for the introduction mode.
domplatypus 0:dd6685f1343e 255 */
domplatypus 0:dd6685f1343e 256 void introInit();
domplatypus 0:dd6685f1343e 257 /**
domplatypus 0:dd6685f1343e 258 @brief Sets the introduction screen including the title and the ship animation.
domplatypus 0:dd6685f1343e 259 */
domplatypus 0:dd6685f1343e 260 void introSet();
domplatypus 0:dd6685f1343e 261 /**
domplatypus 0:dd6685f1343e 262 @brief variable to declare that the highscore mode is active
domplatypus 0:dd6685f1343e 263 */
domplatypus 0:dd6685f1343e 264 int highScoreMode;
domplatypus 0:dd6685f1343e 265 /**
domplatypus 0:dd6685f1343e 266 @brief Sets the high score mode reads the data from the flash drive and displays the top 5 users score, name and date.
domplatypus 0:dd6685f1343e 267 */
domplatypus 0:dd6685f1343e 268 void highScoreSet();
domplatypus 0:dd6685f1343e 269 /**
domplatypus 0:dd6685f1343e 270 @brief declares the helpMode option is open
domplatypus 0:dd6685f1343e 271 */
domplatypus 0:dd6685f1343e 272 int helpMode;
domplatypus 0:dd6685f1343e 273 /**
domplatypus 0:dd6685f1343e 274 @brief Initialises the variables, objects and clears the screen for the help mode and presents them onto the screen along with informative text.
domplatypus 0:dd6685f1343e 275 */
domplatypus 0:dd6685f1343e 276 void helpInit();
domplatypus 0:dd6685f1343e 277 /**
domplatypus 0:dd6685f1343e 278 @brief declares setting mode is active
domplatypus 0:dd6685f1343e 279 */
domplatypus 0:dd6685f1343e 280 bool settingsMode;
domplatypus 0:dd6685f1343e 281 /**
domplatypus 0:dd6685f1343e 282 @brief Initialises the variables, objects and clears the screen for the help mode and presents them onto the screen along with informative text.
domplatypus 0:dd6685f1343e 283 */
domplatypus 0:dd6685f1343e 284 void settingsInit();
domplatypus 0:dd6685f1343e 285 /**
domplatypus 0:dd6685f1343e 286 @brief Sets the setting screen – Including the text and the selector and allows the user to change the options of speed, whether walls are active and toggle the sound. Time is also displayed.
domplatypus 0:dd6685f1343e 287 */
domplatypus 0:dd6685f1343e 288 void settingsSet();
domplatypus 0:dd6685f1343e 289 /**
domplatypus 0:dd6685f1343e 290 @brief declares whether walls for the asteroid are active or not
domplatypus 0:dd6685f1343e 291 */
domplatypus 0:dd6685f1343e 292 bool walls;
domplatypus 0:dd6685f1343e 293 /**
domplatypus 0:dd6685f1343e 294 @brief declares what speed state the game is within
domplatypus 0:dd6685f1343e 295 */
domplatypus 0:dd6685f1343e 296 int speedState;
domplatypus 0:dd6685f1343e 297 /**
domplatypus 0:dd6685f1343e 298 @brief ID class defining the attributes of a Players name, score, the date they achieved this score and whether this Player is active
domplatypus 0:dd6685f1343e 299 @brief This is read from the flash drive
domplatypus 0:dd6685f1343e 300 */
domplatypus 0:dd6685f1343e 301 class ID
domplatypus 0:dd6685f1343e 302 {
domplatypus 0:dd6685f1343e 303 public:
domplatypus 0:dd6685f1343e 304 /**
domplatypus 0:dd6685f1343e 305 declares if the object is active
domplatypus 0:dd6685f1343e 306 */
domplatypus 0:dd6685f1343e 307 bool active;
domplatypus 0:dd6685f1343e 308 /**
domplatypus 0:dd6685f1343e 309 ID score
domplatypus 0:dd6685f1343e 310 */
domplatypus 0:dd6685f1343e 311 int score;
domplatypus 0:dd6685f1343e 312 /**
domplatypus 0:dd6685f1343e 313 ID name string
domplatypus 0:dd6685f1343e 314 */
domplatypus 0:dd6685f1343e 315 char name[3];
domplatypus 0:dd6685f1343e 316 /**
domplatypus 0:dd6685f1343e 317 ID date string
domplatypus 0:dd6685f1343e 318 */
domplatypus 0:dd6685f1343e 319 char date[3];
domplatypus 0:dd6685f1343e 320 };
domplatypus 0:dd6685f1343e 321 /**
domplatypus 0:dd6685f1343e 322 @brief instance of our ID class
domplatypus 0:dd6685f1343e 323 */
domplatypus 0:dd6685f1343e 324 ID iD1;
domplatypus 0:dd6685f1343e 325 /**
domplatypus 0:dd6685f1343e 326 @brief instance of our ID class
domplatypus 0:dd6685f1343e 327 */
domplatypus 0:dd6685f1343e 328 ID iD2;
domplatypus 0:dd6685f1343e 329 /**
domplatypus 0:dd6685f1343e 330 @brief instance of our ID class
domplatypus 0:dd6685f1343e 331 */
domplatypus 0:dd6685f1343e 332 ID iD3;
domplatypus 0:dd6685f1343e 333 /**
domplatypus 0:dd6685f1343e 334 @brief instance of our ID class
domplatypus 0:dd6685f1343e 335 */
domplatypus 0:dd6685f1343e 336 ID iD4;
domplatypus 0:dd6685f1343e 337 /**
domplatypus 0:dd6685f1343e 338 @brief instance of our ID class
domplatypus 0:dd6685f1343e 339 */
domplatypus 0:dd6685f1343e 340 ID iD5;
domplatypus 0:dd6685f1343e 341 /**
domplatypus 0:dd6685f1343e 342 @brief iD matrix of our ID objects
domplatypus 0:dd6685f1343e 343 */
domplatypus 0:dd6685f1343e 344 ID iD[5] = {iD1,iD2,iD3,iD4,iD5};
domplatypus 0:dd6685f1343e 345 /**
domplatypus 0:dd6685f1343e 346 @brief Decodes the flash drive saved files and assigns the ID objects values.
domplatypus 0:dd6685f1343e 347 */
domplatypus 0:dd6685f1343e 348 void iDSet();
domplatypus 0:dd6685f1343e 349 /**
domplatypus 0:dd6685f1343e 350 Compares the current players ID (the score just gained) against the ones on the flash drive and organises them as the top 5.
domplatypus 0:dd6685f1343e 351 Flash drive file is deleted and a new file with the newly organised players ID is set.
domplatypus 0:dd6685f1343e 352 Code idea taken from http://www.cplusplus.com/reference/cstdio/fgets/
domplatypus 0:dd6685f1343e 353 @param score - score of the player
domplatypus 0:dd6685f1343e 354 @param n1 - first character of the players name
domplatypus 0:dd6685f1343e 355 @param n2 - second character of the players name
domplatypus 0:dd6685f1343e 356 @param n3 - third character of the players name
domplatypus 0:dd6685f1343e 357 @brief taking the players name and score this organises their score against the current players and writes the ids in score descending order
domplatypus 0:dd6685f1343e 358 */
domplatypus 0:dd6685f1343e 359 void writeDataToFile(int score,char n1, char n2, char n3);
domplatypus 0:dd6685f1343e 360 /**
domplatypus 0:dd6685f1343e 361 @brief declares which character is selected on the screen
domplatypus 0:dd6685f1343e 362 */
domplatypus 0:dd6685f1343e 363 int cSelected;
domplatypus 0:dd6685f1343e 364 /**
domplatypus 0:dd6685f1343e 365 @brief first character option for the user to change
domplatypus 0:dd6685f1343e 366 */
domplatypus 0:dd6685f1343e 367 int c1;
domplatypus 0:dd6685f1343e 368 /**
domplatypus 0:dd6685f1343e 369 @brief second character option for the user to change
domplatypus 0:dd6685f1343e 370 */
domplatypus 0:dd6685f1343e 371 int c2;
domplatypus 0:dd6685f1343e 372 /**
domplatypus 0:dd6685f1343e 373 @brief third character option for the user to change
domplatypus 0:dd6685f1343e 374 */
domplatypus 0:dd6685f1343e 375 int c3;
domplatypus 0:dd6685f1343e 376 /**
domplatypus 0:dd6685f1343e 377 @brief read the players ID to the the flash drive and assigns the values to our ID objects
domplatypus 0:dd6685f1343e 378 @brief player IDs are displayed on the LCD screen
domplatypus 0:dd6685f1343e 379 */
domplatypus 0:dd6685f1343e 380 void writeID();
domplatypus 0:dd6685f1343e 381 /**
domplatypus 0:dd6685f1343e 382 @brief Calls this function when data sent to mbed, which sets the time
domplatypus 0:dd6685f1343e 383 */
domplatypus 0:dd6685f1343e 384 void serialISR();
domplatypus 0:dd6685f1343e 385 /**
domplatypus 0:dd6685f1343e 386 @brief flag set when button is pressed
domplatypus 0:dd6685f1343e 387 */
domplatypus 0:dd6685f1343e 388 int buttonFlag;
domplatypus 0:dd6685f1343e 389 /**
domplatypus 0:dd6685f1343e 390 @brief Function is called when rising edge on button input, sets a buttonFlag to signal the button has been pressed.
domplatypus 0:dd6685f1343e 391 @brief prevents button bouncing with debounce timer, so that flag is not set again if it was only called 150 ms ago
domplatypus 0:dd6685f1343e 392 */
domplatypus 0:dd6685f1343e 393 void buttonPressed();
domplatypus 0:dd6685f1343e 394 /**
domplatypus 0:dd6685f1343e 395 @brief Item class with properties and functions
domplatypus 0:dd6685f1343e 396 */
domplatypus 0:dd6685f1343e 397 class Item
domplatypus 0:dd6685f1343e 398 {
domplatypus 0:dd6685f1343e 399 public:
domplatypus 0:dd6685f1343e 400 /**
domplatypus 0:dd6685f1343e 401 declares whether item is active
domplatypus 0:dd6685f1343e 402 */
domplatypus 0:dd6685f1343e 403 bool active;
domplatypus 0:dd6685f1343e 404 /**
domplatypus 0:dd6685f1343e 405 declares items pixel shape
domplatypus 0:dd6685f1343e 406 */
domplatypus 0:dd6685f1343e 407 bool shape[5][5];
domplatypus 0:dd6685f1343e 408 /**
domplatypus 0:dd6685f1343e 409 declares x,y coordinates of the item
domplatypus 0:dd6685f1343e 410 */
domplatypus 0:dd6685f1343e 411 int position[2];
domplatypus 0:dd6685f1343e 412 /**
domplatypus 0:dd6685f1343e 413 adds the item shape to the matrix
domplatypus 0:dd6685f1343e 414 */
domplatypus 0:dd6685f1343e 415 void addSelf() { //adding the shape to the array
domplatypus 0:dd6685f1343e 416 for(int i = 0; i<5; i++) {
domplatypus 0:dd6685f1343e 417 for(int j = 0; j<5; j++) { // for loop cycling through each element pf the array
domplatypus 0:dd6685f1343e 418 cellsCurrent[position[1]+j][position[0]+i] = shape[j][i]; // setting the respective pixels
domplatypus 0:dd6685f1343e 419 }
domplatypus 0:dd6685f1343e 420 }
domplatypus 0:dd6685f1343e 421 }
domplatypus 0:dd6685f1343e 422 /**
domplatypus 0:dd6685f1343e 423 deletes the item shape from the matrix
domplatypus 0:dd6685f1343e 424 */
domplatypus 0:dd6685f1343e 425 void deleteSelf() { // deleting the shape from the array
domplatypus 0:dd6685f1343e 426 for(int i = 0; i<5; i++) {
domplatypus 0:dd6685f1343e 427 for(int j =0; j<5; j++) { // for loop cycling through each element of the array
domplatypus 0:dd6685f1343e 428 cellsCurrent[j+position[1]][i+position[0]] =0; // deleting the respective pixels
domplatypus 0:dd6685f1343e 429 }
domplatypus 0:dd6685f1343e 430 }
domplatypus 0:dd6685f1343e 431 }
domplatypus 0:dd6685f1343e 432 /**
domplatypus 0:dd6685f1343e 433 initialises the item object
domplatypus 0:dd6685f1343e 434 */
domplatypus 0:dd6685f1343e 435 void init() {
domplatypus 0:dd6685f1343e 436 active =0;
domplatypus 0:dd6685f1343e 437 for(int i=0; i <5; i++) {
domplatypus 0:dd6685f1343e 438 for(int j=0; j<5; j++) { //defining the ship array
domplatypus 0:dd6685f1343e 439 shape[j][i] = itemShape[j][i];
domplatypus 0:dd6685f1343e 440 }
domplatypus 0:dd6685f1343e 441 }
domplatypus 0:dd6685f1343e 442 }
domplatypus 0:dd6685f1343e 443 };
domplatypus 0:dd6685f1343e 444 /**
domplatypus 0:dd6685f1343e 445 An instance of the Item class created
domplatypus 0:dd6685f1343e 446 */
domplatypus 0:dd6685f1343e 447 Item item;
domplatypus 0:dd6685f1343e 448 /**
domplatypus 0:dd6685f1343e 449 Our player class for the players ship defined
domplatypus 0:dd6685f1343e 450 */
domplatypus 0:dd6685f1343e 451 class Player
domplatypus 0:dd6685f1343e 452 {
domplatypus 0:dd6685f1343e 453 /**
domplatypus 0:dd6685f1343e 454 \class player
domplatypus 0:dd6685f1343e 455 Player class which is our blueprint of the players ship
domplatypus 0:dd6685f1343e 456 class functions and variables are here
domplatypus 0:dd6685f1343e 457 */
domplatypus 0:dd6685f1343e 458 public:
domplatypus 0:dd6685f1343e 459 /**Array defining our Player's shape
domplatypus 0:dd6685f1343e 460 */
domplatypus 0:dd6685f1343e 461 bool shape[5][5];
domplatypus 0:dd6685f1343e 462 ///array defining our Player's position
domplatypus 0:dd6685f1343e 463 int position[2];
domplatypus 0:dd6685f1343e 464 ///declares whether the players shields are up
domplatypus 0:dd6685f1343e 465 bool shield;
domplatypus 0:dd6685f1343e 466 ///adding the current Player to the master matrix
domplatypus 0:dd6685f1343e 467 void addSelf() { //adding the shape to the array
domplatypus 0:dd6685f1343e 468 for(int i = 0; i<5; i++) {
domplatypus 0:dd6685f1343e 469 for(int j = 0; j<5; j++) { // for loop cycling through each element pf the array
domplatypus 0:dd6685f1343e 470 cellsCurrent[position[1]+j][position[0]+i] = shape[j][i]; // setting the respective pixels
domplatypus 0:dd6685f1343e 471 }
domplatypus 0:dd6685f1343e 472 }
domplatypus 0:dd6685f1343e 473 }
domplatypus 0:dd6685f1343e 474 ///deleting the current Player to the master matrix
domplatypus 0:dd6685f1343e 475 void deleteSelf() { // deleting the shape from the array
domplatypus 0:dd6685f1343e 476 for(int i = 0; i<5; i++) {
domplatypus 0:dd6685f1343e 477 for(int j =0; j<5; j++) { // for loop cycling through each element of the array
domplatypus 0:dd6685f1343e 478 cellsCurrent[j+position[1]][i+position[0]] =0; // deleting the respective pixels
domplatypus 0:dd6685f1343e 479 }
domplatypus 0:dd6685f1343e 480 }
domplatypus 0:dd6685f1343e 481 }
domplatypus 0:dd6685f1343e 482 ///Moves the player’s position on the matrix, boundaries are built into this function.
domplatypus 0:dd6685f1343e 483 ///This function deletes the player shape from the array, changes its position and adds the shape back to the array.
domplatypus 0:dd6685f1343e 484 ///@param int x Declares the amount of position movement in the x direction in pixels
domplatypus 0:dd6685f1343e 485 ///@param int y Declares the amount of position movement in the y direction in pixel
domplatypus 0:dd6685f1343e 486 void moveSelf(int x, int y) { //moving the shape, x defines whether up down y defines left right
domplatypus 0:dd6685f1343e 487 deleteSelf(); //deletes the shape the the array
domplatypus 0:dd6685f1343e 488 if((position[0]+x < 79)&(position[0]+x>=0)) { // if within the x bounds of the screen
domplatypus 0:dd6685f1343e 489 position[0] = position[0] + x; //changes the x position
domplatypus 0:dd6685f1343e 490 }
domplatypus 0:dd6685f1343e 491 if((position[1]+y<43)&(position[1]+y>=0)) { // if within the y bounds of the screen
domplatypus 0:dd6685f1343e 492 position[1] = position[1] + y; //changes the y position
domplatypus 0:dd6685f1343e 493 }
domplatypus 0:dd6685f1343e 494 addSelf(); // adds object according to the new position
domplatypus 0:dd6685f1343e 495 }
domplatypus 0:dd6685f1343e 496 /**
domplatypus 0:dd6685f1343e 497 @brief exploding frames for the ship
domplatypus 0:dd6685f1343e 498 @param explotionState Which stage of the explotion the ship is at
domplatypus 0:dd6685f1343e 499 */
domplatypus 0:dd6685f1343e 500 void destroySelf(int explotionState) {
domplatypus 0:dd6685f1343e 501 deleteSelf();
domplatypus 0:dd6685f1343e 502 for(int i=0; i<5; i++) {
domplatypus 0:dd6685f1343e 503 for(int j=0; j<5; j++) {
domplatypus 0:dd6685f1343e 504 if(explotionState>0&explotionState<4) {
domplatypus 0:dd6685f1343e 505 shape[j][i] = explotion1[j][i];
domplatypus 0:dd6685f1343e 506 } else if (explotionState>3&explotionState<8) {
domplatypus 0:dd6685f1343e 507 shape[j][i] = explotion2[j][i];
domplatypus 0:dd6685f1343e 508 } else if (explotionState>7) {
domplatypus 0:dd6685f1343e 509 shape[j][i] = explotion3[j][i];
domplatypus 0:dd6685f1343e 510 } else {
domplatypus 0:dd6685f1343e 511 shape[j][i] = 0;
domplatypus 0:dd6685f1343e 512 }
domplatypus 0:dd6685f1343e 513 }
domplatypus 0:dd6685f1343e 514 }
domplatypus 0:dd6685f1343e 515 addSelf();
domplatypus 0:dd6685f1343e 516 }
domplatypus 0:dd6685f1343e 517 /**
domplatypus 0:dd6685f1343e 518 updates the players shield appearance depending on its value
domplatypus 0:dd6685f1343e 519 */
domplatypus 0:dd6685f1343e 520 void shieldUpdate() { //1 for pushing shields up 0 for putting them down
domplatypus 0:dd6685f1343e 521 for(int i=0; i <5; i++) {
domplatypus 0:dd6685f1343e 522 for(int j=0; j<5; j++) { //defining the ship array
domplatypus 0:dd6685f1343e 523 if(shield) {
domplatypus 0:dd6685f1343e 524 shape[j][i] = playerShape1[j][i];
domplatypus 0:dd6685f1343e 525 }//shields up
domplatypus 0:dd6685f1343e 526 else {
domplatypus 0:dd6685f1343e 527 shape[j][i] = playerShape2[j][i];
domplatypus 0:dd6685f1343e 528 } //shields down
domplatypus 0:dd6685f1343e 529 }
domplatypus 0:dd6685f1343e 530 }
domplatypus 0:dd6685f1343e 531 }
domplatypus 0:dd6685f1343e 532 /** Initialise player properties
domplatypus 0:dd6685f1343e 533 */
domplatypus 0:dd6685f1343e 534 void init() {
domplatypus 0:dd6685f1343e 535 position[0] = 0;
domplatypus 0:dd6685f1343e 536 position[1] = 20; //position sent to the centre of the screen
domplatypus 0:dd6685f1343e 537 shield = 1;
domplatypus 0:dd6685f1343e 538 shieldUpdate();
domplatypus 0:dd6685f1343e 539 //addSelf(); //adding ship to the matrix
domplatypus 0:dd6685f1343e 540 }
domplatypus 0:dd6685f1343e 541 };
domplatypus 0:dd6685f1343e 542 /**
domplatypus 0:dd6685f1343e 543 Player class instance
domplatypus 0:dd6685f1343e 544 */
domplatypus 0:dd6685f1343e 545 Player ship;
domplatypus 0:dd6685f1343e 546
domplatypus 0:dd6685f1343e 547 /**
domplatypus 0:dd6685f1343e 548 asteroid class defined
domplatypus 0:dd6685f1343e 549 */
domplatypus 0:dd6685f1343e 550 class asteroid
domplatypus 0:dd6685f1343e 551 {
domplatypus 0:dd6685f1343e 552 //defining our asteroid template class
domplatypus 0:dd6685f1343e 553 public: //our entity class is public
domplatypus 0:dd6685f1343e 554 /**
domplatypus 0:dd6685f1343e 555 declares that asteroid is active
domplatypus 0:dd6685f1343e 556 */
domplatypus 0:dd6685f1343e 557 bool active; //declaring whether the asteroid is active or not
domplatypus 0:dd6685f1343e 558 /**
domplatypus 0:dd6685f1343e 559 shape array holding the pixels for the asteroid
domplatypus 0:dd6685f1343e 560 */
domplatypus 0:dd6685f1343e 561 bool shape[5][5]; // shape array to hold the pixel data
domplatypus 0:dd6685f1343e 562 /**
domplatypus 0:dd6685f1343e 563 @brief 2 element array to hold the x,y position of the asteroid
domplatypus 0:dd6685f1343e 564 */
domplatypus 0:dd6685f1343e 565 int position[2]; // 2 element array to hold x,y components of the entities position
domplatypus 0:dd6685f1343e 566 /**
domplatypus 0:dd6685f1343e 567 @brief Declares the yDirection the asteroid
domplatypus 0:dd6685f1343e 568 */
domplatypus 0:dd6685f1343e 569 int yDirection;
domplatypus 0:dd6685f1343e 570 /**
domplatypus 0:dd6685f1343e 571 @brief Declares the xDirection the asteroid
domplatypus 0:dd6685f1343e 572 */
domplatypus 0:dd6685f1343e 573 int xDirection; // directon variables to store which direction the asteroid is moving
domplatypus 0:dd6685f1343e 574 /**
domplatypus 0:dd6685f1343e 575 @brief adds the asteroid object to the current matrix
domplatypus 0:dd6685f1343e 576 */
domplatypus 0:dd6685f1343e 577 void addSelf() { //adding the shape to the array
domplatypus 0:dd6685f1343e 578 for(int i = 0; i<5; i++) {
domplatypus 0:dd6685f1343e 579 for(int j = 0; j<5; j++) { // for loop cycling through each element pf the array
domplatypus 0:dd6685f1343e 580 cellsCurrent[position[1]+j][position[0]+i] = shape[j][i]; // setting the respective pixels
domplatypus 0:dd6685f1343e 581 }
domplatypus 0:dd6685f1343e 582 }
domplatypus 0:dd6685f1343e 583 }
domplatypus 0:dd6685f1343e 584 /**
domplatypus 0:dd6685f1343e 585 @brief removes the asteroid object to the current matrix
domplatypus 0:dd6685f1343e 586 */
domplatypus 0:dd6685f1343e 587 void deleteSelf() { // deleting the shape from the array
domplatypus 0:dd6685f1343e 588 for(int i = 0; i<5; i++) {
domplatypus 0:dd6685f1343e 589 for(int j =0; j<5; j++) { // for loop cycling through each element of the array
domplatypus 0:dd6685f1343e 590 cellsCurrent[j+position[1]][i+position[0]] =0; // deleting the respective pixels
domplatypus 0:dd6685f1343e 591 }
domplatypus 0:dd6685f1343e 592 }
domplatypus 0:dd6685f1343e 593 }
domplatypus 0:dd6685f1343e 594 /**
domplatypus 0:dd6685f1343e 595 @brief moves the asteroid object to the current matrix
domplatypus 0:dd6685f1343e 596 */
domplatypus 0:dd6685f1343e 597 void moveSelf() { //moving the shape, x defines whether up down y defines left right
domplatypus 0:dd6685f1343e 598 deleteSelf(); //deletes the shape the the array
domplatypus 0:dd6685f1343e 599 if((position[0]+xDirection < 79)&(position[0]+xDirection>0)) { // if within the x bounds of the screen
domplatypus 0:dd6685f1343e 600 position[0] = position[0] + xDirection; //changes the x position
domplatypus 0:dd6685f1343e 601 } else if(walls) {
domplatypus 0:dd6685f1343e 602 soundType =3;
domplatypus 0:dd6685f1343e 603 initSound();
domplatypus 0:dd6685f1343e 604 xDirection = -xDirection;
domplatypus 0:dd6685f1343e 605 position[0] = position[0] + xDirection; //changes the x position
domplatypus 0:dd6685f1343e 606 } else {
domplatypus 0:dd6685f1343e 607 if(position[0]<=0) {
domplatypus 0:dd6685f1343e 608 position[0] = 79;
domplatypus 0:dd6685f1343e 609 } else {
domplatypus 0:dd6685f1343e 610 position[0] = 0;
domplatypus 0:dd6685f1343e 611 }
domplatypus 0:dd6685f1343e 612 }
domplatypus 0:dd6685f1343e 613 if((position[1]+yDirection<43)&(position[1]+yDirection>0)) { // if within the y bounds of the screen
domplatypus 0:dd6685f1343e 614 position[1] = position[1] + yDirection; //changes the y position
domplatypus 0:dd6685f1343e 615 } else if(walls) {
domplatypus 0:dd6685f1343e 616 soundType =3;
domplatypus 0:dd6685f1343e 617 initSound();
domplatypus 0:dd6685f1343e 618 yDirection = -yDirection;
domplatypus 0:dd6685f1343e 619 position[1] = position[1] + yDirection;
domplatypus 0:dd6685f1343e 620 } else {
domplatypus 0:dd6685f1343e 621 if(position[1]<=0) {
domplatypus 0:dd6685f1343e 622 position[1] = 43;
domplatypus 0:dd6685f1343e 623 } else {
domplatypus 0:dd6685f1343e 624 position[1] = 0;
domplatypus 0:dd6685f1343e 625 }
domplatypus 0:dd6685f1343e 626 }
domplatypus 0:dd6685f1343e 627 addSelf(); // adds object according to the new position
domplatypus 0:dd6685f1343e 628 }
domplatypus 0:dd6685f1343e 629 /**
domplatypus 0:dd6685f1343e 630 @brief initialises the properties of our asteroid object
domplatypus 0:dd6685f1343e 631 */
domplatypus 0:dd6685f1343e 632 void init() {
domplatypus 0:dd6685f1343e 633 int x = getSpawnLocation();
domplatypus 0:dd6685f1343e 634 position[0] = spawnLocation[x][0];
domplatypus 0:dd6685f1343e 635 position[1] = spawnLocation[x][1]; //position defined
domplatypus 0:dd6685f1343e 636 xDirection = directionMatrix[rand() % 2]; // direction chosen randomly to be + or - 1 using the directionMatrix
domplatypus 0:dd6685f1343e 637 yDirection = directionMatrix[rand() % 2];
domplatypus 0:dd6685f1343e 638 active = 0;
domplatypus 0:dd6685f1343e 639 for(int i=0; i <5; i++) {
domplatypus 0:dd6685f1343e 640 for(int j=0; j<5; j++) { //defining the asteroid array
domplatypus 0:dd6685f1343e 641 shape[j][i] = asteroidShape[j][i];
domplatypus 0:dd6685f1343e 642 }
domplatypus 0:dd6685f1343e 643 }
domplatypus 0:dd6685f1343e 644 }
domplatypus 0:dd6685f1343e 645 };
domplatypus 0:dd6685f1343e 646 ///instance of our asteroid class
domplatypus 0:dd6685f1343e 647 asteroid asteroid1;
domplatypus 0:dd6685f1343e 648 ///instance of our asteroid class
domplatypus 0:dd6685f1343e 649 asteroid asteroid2;
domplatypus 0:dd6685f1343e 650 ///instance of our asteroid class
domplatypus 0:dd6685f1343e 651 asteroid asteroid3;
domplatypus 0:dd6685f1343e 652 ///instance of our asteroid class
domplatypus 0:dd6685f1343e 653 asteroid asteroid4;
domplatypus 0:dd6685f1343e 654 ///instance of our asteroid class
domplatypus 0:dd6685f1343e 655 asteroid asteroid5;
domplatypus 0:dd6685f1343e 656 ///instance of our asteroid class
domplatypus 0:dd6685f1343e 657 asteroid asteroid6;
domplatypus 0:dd6685f1343e 658 ///instance of our asteroid class
domplatypus 0:dd6685f1343e 659 asteroid asteroid7;
domplatypus 0:dd6685f1343e 660 ///instance of our asteroid class
domplatypus 0:dd6685f1343e 661 asteroid asteroid8;
domplatypus 0:dd6685f1343e 662
domplatypus 0:dd6685f1343e 663 ///array holding all the asteroid objects
domplatypus 0:dd6685f1343e 664 asteroid asteroidM[8] = {asteroid1,asteroid2,asteroid3,asteroid4,asteroid5,asteroid6,asteroid7,asteroid8};
domplatypus 0:dd6685f1343e 665 /**
domplatypus 0:dd6685f1343e 666 @brief Laser position, active, pixel data, counterFlag variables
domplatypus 0:dd6685f1343e 667 */
domplatypus 0:dd6685f1343e 668 class Laser
domplatypus 0:dd6685f1343e 669 {
domplatypus 0:dd6685f1343e 670 //defining our laser class
domplatypus 0:dd6685f1343e 671 public: //our laser class is public
domplatypus 0:dd6685f1343e 672 /**
domplatypus 0:dd6685f1343e 673 @brief shape 1D array to hold the pixel data
domplatypus 0:dd6685f1343e 674 */
domplatypus 0:dd6685f1343e 675 bool shape[5]; // shape array to hold the pixel data
domplatypus 0:dd6685f1343e 676 /**
domplatypus 0:dd6685f1343e 677 @brief 2 element array to hold x,y components of the laser position
domplatypus 0:dd6685f1343e 678 */
domplatypus 0:dd6685f1343e 679 int position[2]; // 2 element array to hold x,y components of the laser position
domplatypus 0:dd6685f1343e 680 /**
domplatypus 0:dd6685f1343e 681 @brief declares the laser is active
domplatypus 0:dd6685f1343e 682 */
domplatypus 0:dd6685f1343e 683 bool active; //declares whether the particular laser is active
domplatypus 0:dd6685f1343e 684 /**
domplatypus 0:dd6685f1343e 685 @brief declares the laserCounter to start counting to trigger the laserClear variables
domplatypus 0:dd6685f1343e 686 */
domplatypus 0:dd6685f1343e 687 bool counterFlag; //declares the laserCounter to start counting to trigger the laserClear variables
domplatypus 0:dd6685f1343e 688 /**
domplatypus 0:dd6685f1343e 689 @brief adds the laser object to the current matrix
domplatypus 0:dd6685f1343e 690 */
domplatypus 0:dd6685f1343e 691 void addSelf() { //adding the shape to the array
domplatypus 0:dd6685f1343e 692 for(int i = 0; i<5; i++) {
domplatypus 0:dd6685f1343e 693 // for loop cycling through each element pf the array
domplatypus 0:dd6685f1343e 694 cellsCurrent[position[1]][position[0]+i] = shape[i]; // setting the respective pixels
domplatypus 0:dd6685f1343e 695 }
domplatypus 0:dd6685f1343e 696 }
domplatypus 0:dd6685f1343e 697 /**
domplatypus 0:dd6685f1343e 698 @brief removes the laser object to the current matrix
domplatypus 0:dd6685f1343e 699 */
domplatypus 0:dd6685f1343e 700 void deleteSelf() { // deleting the shape from the array
domplatypus 0:dd6685f1343e 701 for(int i = 0; i<5; i++) {
domplatypus 0:dd6685f1343e 702 // for loop cycling through each element of the array
domplatypus 0:dd6685f1343e 703 cellsCurrent[position[1]][i+position[0]] =0; // deleting the respective pixels
domplatypus 0:dd6685f1343e 704 }
domplatypus 0:dd6685f1343e 705 }
domplatypus 0:dd6685f1343e 706 /**
domplatypus 0:dd6685f1343e 707 @brief moves the laser object to the current matrix
domplatypus 0:dd6685f1343e 708 @param x - decleares whether the laser is moving forwards or backwards
domplatypus 0:dd6685f1343e 709 */
domplatypus 0:dd6685f1343e 710 void moveSelf(int x) { //moving the laser y defines left right
domplatypus 0:dd6685f1343e 711 deleteSelf(); //deletes the shape from the array
domplatypus 0:dd6685f1343e 712 if((position[0]+x < 79)&(position[0]+x>0)) { // if within the x bounds of the screen
domplatypus 0:dd6685f1343e 713 position[0] = position[0] + x; //changes the x position
domplatypus 0:dd6685f1343e 714 addSelf(); // adds object according to the new position
domplatypus 0:dd6685f1343e 715 } else { // if out of bounds deactivate the laser
domplatypus 0:dd6685f1343e 716 active = 0;
domplatypus 0:dd6685f1343e 717 }
domplatypus 0:dd6685f1343e 718 }
domplatypus 0:dd6685f1343e 719 };
domplatypus 0:dd6685f1343e 720 /**
domplatypus 0:dd6685f1343e 721 @brief initialises the laser properties
domplatypus 0:dd6685f1343e 722 */
domplatypus 0:dd6685f1343e 723 Laser laserInit();
domplatypus 0:dd6685f1343e 724 /**
domplatypus 0:dd6685f1343e 725 @brief laser object
domplatypus 0:dd6685f1343e 726 */
domplatypus 0:dd6685f1343e 727 Laser laser1 = laserInit();
domplatypus 0:dd6685f1343e 728 /**
domplatypus 0:dd6685f1343e 729 @brief laser object
domplatypus 0:dd6685f1343e 730 */
domplatypus 0:dd6685f1343e 731 Laser laser2 = laserInit();
domplatypus 0:dd6685f1343e 732 /**
domplatypus 0:dd6685f1343e 733 @brief laser object
domplatypus 0:dd6685f1343e 734 */
domplatypus 0:dd6685f1343e 735 Laser laser3 = laserInit();
domplatypus 0:dd6685f1343e 736 /**
domplatypus 0:dd6685f1343e 737 @brief laser object
domplatypus 0:dd6685f1343e 738 */
domplatypus 0:dd6685f1343e 739 Laser laser4 = laserInit();
domplatypus 0:dd6685f1343e 740 /**
domplatypus 0:dd6685f1343e 741 @brief laser object matrix
domplatypus 0:dd6685f1343e 742 */
domplatypus 0:dd6685f1343e 743 Laser laser[4] = {laser1,laser2,laser3,laser4};