Kyle Sturgess / Mbed 2 deprecated GameProject

Dependencies:   N5110 mbed

Fork of DocTest by Craig Evans

Revision:
3:b78d65300f24
Parent:
2:5446154a4028
--- a/main.cpp	Sat May 09 09:38:26 2015 +0000
+++ b/main.cpp	Sun May 10 20:07:18 2015 +0000
@@ -10,7 +10,7 @@
     ///minimal amount of code in the main, see All() for more
     All();
 }
-
+///all of the function that would normally reside in the main
 void All(){
     calibrateJoystick(); ///get the centred values of the joystick
     bright=5;
@@ -40,8 +40,8 @@
     c=1;
 }
 
-
-void powerDown(){///goes into deep power down if nothing happens for a minute
+///goes into deep power down if nothing happens for a set time
+void powerDown(){
     power++;
     if(power==55){
         red1=0;
@@ -78,11 +78,11 @@
         yel=0.1*bright;
         buzzer=0.4;
     }
-    if(power>60){
-        red1=0;
-        red2=0.1*bright;
-        red3=0;
-        yel=0.1*bright;
+    if(power>=60){
+        red1=0.1*bright;
+        red2=0;
+        red3=0.1*bright;
+        yel=0;
         buzzer=0.9;
         DeepPowerDown();
     }
@@ -90,7 +90,7 @@
 
 
 ///the start screen, shows up at the begining and when the player runs out of lives
-///links to the options menu, the highscores, the level select, and the game
+///links to the options menu, the highscores, the level select etc.
 void start(){
     power=0;
     clear();
@@ -155,12 +155,14 @@
     lcd.clearPixel(i,j);
     clear();
 }
+///function called to escape back to the main menu
 void menus(){
     power=0;
     lcd.clearPixel(i,j);
     clear();
     timeout.attach_us(&toggle,10);
 }
+///function called to toggle, clear, or set various flags
 void toggle(){
     power=0;
     l=!l;
@@ -171,6 +173,7 @@
     b=!b;
     startFlag=1;
 }
+///the options menu, links to the reset, brightness, and end game
 void Options(){
     power=0;
     lcd.clearPixel(i,j);
@@ -245,25 +248,31 @@
     lcd.clearPixel(i,j);
     clear();
 }
+///debouncing code for the light() function
 void Light(){
     timeout.attach_us(&light,100);
 }
+///debouncing code for the dark() function
 void Dark(){
     timeout.attach_us(&dark,100);
 }
+///function called to increase the LED and backlight birghtness variable
 void light(){
     bright++;
     if(bright>10)
         bright=10;
 }
+///function called to decrease the LED and backlight brightness variable
 void dark(){
     bright--;
     if(bright<1)
         bright=1;
 }
+///function called to set the LCD backlight brightness from the brigtness variable
 void brightness(){
     lcd.setBrightness(0.1*bright);
 }
+///the level select menu, allows the player to choose between three levels by moveing the joystick left, down, or right
 void Levels(){
     power=0;
     push.rise(&menus);
@@ -345,6 +354,8 @@
     lcd.clearPixel(i,j);
     clear();
 }
+///the scores menu, displays the currently saved high score for the three levels
+/// moving the joystick different directions displays the scores for the different levels
 void Score(){
     power=0;
     lcd.clearPixel(i,j);
@@ -423,11 +434,12 @@
     fprintf(fp,"%i",score1);///prints the integer value for the score to file
     fclose(fp);
 }
+///reads the currently saved score for the first level
 void scoreRead1(){
     int Score1;///tells it that the value to be read is an integer value
     
     FILE *fp1 = fopen("/local/score1.txt","r");///opens score1.txt
-    fscanf(fp1,"%i",&Score1);///searches the file for an integer followed by a string
+    fscanf(fp1,"%i",&Score1);///searches the file for an integer 
     fclose(fp1);
     
     char Points1[14];///bufer to store the points value
@@ -442,11 +454,12 @@
     fprintf(fp2,"%i",score2);///prints the integer value for the score to file
     fclose(fp2);
 }
+///reads the currently saved score for the second level
 void scoreRead2(){
     int Score2;///tells it that the value to be read is an integer value
     
     FILE *fp3 = fopen("/local/score2.txt","r");///opens score2.txt
-    fscanf(fp3,"%i",&Score2);///searches the file for an integer followed by a string
+    fscanf(fp3,"%i",&Score2);///searches the file for an integer
     fclose(fp3);
     
     char Points2[14];///bufer to store the points value
@@ -461,18 +474,20 @@
     fprintf(fp4,"%i",score3);///prints the integer value for the score to file
     fclose(fp4);
 }
+///reads the curently saved score for the third level
 void scoreRead3(){
     int Score3;///tells it that the value to be read is an integer value
     
     FILE *fp5 = fopen("/local/score3.txt","r");///opens score3.txt
-    fscanf(fp5,"%i",&Score3);///searches the file for an integer followed by a string
+    fscanf(fp5,"%i",&Score3);///searches the file for an integer 
     fclose(fp5);
     
     char Points3[14];///bufer to store the points value
     sprintf(Points3,"%i",Score3);///sends the score to the buffer
     lcd.printString(Points3,30,3);///prints the score to the LCD
 }
-
+///function called to quite the game and return to the menu
+///, has the same effect on the game as running out of lives while playing
 void pause(){
     power=0;
     lcd.clearPixel(i,j);
@@ -482,7 +497,7 @@
     life=0;
 }
 ///all of the functions that make up the main game
-void mainGame(){
+void mainGame(){ 
     count.attach(&counter,1.0);///counts every second for the lives function etc.
     flash.attach(&Flash,0.25);
     push.rise(&pause);
@@ -555,7 +570,7 @@
     clear();
 }
 
-///mini game
+///mini game fashioned after the style of etch-a-sketch
 void endGame(){
     flash.attach(&Flash,0.25);
     red1=0;
@@ -704,7 +719,7 @@
 
 ///function that checks if the goal area has been reached
 void winning(){
-        if(j==0){
+        if(j==0){///if the pixel reaches the top top of the screen
             lcd.clearPixel(i,j);
             i=1;
             j=24;
@@ -761,7 +776,7 @@
     if (j<0)
         j=ny-1;
 }
-
+///function called to check if the player is trying to move through a solid object
 void collide1(){    
     int block=0;
     if(joystick.direction==UP){
@@ -870,13 +885,13 @@
     joystick.x0 = xPot;  /// initial positions in the range 0.0 to 1.0 (0.5 if centred exactly)
     joystick.y0 = yPot;
 }
+ /// read current joystick values relative to calibrated values (in range -0.5 to 0.5, 0.0 is centred)
 void updateJoystick(){
-    /// read current joystick values relative to calibrated values (in range -0.5 to 0.5, 0.0 is centred)
     joystick.x = xPot - joystick.x0;
     joystick.y = yPot - joystick.y0;
     /// read button state
     joystick.button = button;
-
+   
     /// calculate direction depending on x,y values
     /// tolerance allows a little lee-way in case joystick not exactly in the stated direction