Version of Robotron arcade game using LPC1768, a Gameduino shield, a serial EEPROM (for high scores), two microswitch joysticks and two buttons plus a box to put it in. 20 levels of mayhem.

Dependencies:   25LCxxx_SPI CommonTypes Gameduino mbed

Files at this revision

API Documentation at this revision

Comitter:
RichardE
Date:
Sun Jun 16 08:54:57 2013 +0000
Parent:
16:d0b142ba4362
Child:
18:70190f956a24
Commit message:
New high score entry routines completed and working.

Changed in this revision

GameRobotRic.cpp Show annotated file Show diff for this revision Revisions of this file
HighScoreEntry.cpp Show annotated file Show diff for this revision Revisions of this file
HighScoreEntry.h Show annotated file Show diff for this revision Revisions of this file
HighScoreTable.h Show annotated file Show diff for this revision Revisions of this file
--- a/GameRobotRic.cpp	Sat Jun 15 19:27:36 2013 +0000
+++ b/GameRobotRic.cpp	Sun Jun 16 08:54:57 2013 +0000
@@ -16,7 +16,10 @@
 #include "ArenaConst.h"            // gameplay arena constants
 
 // Define following for debugging messages to serial port.
-#define CHATTY
+#undef CHATTY
+
+// Define following to reset all high scores on power up.
+#undef RESETHIGHSCORES
 
 // Number of lives player starts with.
 #define START_LIVES 5
@@ -108,11 +111,10 @@
     // Restrict players movement.
     player.MovementRestricted = true;
     player.Bounds = &ArenaRectangle;
-    
-    // REMOVE THIS!
-    CheckForHighScore( &gd, &highScores, 0x10000 );
-    
-    
+    // If configured to do so reset high scores.
+    #ifdef RESETHIGHSCORES
+        highScores.WriteEEPROMDefaults();
+    #endif    
     // Repeat forever.
     while( true ) {
         // Get level specified by level number.
--- a/HighScoreEntry.cpp	Sat Jun 15 19:27:36 2013 +0000
+++ b/HighScoreEntry.cpp	Sun Jun 16 08:54:57 2013 +0000
@@ -27,10 +27,14 @@
 #define GRIDX 5
 #define GRIDY 16
 #define GRIDCOLUMNS 20
-#define GRIDROWS 3
+#define GRIDROWS 4                  // 3 rows for characters, 1 row for special functions
 #define GRIDCOLUMNSPACING 2
 #define GRIDROWSPACING 2
 
+// Some text.
+const char HighScoreEntry::textDelete[] = "DELETE";
+const char HighScoreEntry::textEnter[] = "ENTER";
+
 /***************/
 /* CONSTRUCTOR */
 /***************/
@@ -72,6 +76,7 @@
 /* INITIALISE GRID */
 /*******************/
 void HighScoreEntry::InitialiseGrid( void ) {
+    // First initialise rows used for characters.
     UInt8 code = PlayerName::MinChar;
     UInt8 x = GRIDX, y = GRIDY;
     UInt8 columnNumber = 0, rowNumber = 0;;
@@ -97,8 +102,34 @@
         }
         code++;
     }
+    // Add another row for special functions.
+    columnNumber = 0;
+    x = GRIDX;
+    y += GRIDROWSPACING;
+    row = grid.GetRow( rowNumber++ );
+    if( row != (FieldRow*)NULL ) {
+        AddTextCell( x, y, row, textDelete );
+        AddTextCell( x, y, row, textEnter );
+    }
 }
 
+/***************************************/
+/* ADD A CELL CONTAINING TEXT TO A ROW */
+/***************************************/
+// Pass character coordinates in x and y. These will be updated.
+// Pass row to which cells should be added in row.
+// Pass text which is to be contained in cell in text.
+void HighScoreEntry::AddTextCell( UInt8 &x, UInt8 &y, FieldRow *row, const char *text ) {
+    int len = strlen( text );
+    FieldCell *cell = new FieldCell();
+    cell->Rect.X1 = x - 1;
+    cell->Rect.Y1 = y - 1;
+    cell->Rect.X2 = x + len;
+    cell->Rect.Y2 = y + 1;
+    row->AddCell( cell );
+    x += ( len + 1 );
+ }
+
 /*********************/
 /* GET A PLAYER NAME */
 /*********************/
