Code for the space evader game.

Dependencies:   N5110 PowerControl mbed

Files at this revision

API Documentation at this revision

Comitter:
domplatypus
Date:
Mon May 11 11:44:51 2015 +0000
Parent:
0:dd6685f1343e
Commit message:
Version 1.0

Changed in this revision

joystick.cpp Show annotated file Show diff for this revision Revisions of this file
joystick.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
--- a/joystick.cpp	Sun May 10 16:48:46 2015 +0000
+++ b/joystick.cpp	Mon May 11 11:44:51 2015 +0000
@@ -2,7 +2,7 @@
 @file joystick.cpp
  
 @brief Program implementation
- 
+@brief Original code https://developer.mbed.org/users/eencae/code/Joystick/ 
 */
 #include "mbed.h"
 #include "joystick.h"
@@ -32,6 +32,9 @@
 
     // calculate direction depending on x,y values
     // tolerance allows a little lee-way in case joystick not exactly in the stated direction
+    //Direction matrix modified here depending on the direction tolerence
+    // +1 is down/right, 0 is centre and -1 is up/left
+    //modified by Dominic Platt
     if ( fabs(joystick.y) < DIRECTION_TOLERANCE) {
         joystick.direction[0] = 0; //middle for y
     } else if ( joystick.y > DIRECTION_TOLERANCE) {
--- a/joystick.h	Sun May 10 16:48:46 2015 +0000
+++ b/joystick.h	Mon May 11 11:44:51 2015 +0000
@@ -3,6 +3,7 @@
 @brief Header file containing functions prototypes, defines and global variables.
 @brief Joystick header file, with modification from original file
 @brief CHANGEME_H_ and endif added to prevent header file error https://developer.mbed.org/cookbook/Compiler-Error-256
+@brief Original code https://developer.mbed.org/users/eencae/code/Joystick/
 @author Craig A. Evans (Original author)
 @author Dominic J. Platt (Modifications labelled)
 @date   April 2015
@@ -58,6 +59,7 @@
     /*!
       values of 1,0,-1 for each element
       e.g. the matrix of {-1,0} will mean direction is -1 in x directions and 0 in the y direction
+      property added by Dominic Platt
     */
     int direction[2];  // current direction x,y used
     /*@}*/
--- a/main.cpp	Sun May 10 16:48:46 2015 +0000
+++ b/main.cpp	Mon May 11 11:44:51 2015 +0000
@@ -12,7 +12,7 @@
 //external variables printFlag,joystick,pollJoystick,serial and button used
 //button(p18),xPot(p19),yPot(p20) used with external joystick
 #include "PowerControl/PowerControl.h"
-#include "PowerControl/EthernetPowerControl.h" 
+#include "PowerControl/EthernetPowerControl.h"
 int main()
 {
     init();
@@ -21,166 +21,124 @@
     introInit();
     timer.attach(&timerExpired,0.01);
     while(1) {
-
-        if(menuMode&timerFlag) {
+        if(timerFlag) {
             timerFlag = 0;
-            if(counter==20) {
-                menuSet();//runs the menu every 20 counts
-            }
             if(soundOn) {
                 soundActivate(); //activates sound
             }
-            if(counter == 20) {
-                counter=0;//reset the counter
-            }
-            counter++;
-            //timer.detach();
-            //timer.attach(&timerExpired,0.01);//attaching the timer for the next frame
-        } else if(gameOverMode&timerFlag) {
-            //game over mode
-            timerFlag=0;
-            if(counter==20) {
-                gameOverSet();//sets the game over frame every 20 counts
-            }
-            if(soundOn) {
-                soundActivate(); //acitvates sound
-            }
-            if(counter == 20) {
-                counter=0;//reset the counter
+            if(menuMode) {
+                if(counter==20) {
+                    menuSet();//runs the menu every 20 counts
+                }
+            } else if(gameOverMode) {
+                //game over mode
+                if(counter==20) {
+                    gameOverSet();//sets the game over frame every 20 counts
+                }
+                if(soundOn) {
+                    soundActivate(); //acitvates sound
+                }
+            } else if(introMode) {
+                introSet(); //sets the intro frame every count
+                timer.detach();
+                timer.attach(&timerExpired,0.01); //attaching the timer for the next frame
+            } else if(helpMode) {
+                if(buttonFlag) {
+                    menuInit(); //if button pressed go back to the menu
+                }
+                buttonFlag = 0;
             }
-            counter++;
-            //timer.detach();
-            //timer.attach(&timerExpired,0.01);//attaching the timer for the next frame
-        } else if(introMode&timerFlag) {
-            introSet(); //sets the intro frame every count
-            timer.detach();
-            timer.attach(&timerExpired,0.01); //attaching the timer for the next frame
-        } else if(helpMode&timerFlag) {
-            timerFlag = 0;
-            if(buttonFlag) {
-                menuInit(); //if button pressed go back to the menu
-            }
-            buttonFlag = 0;
-            if(counter == 20) {
-                counter=0;//reset the counter
-            }
-            counter++;
-            //timer.detach();
-            //timer.attach(&timerExpired,0.01);
-        }
 
-        else if(highScoreMode&timerFlag) {
-            if(counter==20) {
-                timerFlag = 0;
-                if(buttonFlag) {
-                    menuInit(); //if button pressed bring player back to menu
+            else if(highScoreMode) {
+                if(counter==20) {
+                    if(buttonFlag) {
+                        menuInit(); //if button pressed bring player back to menu
+                    }
+                }
+            } else if(settingsMode) { //runs settingsMode
+                if(counter==20) {
+                    settingsSet();//runs the setting frame
+                }
+            } else if(gameMode) { //game run mode
+                if(roundFlag) {
+                    //if new round flag is set start the next round
+                    roundFlag =0;
+                    roundInit();
+                }
+                if(item.active) {
+                    item.addSelf();//if item has selected add the item to the screen
+                }
+                if(speedState==0) {
+                    //controlling the rate of movement of the players ship and asteroids depending on the speedState
+                    if(counter == 5||counter == 10||counter == 15||counter == 20) {// speed x1.0
+                        if(shipExplodeFlag) {
+                            shipExplode();//if is in explotion stage play explotion frame
+                        } else {
+                            //otherwise move the ship
+                            ship.moveSelf(joystick.direction[0],joystick.direction[1]);
+                        }
+                        for(int i=0; i<8; i++) {
+                            if(asteroid[i].active) {
+                                //move the asteroids that are active
+                                asteroid[i].moveSelf();
+                            }
+                        }
+                    }
+                } else if(speedState==1) {// x1.25
+                    if(counter == 4||counter == 8||counter == 12||counter == 16||counter == 20) {
+                        if(shipExplodeFlag) {
+                            shipExplode();
+                        } else {
+                            ship.moveSelf(joystick.direction[0],joystick.direction[1]);
+                        }
+                        for(int i=0; i<8; i++) {
+                            if(asteroid[i].active) {
+                                asteroid[i].moveSelf();
+                            }
+                        }
+                    }
+                } else if(speedState==2) { //x1.33
+                    if(counter == 3||counter == 6||counter == 9||counter == 12||counter == 15||counter == 18||counter == 20) {
+                        if(shipExplodeFlag) {
+                            shipExplode();
+                        } else {
+                            ship.moveSelf(joystick.direction[0],joystick.direction[1]);
+                        }
+                        for(int i=0; i<8; i++) {
+                            if(asteroid[i].active) {
+                                asteroid[i].moveSelf();
+                            }
+                        }
+                    }
+                } else if(speedState==3) { //x2.5
+                    if(counter == 2||counter == 4||counter == 6||counter == 8||counter == 10||counter == 12||counter == 14||counter == 16||counter == 18||counter == 20) {
+                        if(shipExplodeFlag) {
+                            shipExplode();
+                        } else {
+                            ship.moveSelf(joystick.direction[0],joystick.direction[1]);
+                        }
+                        for(int i=0; i<8; i++) {
+                            if(asteroid[i].active) {
+                                asteroid[i].moveSelf();
+                            }
+                        }
+                    }
+                }
+
+                if(buttonFlag&laserClear) { // fire button pressed
+                    laserActivate();
+                }
+                buttonFlag = 0; //reset the buttonFlag after everytime used
+                laserMove(); //move the laser depending on that which are active
+                check(); //checks the logic of the ships position against asteroids, asteroids against each other and walls, lasers against asteroids
+                if(counter ==3||counter == 6|| counter ==9||counter == 12||counter == 15||counter == 18||counter == 20) {
+                    setScreen(); // refresh the screen once every three 'counts'
                 }
             }
             if(counter == 20) {
                 counter=0;//reset the counter
             }
             counter++;
-            //timer.detach();
-            //timer.attach(&timerExpired,0.01);
-        } else if(settingsMode&timerFlag) { //runs settingsMode
-            timerFlag=0;
-            if(counter==20) {
-                settingsSet();//runs the setting frame
-            }
-            if(soundOn) {
-                soundActivate();
-            }
-            if(counter == 20) {
-                counter=0;//reset the counter
-            }
-            counter++;
-            //timer.detach();
-            //timer.attach(&timerExpired,0.01);
-        } else if(timerFlag&gameMode) { //game run mode
-            timerFlag = 0;
-            if(roundFlag) {
-                //if new round flag is set start the next round
-                roundFlag =0;
-                roundInit();
-            }
-            if(soundOn) {
-                soundActivate();//activates sound
-            }
-            if(item.active) {
-                item.addSelf();//if item has selected add the item to the screen
-            }
-            if(speedState==0) {
-                //controlling the rate of movement of the players ship and asteroids depending on the speedState
-                if(counter == 5||counter == 10||counter == 15||counter == 20) {
-                    if(shipExplodeFlag) {
-                        shipExplode();//if is in explotion stage play explotion frame
-                    } else {
-                        //otherwise move the ship
-                        ship.moveSelf(joystick.direction[0],joystick.direction[1]);
-                    }
-                    for(int i=0; i<8; i++) {
-                        if(asteroidM[i].active) {
-                            //move the asteroids that are active
-                            asteroidM[i].moveSelf();
-                        }
-                    }
-                }
-            } else if(speedState==1) {
-                if(counter == 4||counter == 8||counter == 12||counter == 16||counter == 20) {
-                    if(shipExplodeFlag) {
-                        shipExplode();
-                    } else {
-                        ship.moveSelf(joystick.direction[0],joystick.direction[1]);
-                    }
-                    for(int i=0; i<8; i++) {
-                        if(asteroidM[i].active) {
-                            asteroidM[i].moveSelf();
-                        }
-                    }
-                }
-            } else if(speedState==2) {
-                if(counter == 3||counter == 6||counter == 9||counter == 12||counter == 15||counter == 18||counter == 20) {
-                    if(shipExplodeFlag) {
-                        shipExplode();
-                    } else {
-                        ship.moveSelf(joystick.direction[0],joystick.direction[1]);
-                    }
-                    for(int i=0; i<8; i++) {
-                        if(asteroidM[i].active) {
-                            asteroidM[i].moveSelf();
-                        }
-                    }
-                }
-            } else if(speedState==3) {
-                if(counter == 2||counter == 4||counter == 6||counter == 8||counter == 10||counter == 12||counter == 14||counter == 16||counter == 18||counter == 20) {
-                    if(shipExplodeFlag) {
-                        shipExplode();
-                    } else {
-                        ship.moveSelf(joystick.direction[0],joystick.direction[1]);
-                    }
-                    for(int i=0; i<8; i++) {
-                        if(asteroidM[i].active) {
-                            asteroidM[i].moveSelf();
-                        }
-                    }
-                }
-            }
-
-            if(buttonFlag&laserClear) { // fire button pressed
-                laserActivate();
-            }
-            buttonFlag = 0; //reset the buttonFlag after everytime used
-            laserMove(); //move the laser depending on that which are active
-            check(); //checks the logic of the ships position against asteroids, asteroids against each other and walls, lasers against asteroids
-            if(counter ==3||counter == 6|| counter ==9||counter == 12||counter == 15||counter == 18||counter == 20) {
-                setScreen(); // refresh the screen once every three 'counts'
-            }
-            if(counter == 20) {
-                counter=0;//reset the counter
-            }
-            counter++;
-            //timer.detach();
-            //timer.attach(&timerExpired,0.005);//timerExpired function increased rate for the game
         }
         sleep();// put the mbed to sleep otherwise
     }
@@ -222,7 +180,7 @@
     laserCoolDown = 70;
     rapidFire = 0;
     abilityCounter = 0;
-    titleSelected = 0;
+    optionSelected = 0;
     introMode = 1;
     lcd.init();
     srand(time(NULL));//seedin the random function with the current time for more random functions
@@ -501,17 +459,7 @@
     gameMode = 0;
     gameOverMode =1;
     menuMode = 0;
-    speedState = 0;
-    //http://developer.mbed.org/questions/249/float-or-integer-to-char-or-string-conve/
-    char scoreString[10];
-    //converts score to string
-    sprintf(scoreString,"%d",score);
     lcd.clear();
-    lcd.printString("Game Over",10,0);
-    lcd.printString("Your score was",0,1);
-    //score is printed
-    lcd.printString(scoreString,10,2);
-    lcd.printString("AAA",10,4);
     buttonFlag = 0;
     timer.detach();
     timer.attach(&timerExpired,0.01);
@@ -521,12 +469,12 @@
     //ship position check against asteroids
     for (int j = 0; j<8; j++) {
         //loops through every asteroid
-        if((((asteroidM[j].position[0])>(ship.position[0]-5))&((asteroidM[j].position[0])<(ship.position[0]+5))
-                &((asteroidM[j].position[1])>(ship.position[1]-5))&((asteroidM[j].position[1])<(ship.position[1]+5)))&asteroidM[j].active) {
+        if((((asteroid[j].position[0])>(ship.position[0]-5))&((asteroid[j].position[0])<(ship.position[0]+5))
+                &((asteroid[j].position[1])>(ship.position[1]-5))&((asteroid[j].position[1])<(ship.position[1]+5)))&asteroid[j].active) {
             //if an asteroid overlaps with a ships position
             if(ship.shield) {//if ship shields are up
-                asteroidM[j].active = 0;
-                asteroidM[j].deleteSelf(); //deactivating the asteroid
+                asteroid[j].active = 0;
+                asteroid[j].deleteSelf(); //deactivating the asteroid
                 asteroids--;
                 if(score>50) {//player looses 50 points
                     score = score - 50;
@@ -540,8 +488,8 @@
             } else if((!shipExplodeFlag)&!ship.shield) {
                 shipExplodeFlag = 1;
                 explotionStage = 1;
-                asteroidM[j].active = 0;
-                asteroidM[j].deleteSelf();
+                asteroid[j].active = 0;
+                asteroid[j].deleteSelf();
                 initSound();
                 soundType =2;
             }
@@ -549,26 +497,26 @@
     }
 // checking the asteroids position off each other so they can bounce off each other
     for(int i = 0; i<8; i++) {
-        if(asteroidM[i].active) { //looping through all the active asteroids
+        if(asteroid[i].active) { //looping through all the active asteroids
             for(int j = 0; j<8; j++) {
                 if(i==j) { //if asteroid checked is the actual asteroid of the first for loop move to the next one
                     j++;
                 }
-                if(asteroidM[j].active) {
-                    if((asteroidM[i].position[0]>(asteroidM[j].position[0]-5))&(asteroidM[i].position[0]<(asteroidM[j].position[0]+5))
-                            &(asteroidM[i].position[1]>(asteroidM[j].position[1]-5))&(asteroidM[i].position[1]<(asteroidM[j].position[1]+5))) {
+                if(asteroid[j].active) {
+                    if((asteroid[i].position[0]>(asteroid[j].position[0]-5))&(asteroid[i].position[0]<(asteroid[j].position[0]+5))
+                            &(asteroid[i].position[1]>(asteroid[j].position[1]-5))&(asteroid[i].position[1]<(asteroid[j].position[1]+5))) {
                         // if asteroids collide
                         initSound();
                         soundType =3;// produce a sound
-                        if(asteroidM[i].position[0]>asteroidM[j].position[0]) {//if asteroids x position is greater than the other move forwards
-                            asteroidM[i].xDirection = 1;
-                        } else if(asteroidM[i].position[0]<=asteroidM[j].position[0]) { //if asteroid is behind the other asteroid in the x direction move to the left
-                            asteroidM[i].xDirection = -1;
+                        if(asteroid[i].position[0]>asteroid[j].position[0]) {//if asteroids x position is greater than the other move forwards
+                            asteroid[i].xDirection = 1;
+                        } else if(asteroid[i].position[0]<=asteroid[j].position[0]) { //if asteroid is behind the other asteroid in the x direction move to the left
+                            asteroid[i].xDirection = -1;
                         }
-                        if(asteroidM[i].position[1]>asteroidM[j].position[1]) {//if asteroid is below the other asteroid move down
-                            asteroidM[i].yDirection = 1;
-                        } else if(asteroidM[i].position[1]<=asteroidM[j].position[1])//if asteroid is above the other asteroid move up
-                            asteroidM[i].yDirection = -1;
+                        if(asteroid[i].position[1]>asteroid[j].position[1]) {//if asteroid is below the other asteroid move down
+                            asteroid[i].yDirection = 1;
+                        } else if(asteroid[i].position[1]<=asteroid[j].position[1])//if asteroid is above the other asteroid move up
+                            asteroid[i].yDirection = -1;
                     }
                 }
             }
@@ -577,13 +525,13 @@
     //checking the laser positions against the asteroids
     for(int i = 0; i<4; i++) {
         for (int j = 0; j<8; j++) {
-            if(((asteroidM[j].position[0]>(laser[i].position[0]-5))&(asteroidM[j].position[0]<(laser[i].position[0]+5))
-                    &(asteroidM[j].position[1]>(laser[i].position[1]-5))&(asteroidM[j].position[1]<(laser[i].position[1]+5))&asteroidM[j].active&laser[i].active)) {
+            if(((asteroid[j].position[0]>(laser[i].position[0]-5))&(asteroid[j].position[0]<(laser[i].position[0]+5))
+                    &(asteroid[j].position[1]>(laser[i].position[1]-5))&(asteroid[j].position[1]<(laser[i].position[1]+5))&asteroid[j].active&laser[i].active)) {
                 //if both laser and asteroid is active and they collide inititiate destruction
                 initSound();
                 soundType =2;//play sound
-                asteroidM[j].active = 0;
-                asteroidM[j].deleteSelf(); //deactivating the asteroid
+                asteroid[j].active = 0;
+                asteroid[j].deleteSelf(); //deactivating the asteroid
                 asteroids--;//marking one less asteroid
                 score = score + 10;//player gains point
                 laser[i].active = 0; // deactiviating the laser
@@ -593,8 +541,8 @@
                     if(x==0) {
                         //puts the item to the asteroids position
                         item.active = 1;
-                        item.position[0] = asteroidM[j].position[0];
-                        item.position[1] = asteroidM[j].position[1];
+                        item.position[0] = asteroid[j].position[0];
+                        item.position[1] = asteroid[j].position[1];
                         item.addSelf();
                     }
                 }
@@ -686,7 +634,7 @@
 void gameStart()
 {
     for(int i = 0; i<8; i++) {
-        asteroidM[i].active = 0;
+        asteroid[i].active = 0;
     }
     item.active = 0;
     clearArray();
@@ -723,12 +671,12 @@
 void menuSet()
 {
     //sets the option selected depending on the joystick y direction
-    titleSelected = titleSelected + joystick.direction[1];
+    optionSelected = optionSelected + joystick.direction[1];
     //loops around the menu
-    if(titleSelected>3) {
-        titleSelected = 0;
-    } else if(titleSelected<0) {
-        titleSelected = 3;
+    if(optionSelected>3) {
+        optionSelected = 0;
+    } else if(optionSelected<0) {
+        optionSelected = 3;
     }
     if((joystick.direction[1]==1)||(joystick.direction[1]==-1)) {
         //if joystick moved initiate sound
@@ -746,17 +694,17 @@
     lcd.printString("HighScores",10,3);
     lcd.printString("Help",10,4);
     lcd.printString("Settings",10,5);
-    lcd.printString(">",0,titleSelected+2); // array set according to which titleSelected
-    if(buttonFlag&(titleSelected == 0)) {
+    lcd.printString(">",0,optionSelected+2); // array set according to which optionSelected
+    if(buttonFlag&(optionSelected == 0)) {
         //start option selected
         gameStart();
-    } else if(buttonFlag&(titleSelected == 1)) {
+    } else if(buttonFlag&(optionSelected == 1)) {
         //instruction option selected
         highScoreSet();
-    } else if(buttonFlag&(titleSelected == 2)) {
+    } else if(buttonFlag&(optionSelected == 2)) {
         //instruction option selected
         helpInit();
-    } else if(buttonFlag&(titleSelected == 3)) {
+    } else if(buttonFlag&(optionSelected == 3)) {
         //settings option selected
         settingsInit();
     }
@@ -773,6 +721,7 @@
     }
     char scoreString[10]; //stores the score
     sprintf(scoreString,"%d",score);//converts the users score from an int to a string
+    ////http://developer.mbed.org/questions/249/float-or-integer-to-char-or-string-conve/
     char alphabet [27] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"}; //alphabet matrix defined
     cSelected = cSelected +joystick.direction[0]; //character selected moved depending on the joystick
     if(cSelected>2) { //loops through the characters selected at the boundaries
@@ -814,11 +763,11 @@
     //sets the characters
     lcd.printString("Game Over",10,0);
     lcd.printString("Your score was",0,1);
-    lcd.printString(scoreString,25,2);
-    lcd.printString(name,25,4);
+    lcd.printString(scoreString,35,2);
+    lcd.printString(name,35,4);
     for(int i = 0; i<5; i++) {
         ///draws a line under the selected char
-        lcd.setPixel(25+i+cSelected*6,40);
+        lcd.setPixel(35+i+cSelected*6,40);
     }
     lcd.refresh();
     if(buttonFlag) {
@@ -839,7 +788,7 @@
     //initialise the spawn position, although spawn positions are not needed this function is required to initialise an asteroid object
     initSpawn();
     ship.init();
-    asteroidM[0].init();
+    asteroid[0].init();
     item.init();
     menuMode = 0;
     gameOverMode = 0;
@@ -855,9 +804,9 @@
     ship.position[0] = 0;
     ship.position[1] = 8;
     ship.addSelf();
-    asteroidM[0].position[0] = 0;
-    asteroidM[0].position[1] = 16;
-    asteroidM[0].addSelf();
+    asteroid[0].position[0] = 0;
+    asteroid[0].position[1] = 16;
+    asteroid[0].addSelf();
     item.position[0] = 0;
     item.position[1] = 24;
     item.addSelf();
@@ -879,11 +828,6 @@
     ship.position[1] = 2;
     ship.addSelf();
     setScreen();
-    lcd.printString("Space Evader",0,0);
-    lcd.printString("Start Game",10,2);
-    lcd.printString("HighScores",10,3);
-    lcd.printString("Help",10,4);
-    lcd.printString("Settings",10,5);
     settingsMode = 0;
     gameOverMode = 0;
     gameMode = 0;
@@ -948,8 +892,8 @@
     }
     initSpawn(); // initialises spawn positions
     for(int i = 0; i<roundNumber; i++) {
-        asteroidM[i].init();//initiates asteroids equal to the round number
-        asteroidM[i].active = 1;
+        asteroid[i].init();//initiates asteroids equal to the round number
+        asteroid[i].active = 1;
         asteroids++; // add one to the counter
     }
     roundNumber++; //increment roundNumber
@@ -968,11 +912,11 @@
 void settingsSet()
 {
     //sets the title selected with the joystick
-    titleSelected = titleSelected + joystick.direction[1];
-    if(titleSelected>3) {
-        titleSelected = 0;
-    } else if(titleSelected<0) {
-        titleSelected = 3;
+    optionSelected = optionSelected + joystick.direction[1];
+    if(optionSelected>3) {
+        optionSelected = 0;
+    } else if(optionSelected<0) {
+        optionSelected = 3;
     }
     if((joystick.direction[1]==1)||(joystick.direction[1]==-1)) {
         soundType =3; //sound when joystick moved
@@ -994,7 +938,7 @@
     sprintf(myChar,"%dx",1+speedState); //speed marked
     lcd.printString(myChar,60,1);
     lcd.printString("Walls",7,2);
-    lcd.printString(">",0,titleSelected); //selector depending on option selected
+    lcd.printString(">",0,optionSelected); //selector depending on option selected
     char bufferDate[14]; //presents the time and date
     char bufferTime[14];
     lcd.printString("Back",7,3);
@@ -1004,19 +948,19 @@
     strftime(bufferTime,14,"%T", localtime(&seconds));
     lcd.printString(bufferDate,7,4);
     lcd.printString(bufferTime,7,5);
-    if(buttonFlag&(titleSelected == 0)) {
+    if(buttonFlag&(optionSelected == 0)) {
         sound = !sound;
-    } else if(buttonFlag&(titleSelected == 1)) {
+    } else if(buttonFlag&(optionSelected == 1)) {
         //increments the speed counter if that option is selected
         speedState++;
         if(speedState>3) {
             //reset speedState if to high
             speedState=0;
         }
-    } else if(buttonFlag&(titleSelected == 3)) {
+    } else if(buttonFlag&(optionSelected == 3)) {
         //back to menu
         menuInit();
-    } else if(buttonFlag&(titleSelected == 2)) {
+    } else if(buttonFlag&(optionSelected == 2)) {
         //turn on/off the walls
         walls = !walls;
     }
@@ -1033,7 +977,7 @@
     //initialises the setting screen
     menuMode = 0;
     settingsMode = 1;
-    titleSelected = 0;
+    optionSelected = 0;
     buttonFlag =0;
     settingsSet();
     timer.detach();
@@ -1042,11 +986,11 @@
 void serialISR()
 {
     //sets UNIX time
-    set_time(1430595271);
+    set_time(1431348000);
 }
 void buttonPressed() // toggle direction in ISR
 {
-    if(debounce.read_ms()>150) {//only set flag 150 ms after the last flag was set to filter out the 'bounces'
+    if(debounce.read_ms()>200) {//only set flag 200 ms after the last flag was set to filter out the 'bounces'
         //buttonFlag set when button is pressed
         buttonFlag = 1;
         debounce.reset();//reset the debounce timer
--- a/main.h	Sun May 10 16:48:46 2015 +0000
+++ b/main.h	Mon May 11 11:44:51 2015 +0000
@@ -227,7 +227,7 @@
 /**
 @brief declares which option on the menu the user is currently selecting
 */
-int titleSelected;
+int optionSelected;
 /**
 @brief declares gameOver mode screen
 */
@@ -485,10 +485,10 @@
     ///@param int y Declares the amount of position movement in the y direction in pixel
     void moveSelf(int x, int y) { //moving the shape, x defines whether up down y defines left right
         deleteSelf(); //deletes the shape the the array
-        if((position[0]+x < 79)&(position[0]+x>=0)) { // if within the x bounds of the screen
+        if((position[0]+x <= 79)&(position[0]+x>=0)) { // if within the x bounds of the screen
             position[0] = position[0] + x; //changes the x position
         }
-        if((position[1]+y<43)&(position[1]+y>=0)) { // if within the y bounds of the screen
+        if((position[1]+y<=43)&(position[1]+y>=0)) { // if within the y bounds of the screen
             position[1] = position[1] + y; //changes the y position
         }
         addSelf(); // adds object according to the new position
@@ -547,32 +547,32 @@
 /**
 asteroid class defined
 */
-class asteroid
+class Asteroid
 {
-    //defining our asteroid template class
+    //defining our Asteroid template class
 public: //our entity class is public
     /**
-    declares that asteroid is active
+    declares that Asteroid is active
     */
-    bool active; //declaring whether the asteroid is active or not
+    bool active; //declaring whether the Asteroid is active or not
     /**
-    shape array holding the pixels for the asteroid
+    shape array holding the pixels for the Asteroid
     */
     bool shape[5][5]; // shape array to hold the pixel data
     /**
-    @brief 2 element array to hold the x,y position of the asteroid
+    @brief 2 element array to hold the x,y position of the Asteroid
     */
     int position[2]; // 2 element array to hold x,y components of the entities position
     /**
-    @brief Declares the yDirection the asteroid
+    @brief Declares the yDirection the Asteroid
     */
     int yDirection;
     /**
-    @brief Declares the xDirection the asteroid
+    @brief Declares the xDirection the Asteroid
     */
-    int xDirection; // directon variables to store which direction the asteroid is moving
+    int xDirection; // directon variables to store which direction the Asteroid is moving
     /**
-    @brief adds the asteroid object to the current matrix
+    @brief adds the Asteroid object to the current matrix
     */
     void addSelf() { //adding the shape to the array
         for(int i = 0; i<5; i++) {
@@ -582,7 +582,7 @@
         }
     }
     /**
-    @brief removes the asteroid object to the current matrix
+    @brief removes the Asteroid object to the current matrix
     */
     void deleteSelf() { // deleting the shape from the array
         for(int i = 0; i<5; i++) {
@@ -592,11 +592,11 @@
         }
     }
     /**
-    @brief moves the asteroid object to the current matrix
+    @brief moves the Asteroid object to the current matrix
     */
     void moveSelf() { //moving the shape, x defines whether up down y defines left right
         deleteSelf(); //deletes the shape the the array
-        if((position[0]+xDirection < 79)&(position[0]+xDirection>0)) { // if within the x bounds of the screen
+        if((position[0]+xDirection <= 79)&(position[0]+xDirection>=0)) { // if within the x bounds of the screen
             position[0] = position[0] + xDirection; //changes the x position
         } else if(walls) {
             soundType =3;
@@ -610,7 +610,7 @@
                 position[0] = 0;
             }
         }
-        if((position[1]+yDirection<43)&(position[1]+yDirection>0)) { // if within the y bounds of the screen
+        if((position[1]+yDirection<=43)&(position[1]+yDirection>=0)) { // if within the y bounds of the screen
             position[1] = position[1] + yDirection; //changes the y position
         } else if(walls) {
             soundType =3;
@@ -627,7 +627,7 @@
         addSelf(); // adds object according to the new position
     }
     /**
-    @brief initialises the properties of our asteroid object
+    @brief initialises the properties of our Asteroid object
     */
     void init() {
         int x = getSpawnLocation();
@@ -637,31 +637,31 @@
         yDirection = directionMatrix[rand() % 2];
         active = 0;
         for(int i=0; i <5; i++) {
-            for(int j=0; j<5; j++) { //defining the asteroid array
+            for(int j=0; j<5; j++) { //defining the Asteroid array
                 shape[j][i] = asteroidShape[j][i];
             }
         }
     }
 };
-///instance of our asteroid class
-asteroid asteroid1;
+///instance of our Asteroid class
+Asteroid asteroid1;
 ///instance of our asteroid class
-asteroid asteroid2;
+Asteroid asteroid2;
 ///instance of our asteroid class
-asteroid asteroid3;
+Asteroid asteroid3;
 ///instance of our asteroid class
-asteroid asteroid4;
+Asteroid asteroid4;
 ///instance of our asteroid class
-asteroid asteroid5;
+Asteroid asteroid5;
 ///instance of our asteroid class
-asteroid asteroid6;
+Asteroid asteroid6;
 ///instance of our asteroid class
-asteroid asteroid7;
+Asteroid asteroid7;
 ///instance of our asteroid class
-asteroid asteroid8;
+Asteroid asteroid8;
 
 ///array holding all the asteroid objects
-asteroid asteroidM[8] = {asteroid1,asteroid2,asteroid3,asteroid4,asteroid5,asteroid6,asteroid7,asteroid8};
+Asteroid asteroid[8] = {asteroid1,asteroid2,asteroid3,asteroid4,asteroid5,asteroid6,asteroid7,asteroid8};
 /**
 @brief Laser position, active, pixel data, counterFlag variables
 */