A retro gaming programme, designed for use on a portable embedded system. Incorporates power saving techniques.

Dependencies:   ConfigFile N5110 PowerControl beep mbed

Files at this revision

API Documentation at this revision

Comitter:
el13drt
Date:
Mon Apr 20 22:02:04 2015 +0000
Parent:
29:c17bd5597723
Child:
31:da1a4875c404
Commit message:
ITS WORKING !!!!!!!

Changed in this revision

tower.h Show annotated file Show diff for this revision Revisions of this file
--- a/tower.h	Mon Apr 20 19:27:54 2015 +0000
+++ b/tower.h	Mon Apr 20 22:02:04 2015 +0000
@@ -56,9 +56,9 @@
 int highScore3 = 0;
 
 //player initials
-char player1initials[3];
-char player2initials[3];
-char player3initials[3];
+char player1initials[14];
+char player2initials[14];
+char player3initials[14];
 
 // difficulty - number of pixels hazards incrememnt by
 int fall = 2;
@@ -866,8 +866,8 @@
 // if any of the high scores are beaten, they are replaced.
 // player enters initials using struct
 void newScore()
-{
-    if(score >= highScore3) {
+{   
+    if(score >= highScore3) {//entry condition
 
         lcd.clear();
         backGround();
@@ -875,27 +875,11 @@
         lcd.printString("Enter ID",19,4);//title
         int n;//local variable used for storing temporary global variable
         int initial = 0;//used for isolating which initial is being selected
-        
-        // if player beats High Score 3, replace it with new score
-        if(score >= highScore3 && score<highScore2 ) {
-            n = score;
-            highScore3 = n;
-        }
-        // if player beats High Score 3 and 2, replace HighScore2 with new score
-        if(score >= highScore2 && score< highScore1) {
-            highScore3 = highScore2;
-            n = score;
-            highScore2 = n;
-        }
-        // if player beats High Score 1, 2 and 3, replace highScore1 with new score
-        if(score >= highScore1 ) {
-            highScore3 = highScore2;
-            highScore2 = highScore1;
-            n = score;
-            highScore1 = n;
-        }
+
+        //put conditions here
+
         while(1) {
-            
+
             // joystick selection
             if (printFlag) {//if flag set, clear flag,print joystick values
                 printFlag = 0;
@@ -911,12 +895,10 @@
                     state = state++;
                     if (state > 26)state = 26;
                 }
-
                 if (joystick.direction == LEFT) {
                     serial.printf(" LEFT\n");
                     initial = initial--;
                     if (initial < 0)initial = 0;
-
                 }
                 if (joystick.direction == RIGHT) {
                     serial.printf(" RIGHT\n");
@@ -930,46 +912,54 @@
                     serial.printf(" Unsupported direction\n");
             }
 
-            char buffer1[14];//create buffer for strings
-            char buffer2[14];
-            char buffer3[14];
-            
+            char x[1];//create storage
+            char y[1];//for initials
+            char z[1];
+
             // if initial 3 display selected character
             if (initial == 0) {
-                int initial1 = sprintf(buffer1,"%c",fsm[state].output1);//insert scores}
-                if (initial1 <= 14)  //ensure length is smaller than screen
-                    lcd.printString(buffer1,25,26);//display
+                int initial1 = sprintf(x,"%c",fsm[state].output1);//insert into letter in x
+                lcd.printString(x,25,26);//print x buffer
             }
             // if initial 1 display selected character
             if(initial == 1) {
-                int initial2 = sprintf(buffer2,"%c",fsm[state].output2);//into buffers
-                if (initial2 <= 14)  //ensure length is smaller than screen
-                    lcd.printString(buffer2,37,26);//display
+                int initial2 = sprintf(y,"%c",fsm[state].output2);//insert into letter in y
+                lcd.printString(y,37,26);//print y buffer
             }
             // if initial 2 display selected character
             if(initial == 2) {
-                int initial3 = sprintf(buffer3,"%c",fsm[state].output3);
-                if (initial3 <= 14)  //ensure length is smaller than screen
-                    lcd.printString(buffer3,49,26);//display
+                int initial3 = sprintf(z,"%c",fsm[state].output3);//insert into letter z
+                lcd.printString(z,49,26);//print z buffer
+            }
+            // if player beats High Score 3, replace it with new score
+            if(score >= highScore3 && score<highScore2 ) {
+                n = score;
+                highScore3 = n;
+                //
+                int insert3 = sprintf (player3initials, "3.%s%s%s.....%i",x,y,z,highScore3);
             }
-
-            actionButtons();
-
-            //in while
+            // if player beats High Score 3 and 2, replace HighScore2 with new score
+            if(score >= highScore2 && score< highScore1) {
+                highScore3 = highScore2;
+                n = score;
+                highScore2 = n;
+                int insert2 = sprintf (player2initials, "2.%s%s%s.....%i",x,y,z,highScore2);
+            }
+            // if player beats High Score 1, 2 and 3, replace highScore1 with new score
+            if(score >= highScore1 ) {
+                highScore3 = highScore2;
+                highScore2 = highScore1;
+                n = score;
+                highScore1 = n;
+                int insert1 = sprintf (player1initials, "1.%s%s%s.....%i",x,y,z,highScore1);
+            }
+            // goes back to main menu after storing initials
             if(buttonFlagA) {
                 buttonFlagA = 0;
                 buttonFlagB = 0;
-   
-//                char x = fsm[state].output1;
-//                char y = fsm[state].output2;
-//                char z = fsm[state].output3;
-// 
-//                    int insert1 = sprintf (player1initials, "%c%c%c",x,y,z);
-                
                 break;
             }
         }
-        
     }
 }
 
@@ -986,8 +976,7 @@
         // print score - top left of display
         char buffer[14];//create buffer for string
         int length = sprintf(buffer,"Level:%d",score);//insert buffer
-        if (length <= 14)  //ensure length is smaller than screen
-            lcd.printString(buffer,3,0);//display
+        lcd.printString(buffer,3,0);//display
 
         actionButtons();
         pixelNinja();//set character
@@ -1046,7 +1035,6 @@
             // character has been hit
             // and the game ends
             if ( contactPoint !=0) {
-                //newScore();
                 lcd.printString("Game Over",17,2);
                 lcd.inverseMode();
                 buzzer.beep(2000,0.2);//frequeny/duration
@@ -1062,13 +1050,12 @@
                 buzzer.beep(2000,0.2);
                 wait(0.5);
                 lcd.normalMode();
-                newScore();
+                newScore();//enter initial screen if previous scores are beaten
                 resetGame();
                 break;
             }
             startrek();//clears unset pixels, keeps set pixels
 
-
 /// Exit Menu (Back button pressed)///
             if(buttonFlagB) {
                 buttonFlagB = 0;//reset flags
@@ -1117,21 +1104,12 @@
     backGround();//set background
     lcd.printString("High Scores",10,0);//title
 
-    // players high scores - highest first
-    char buffer1[14];//create buffer for strings
-    char buffer2[14];
-    char buffer3[14];
+    // prints scores with names
+    lcd.printString(player1initials,5,2);//display
 
-    int player1 = sprintf(buffer1,"1.DRT......%i",highScore1);//insert scores
-    int player2 = sprintf(buffer2,"2.HFR......%i",highScore2);//and names in 
-    int player3 = sprintf(buffer3,"3.DEU......%i",highScore3);//to the buffer
+    lcd.printString(player2initials,5,3);//display
 
-    if (player1 <= 14)  //ensure length is smaller than screen
-        lcd.printString(buffer1,5,2);//display
-    if (player2 <= 14)  //ensure length is smaller than screen
-        lcd.printString(buffer2,5,3);//display
-    if (player3 <= 14)  //ensure length is smaller than screen
-        lcd.printString(buffer3,5,4);//display
+    lcd.printString(player3initials,5,4);//display
 
     while(1) {
         actionButtons();//select
@@ -1223,6 +1201,7 @@
     joystick.y0 = yPot;
 }
 
+//reads and updates position of joystick according to voltage readings
 void updateJoystick()
 {
     // read current joystick values relative to calibrated values (in range -0.5 to 0.5, 0.0 is centred)