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

Dependencies:   ConfigFile N5110 PowerControl beep mbed

Revision:
24:eb80956e2e95
Parent:
23:548299d45a60
Child:
25:70048c7e02c7
--- a/tower.h	Sun Apr 19 22:43:03 2015 +0000
+++ b/tower.h	Mon Apr 20 15:28:01 2015 +0000
@@ -2,6 +2,10 @@
 // change this to alter tolerance of joystick direction
 #define DIRECTION_TOLERANCE 0.05
 
+#include <string>
+
+//using namespace :: std;
+
 // VCC,SCE,RST,D/C,MOSI,SCLK,LED - set pins for LCD
 N5110 lcd(p7,p8,p9,p10,p11,p13,p22);
 
@@ -79,20 +83,20 @@
 int randY5 = 0;
 int randY6 = 0;
 
-// struct for choosing initials 
-struct State{
-        char output;
-        int nextState[2];
-    };
-    typedef const struct State STYP;
+// struct for choosing initials
+struct State {
+    char output;
+    int nextState[2];
+};
+typedef const struct State STYP;
 
-int state = 0;
+int state = 0;//integer for changing states
 
 // array for Alphabet
 STYP fsm[26] = {
-    
-    //output//timedelay//nextstate//previousstate//
-    
+
+    //output//nextstate//previousstate//
+
     {'A',{1,25}},
     {'B',{2,0}},
     {'C',{3,1}},
@@ -852,7 +856,7 @@
 }
 
 // if any of the high scores are beaten, they are replaced.
-// player enters initials using array
+// player enters initials using struct
 void newScore()
 {
     if(score >= highScore3) {
@@ -862,6 +866,7 @@
         lcd.printString("High Score!!",7,0);//title
         lcd.printString("Enter ID",19,4);//title
         int n;//local variable used for storing temporary global variable
+        int initial = 0;
 
         // if player beats High Score 3, replace it with new score
         if(score >= highScore3) {
@@ -883,9 +888,9 @@
             highScore1 = n;
         }
         while(1) {
-            
+
             actionButtons();
-            
+
             // joystick selection
             if (printFlag) {//if flag set, clear flag,print joystick values
                 printFlag = 0;
@@ -902,31 +907,46 @@
                     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");
+                    initial = initial++;
+                    if (initial > 2)initial = 2;
+                }
                 // Centre / Unknown orientation
                 if (joystick.direction == CENTRE)
                     serial.printf(" CENTRE\n");
                 if (joystick.direction == UNKNOWN)
                     serial.printf(" Unsupported direction\n");
             }
-            
-            char buffer1[26];//create buffer for strings
-            char buffer2[26];
-            char buffer3[26];
 
-            int initial1 = sprintf(buffer1,"%c",fsm[state].output);//insert scores
-            int initial2 = sprintf(buffer2,"%c",fsm[state].output);//into buffers
-            int initial3 = sprintf(buffer3,"%c",fsm[state].output);
+            char buffer1[14];//create buffer for strings
+            char buffer2[14];
+            char buffer3[14];
 
-            if (initial1 <= 26)  //ensure length is smaller than screen
-                lcd.printString(buffer1,25,26);//display
-            if (initial2 <= 26)  //ensure length is smaller than screen
-                lcd.printString(buffer2,37,26);//display
-            if (initial3 <= 26)  //ensure length is smaller than screen
-                lcd.printString(buffer3,49,26);//display
+            if (initial == 0) {
+                int initial1 = sprintf(buffer1,"%c",fsm[state].output);//insert scores}
+                if (initial1 <= 14)  //ensure length is smaller than screen
+                    lcd.printString(buffer1,25,26);//display
+            }
+            if(initial == 1) {
+                int initial2 = sprintf(buffer2,"%c",fsm[state].output);//into buffers
+                if (initial2 <= 14)  //ensure length is smaller than screen
+                    lcd.printString(buffer2,37,26);//display
+            }
+            if(initial == 2) {
+                int initial3 = sprintf(buffer3,"%c",fsm[state].output);
+                if (initial3 <= 14)  //ensure length is smaller than screen
+                    lcd.printString(buffer3,49,26);//display
+            }
+            //inwhile
 
-            
-            //inwhile
-                
         }
     }
 }
@@ -1073,13 +1093,15 @@
     lcd.clear();//clear screen
     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];
+    
+    char name1 = 'D';
 
-    int player1 = sprintf(buffer1,"1.DRT.....%i",highScore1);//insert scores
+    int player1 = sprintf(buffer1,"1.%c.....%i",name1,highScore1);//insert scores
     int player2 = sprintf(buffer2,"2.NRG.....%i",highScore2);//into buffers
     int player3 = sprintf(buffer3,"3.GRT.....%i",highScore3);