@@ -161,7 +192,7 @@
       }
       if( inputs & PanelControls::Button1 ) {
           // Button 1 adds a character or possibly does something special.
-          if( cursorRow < grid.GetRowCount() ) {
+          if( cursorRow < grid.GetRowCount() - 1 ) {
               char newChar = (char)( PlayerName::MinChar + cursorRow * GRIDCOLUMNS + cursorColumn );
               name->Name[ charIndex ] = newChar;
               if( charIndex < PlayerName::Length - 1 ) {
@@ -169,7 +200,8 @@
               }
           }
           else {
-              // TODO. Special functions.
+              // Last row contains special functions.
+              SpecialFunction( gd, cursorColumn, name, done );
           }
           // Draw modified name.
           gd->waitvblank();
@@ -195,6 +227,29 @@
   WaitControls( gd, controls, false );
 }
 
+/************************************************************************/
+/* PERFORM A SPECIAL FUNCTION TRIGGERED FROM A CELL ON LAST ROW OF GRID */
+/************************************************************************/
+// Pass pointer to Gameduino to draw on in gd.
+// Pass function number in funcNum (this is the cursor column number).
+// Pass player name in name.
+// Pass reference to done flag in done.
+void HighScoreEntry::SpecialFunction( Gameduino *gd, UInt8 funcNum, PlayerName *name, bool &done ) {
+    switch( funcNum ) {
+    
+    case 0 :        // DELETE function
+        if( charIndex > 0 ) {
+            name->Name[ charIndex-- ] = ' ';
+        }
+        break;
+        
+    case 1 :        // ENTER function
+        done = true;
+        break;
+        
+    }
+}
+
 /*********************/
 /* WAIT FOR CONTROLS */
 /*********************/
@@ -236,8 +291,8 @@
   gd->putstr( 2, 2,  "   CONGRATULATIONS : YOU HAVE A HIGH SCORE!" );
   gd->putstr( 2, 4,  "PLEASE ENTER YOUR NAME USING THE LEFT JOYSTICK" );
   gd->putstr( 2, 6,  " TO MOVE THE CURSOR. PRESS THE LEFT BUTTON TO" );
-  gd->putstr( 2, 8,  "  ENTER EACH LETTER. MOVE CURSOR TO FOOT OF" );
-  gd->putstr( 2, 10, " SCREEN AND PRESS LEFT BUTTON WHEN FINISHED." );
+  gd->putstr( 2, 8,  "  ENTER EACH LETTER. MOVE CURSOR TO \"ENTER\"" );
+  gd->putstr( 2, 10, "     AND PRESS LEFT BUTTON WHEN FINISHED." );
   // Draw player's name.
   DrawName( gd, name );
   // Draw character grid.
@@ -251,6 +306,7 @@
 /***************************/
 // Pass pointer to Gameduino to draw on in gd.
 void HighScoreEntry::DrawGrid( Gameduino *gd ) {
+    // Draw rows containing characters.
     UInt8 code = PlayerName::MinChar;
     UInt8 x = GRIDX, y = GRIDY;
     UInt8 columnNumber = 0;
@@ -268,6 +324,12 @@
             x += GRIDCOLUMNSPACING;
         }
     }
+    // Draw row containing special functions.
+    x = GRIDX;
+    y += GRIDROWSPACING;
+    gd->putstr( x, y, textDelete );
+    x += ( strlen( textDelete ) + 1 );
+    gd->putstr( x, y, textEnter );
 }
 
 /********************************/
--- a/HighScoreEntry.h	Sat Jun 15 19:27:36 2013 +0000
+++ b/HighScoreEntry.h	Sun Jun 16 08:54:57 2013 +0000
@@ -48,12 +48,33 @@
     
     // Grid around which cursor moves.
     FieldGrid grid;
-    
+
+    // Some text.
+    static const char textDelete[];
+    static const char textEnter[];
+        
     /*******************/
     /* INITIALISE GRID */
     /*******************/
     void InitialiseGrid( void );
     
+    /***************************************/
+    /* ADD A CELL CONTAINING TEXT TO A ROW */
+    /***************************************/
+    // Pass character coordinates in x and y. These will be updated.
+    // Pass row to which cells should be added in row.
+    // Pass text which is to be contained in cell in text.
+    void AddTextCell( UInt8 &x, UInt8 &y, FieldRow *row, const char *text );
+
+    /************************************************************************/
+    /* PERFORM A SPECIAL FUNCTION TRIGGERED FROM A CELL ON LAST ROW OF GRID */
+    /************************************************************************/
+    // Pass pointer to Gameduino to draw on in gd.
+    // Pass function number in funcNum (this is the cursor column number).
+    // Pass player name in name.
+    // Pass reference to done flag in done.
+    void SpecialFunction( Gameduino *gd, UInt8 funcNum, PlayerName *name, bool &done );
+
     /*********************/
     /* WAIT FOR CONTROLS */
     /*********************/
--- a/HighScoreTable.h	Sat Jun 15 19:27:36 2013 +0000
+++ b/HighScoreTable.h	Sun Jun 16 08:54:57 2013 +0000
@@ -50,6 +50,11 @@
     // Returns true if EEPROM is valid.
     bool EEPROMValid( void );
     
+    /****************************/
+    /* WRITE DEFAULTS TO EEPROM */
+    /****************************/
+    void WriteEEPROMDefaults( void );
+    
     /*************************/
     /* GET CAPACITY OF TABLE */
     /*************************/
@@ -98,11 +103,6 @@
     // Pointer to EEPROM that holds high scores.
     Ser25LCxxx *eeprom;
         
-    /****************************/
-    /* WRITE DEFAULTS TO EEPROM */
-    /****************************/
-    void WriteEEPROMDefaults( void );
-    
   };
 
 #endif