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:
Sat Apr 18 18:05:11 2015 +0000
Parent:
20:993c12c6a7bc
Child:
22:e5bfe0e7c508
Commit message:
post high score; pre enter name menu

Changed in this revision

tower.h Show annotated file Show diff for this revision Revisions of this file
--- a/tower.h	Sat Apr 18 05:43:48 2015 +0000
+++ b/tower.h	Sat Apr 18 18:05:11 2015 +0000
@@ -46,6 +46,10 @@
 // player's score
 int score = 0;
 
+int highScore1 = 5;
+int highScore2 = 3;
+int highScore3 = 1;
+
 // difficulty - number of pixels hazards incrememnt by
 int fall = 2;
 
@@ -289,7 +293,7 @@
 
 // resets back to initial values
 void resetGame()
-{
+{   
     score = 0;
 
     a1 = 22;
@@ -812,6 +816,33 @@
     lcd.printString("OFF",33,10);//title
 }
 
+// if any of the high scores are beaten, they are replaced.
+void newScore()
+{   
+    int n;
+    
+    // if player beats High Score 3, replace it with new score
+    if(score >= highScore3) {
+        n = score;
+        highScore3 = n;
+    }
+    // if player beats High Score 3 and 2, replace HighScore2 with new score
+    if(score >= highScore2) {
+        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;
+
+    }
+}
+
 // actual game
 void game(int& exitFlag, int& exitOption)
 {
@@ -860,11 +891,14 @@
                 a8 = a8+=2;
                 ninjaBoundaries();
             }
+           
+            /////////////////////readWrite();
+            
             if (joystick.direction == CENTRE)
                 serial.printf(" CENTRE\n");
             if (joystick.direction == UNKNOWN)
                 serial.printf(" Unsupported direction\n");
-
+            
             // integer to represent character being
             // struck by falling object
             int contactPoint = 0;
@@ -881,6 +915,7 @@
             // 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
@@ -951,20 +986,20 @@
     lcd.printString("High Scores",10,0);//title
 
     // players high scores - highest first
-    char highScore1[14];//create buffer for strings
-    char highScore2[14];
-    char highScore3[14];
+    char buffer1[14];//create buffer for strings
+    char buffer2[14];
+    char buffer3[14];
 
-    int player1 = sprintf(highScore1,"1.DRT.....99",score);//insert buffer
-    int player2 = sprintf(highScore2,"2.NRG.....98",score);//insert buffer
-    int player3 = sprintf(highScore3,"3.GRT.....10",score);//insert buffer
+    int player1 = sprintf(buffer1,"1.DRT.....%i",highScore1);//insert scores
+    int player2 = sprintf(buffer2,"2.NRG.....%i",highScore2);//into buffers
+    int player3 = sprintf(buffer3,"3.GRT.....%i",highScore3);
 
     if (player1 <= 14)  //ensure length is smaller than screen
-        lcd.printString(highScore1,5,2);//display
+        lcd.printString(buffer1,5,2);//display
     if (player2 <= 14)  //ensure length is smaller than screen
-        lcd.printString(highScore2,5,3);//display
+        lcd.printString(buffer2,5,3);//display
     if (player3 <= 14)  //ensure length is smaller than screen
-        lcd.printString(highScore3,5,4);//display
+        lcd.printString(buffer3,5,4);//display
 
     while(1) {
         actionButtons();//select