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:
Mon Jun 10 20:02:28 2013 +0000
Parent:
11:2ddaf46e95cb
Child:
13:50779b12ff51
Commit message:
Changed so you can specify how many humans you want on each level. Mainly messing around with LevelDescriptor and LevelCollection classes.

Changed in this revision

LevelCollection.cpp Show annotated file Show diff for this revision Revisions of this file
LevelDescriptor.cpp Show annotated file Show diff for this revision Revisions of this file
LevelDescriptor.h Show annotated file Show diff for this revision Revisions of this file
LevelNormal.cpp Show annotated file Show diff for this revision Revisions of this file
LevelNormal.h Show annotated file Show diff for this revision Revisions of this file
--- a/LevelCollection.cpp	Sun Jun 09 19:58:49 2013 +0000
+++ b/LevelCollection.cpp	Mon Jun 10 20:02:28 2013 +0000
@@ -36,36 +36,54 @@
 // Not a real level. This is attract mode.
 static Level0 level0;
 
-// Level descriptors.
-static const UInt8 ld0[] = { ENDDESCRIPTOR };
-static const UInt8 ld1[] = { Grunt, 5, Crusher, 5, ENDDESCRIPTOR };
-static const UInt8 ld2[] = { Grunt, 10, Brain, 2, ENDDESCRIPTOR };
-static const UInt8 ld3[] = { Grunt, 10, Crusher, 8, ENDDESCRIPTOR };
-static const UInt8 ld4[] = { Grunt, 12, Crusher, 6, Brain, 2, ENDDESCRIPTOR };
-static const UInt8 ld5[] = { Grunt, 12, Brain, 4, BlueMeany, 2, ENDDESCRIPTOR };
-static const UInt8 ld6[] = { Grunt, 5, Crusher, 8, Brain, 1, BlueMeany, 3, ENDDESCRIPTOR };
-static const UInt8 ld7[] = { Brain, 15, ENDDESCRIPTOR };
-static const UInt8 ld8[] = { Grunt, 3, Brain, 2, BlueMeany, 5, ENDDESCRIPTOR };
-static const UInt8 ld9[] = { Grunt, 1, BlueMeany, 10, ENDDESCRIPTOR };
-static const UInt8 ld10[] = { Brain, 5, BlueMeany, 10, ENDDESCRIPTOR };
-static const UInt8 ld11[] = { Grunt, 5, Crusher, 5, Brain, 10, ENDDESCRIPTOR };
-static const UInt8 ld12[] = { Grunt, 10, Brain, 5, BlueMeany, 9, ENDDESCRIPTOR };
-static const UInt8 ld13[] = { BlueMeany, 15, ENDDESCRIPTOR };
-static const UInt8 ld14[] = { Brain, 20, ENDDESCRIPTOR };
-static const UInt8 ld15[] = { Grunt, 32, BlueMeany, 1, ENDDESCRIPTOR };
-static const UInt8 ld16[] = { Grunt, 10, Crusher, 30, ENDDESCRIPTOR };
-static const UInt8 ld17[] = { Brain, 25, ENDDESCRIPTOR };
-static const UInt8 ld18[] = { Grunt, 16, Brain, 16, ENDDESCRIPTOR };
-static const UInt8 ld19[] = { Grunt, 16, Brain, 16, BlueMeany, 5, ENDDESCRIPTOR };
-static const UInt8 ld20[] = { Brain, 15, BlueMeany, 15, ENDDESCRIPTOR };
+// Data for enemies on each level.
+static const UInt8 e0 [] = { ENDDESCRIPTOR };
+static const UInt8 e1 [] = { Grunt, 5, Crusher, 5, ENDDESCRIPTOR };
+static const UInt8 e2 [] = { Grunt, 10, Brain, 2, ENDDESCRIPTOR };
+static const UInt8 e3 [] = { Grunt, 10, Crusher, 8, ENDDESCRIPTOR };
+static const UInt8 e4 [] = { Grunt, 12, Crusher, 6, Brain, 2, ENDDESCRIPTOR };
+static const UInt8 e5 [] = { Grunt, 12, Brain, 4, BlueMeany, 2, ENDDESCRIPTOR };
+static const UInt8 e6 [] = { Grunt, 5, Crusher, 8, Brain, 1, BlueMeany, 3, ENDDESCRIPTOR };
+static const UInt8 e7 [] = { Brain, 15, ENDDESCRIPTOR };
+static const UInt8 e8 [] = { Grunt, 3, Brain, 2, BlueMeany, 5, ENDDESCRIPTOR };
+static const UInt8 e9 [] = { Grunt, 1, BlueMeany, 10, ENDDESCRIPTOR };
+static const UInt8 e10 [] = { Brain, 5, BlueMeany, 10, ENDDESCRIPTOR };
+static const UInt8 e11 [] = { Grunt, 5, Crusher, 5, Brain, 10, ENDDESCRIPTOR };
+static const UInt8 e12 [] = { Grunt, 10, Brain, 5, BlueMeany, 9, ENDDESCRIPTOR };
+static const UInt8 e13 [] = { BlueMeany, 15, ENDDESCRIPTOR };
+static const UInt8 e14 [] = { Brain, 20, ENDDESCRIPTOR };
+static const UInt8 e15 [] = { Grunt, 32, BlueMeany, 1, ENDDESCRIPTOR };
+static const UInt8 e16 [] = { Grunt, 10, Crusher, 30, ENDDESCRIPTOR };
+static const UInt8 e17 [] = { Brain, 25, ENDDESCRIPTOR };
+static const UInt8 e18 [] = { Grunt, 16, Brain, 16, ENDDESCRIPTOR };
+static const UInt8 e19 [] = { Grunt, 16, Brain, 16, BlueMeany, 5, ENDDESCRIPTOR };
+static const UInt8 e20 [] = { Brain, 15, BlueMeany, 15, ENDDESCRIPTOR };
 
-// Array pointing to level data for each level.
-static const UInt8* const levelDescriptors[ LEVELCOUNT ] = {
-    ld0, ld1, ld2, ld3, ld4,
-    ld5, ld6, ld7, ld8, ld9,
-    ld10, ld11, ld12, ld13, ld14,
-    ld15, ld16, ld17, ld18, ld19,
-    ld20,
+// Array containing level data for each level.
+// First parameter is number of humans.
+// Second parameter points to an array describing enemies on the level.
+static const LevelDescriptor levelDescriptors[ LEVELCOUNT ] = {
+    LevelDescriptor( 0, e0 ),
+    LevelDescriptor( 5, e1 ),
+    LevelDescriptor( 6, e2 ),
+    LevelDescriptor( 5, e3 ),
+    LevelDescriptor( 6, e4 ),
+    LevelDescriptor( 8, e5 ),
+    LevelDescriptor( 8, e6 ),
+    LevelDescriptor( 8, e7 ),
+    LevelDescriptor( 8, e8 ),
+    LevelDescriptor( 8, e9 ),
+    LevelDescriptor( 8, e10 ),
+    LevelDescriptor( 8, e11 ),
+    LevelDescriptor( 8, e12 ),
+    LevelDescriptor( 12, e13 ),
+    LevelDescriptor( 8, e14 ),
+    LevelDescriptor( 16, e15 ),
+    LevelDescriptor( 16, e16 ),
+    LevelDescriptor( 16, e17 ),
+    LevelDescriptor( 16, e18 ),
+    LevelDescriptor( 16, e19 ),
+    LevelDescriptor( 24, e20 ),
 };
 
 /***************/
@@ -84,7 +102,7 @@
   }
   else {
     // Fetch level descriptor for this level and create a Level from it.
-    Level *level = new LevelNormal( levelDescriptors[ levelNumber ] );
+    Level *level = new LevelNormal( levelDescriptors + levelNumber );
     // Tag it with the correct level number before returning it.
     level->LevelNumber = levelNumber;
     return level;
--- a/LevelDescriptor.cpp	Sun Jun 09 19:58:49 2013 +0000
+++ b/LevelDescriptor.cpp	Mon Jun 10 20:02:28 2013 +0000
@@ -11,13 +11,11 @@
 /*****************************************/
 /* GET COUNT FOR A PARTICULAR ENEMY TYPE */
 /*****************************************/
-// Pass pointer to array containing data in data parameter.
-// The array alternates between enemy type and count and MUST
-// be terminated with a byte of value ENDDESCRIPTOR.
 // Pass type of enemy to fetch count for in et.
 // Returns number of enemies of the given type on this level.
-UInt8 LevelDescriptor::GetEnemyCount( const UInt8 *data, EnemyType et ) {
+UInt8 LevelDescriptor::GetEnemyCount( EnemyType et ) const {
     bool found = false;
+    const UInt8 *data = EnemyData;
     while( ! found && ( *data != ENDDESCRIPTOR ) ) {
         if( *data == (UInt8)et ) {
             found = true;
--- a/LevelDescriptor.h	Sun Jun 09 19:58:49 2013 +0000
+++ b/LevelDescriptor.h	Mon Jun 10 20:02:28 2013 +0000
@@ -17,18 +17,41 @@
 
   public :
 
+    // Number of humans.
+    UInt8 HumanCount;
+    
+    // Array containing enemy data.
+    // The array alternates between enemy type and count and MUST
+    // be terminated with a byte of value ENDDESCRIPTOR.
+    const UInt8* EnemyData;
+    
+    /***************/
+    /* CONSTRUCTOR */
+    /***************/
+    // Pass number of humans on level in hc.
+    // Pass array of data defining enemies in ed.
+    // The array alternates between enemy type and count and MUST
+    // be terminated with a byte of value ENDDESCRIPTOR.
+    LevelDescriptor( UInt8 hc, const UInt8 *ed ) {
+        HumanCount = hc;
+        EnemyData = ed;
+    }
+    
+    /**************/
+    /* DESTRUCTOR */
+    /**************/
+    virtual ~LevelDescriptor() {
+    }
+    
     // Used to mark the end of the descriptor array.
     #define ENDDESCRIPTOR ((UInt8)0xFF)
     
     /*****************************************/
     /* GET COUNT FOR A PARTICULAR ENEMY TYPE */
     /*****************************************/
-    // Pass pointer to array containing data in data parameter.
-    // The array alternates between enemy type and count and MUST
-    // be terminated with a byte of value ENDDESCRIPTOR.
     // Pass type of enemy to fetch count for in et.
     // Returns number of enemies of the given type on this level.
-    static UInt8 GetEnemyCount( const UInt8 *data, EnemyType et );
+    UInt8 GetEnemyCount( EnemyType et ) const;
     
   private :
 
--- a/LevelNormal.cpp	Sun Jun 09 19:58:49 2013 +0000
+++ b/LevelNormal.cpp	Mon Jun 10 20:02:28 2013 +0000
@@ -31,7 +31,7 @@
 /* CONSTRUCTOR */
 /***************/
 // Pass pointer to level descriptor data in data parameter.
-LevelNormal::LevelNormal( const UInt8 *data ) :
+LevelNormal::LevelNormal( const LevelDescriptor *data ) :
     descriptorData( data )
 {
     // Normal levels are always dynamically alocated.
@@ -286,12 +286,12 @@
 /**************/
 // Returns code indicating how level ended.
 Level::LevelExitCode LevelNormal::Play( void ) {
-  UInt8 humanCount, enemyCount = 0;
+  UInt8 enemyCount = 0;
   GameObject **ptr = dataForLevel.Enemies;
   // Repeat for all enemy types.
   for( UInt8 et = 0; et < (int)EnemyTypeCount; ++et ) {
     // Get number of this enemy type on this level.
-    UInt8 eCount = LevelDescriptor::GetEnemyCount( descriptorData, (EnemyType)et );
+    UInt8 eCount = descriptorData->GetEnemyCount( (EnemyType)et );
     // Create required number of enemies.
     for( UInt8 eNum = 0; eNum < eCount; ++eNum ) {
         if( enemyCount < LevelData::MaxEnemies ) {
@@ -303,11 +303,11 @@
         }
     }
   }
-  // Humans.
-  #define HUMANCOUNT 6
-  HumanObject humans[ HUMANCOUNT ];
+  // Create required number of humans.
+  HumanObject humans[ LevelData::MaxHumans ];
   ptr = dataForLevel.Humans;
-  humanCount = ( HUMANCOUNT > LevelData::MaxHumans ) ? LevelData::MaxHumans : HUMANCOUNT;
+  UInt8 humanCount = descriptorData->HumanCount;
+  humanCount = ( humanCount > LevelData::MaxHumans ) ? LevelData::MaxHumans : humanCount;
   for( UInt8 i = 0; i < humanCount; ++i ) {
     *ptr++ = humans + i;
   }
--- a/LevelNormal.h	Sun Jun 09 19:58:49 2013 +0000
+++ b/LevelNormal.h	Mon Jun 10 20:02:28 2013 +0000
@@ -26,7 +26,7 @@
     /* CONSTRUCTOR */
     /***************/
     // Pass pointer to level descriptor data in data parameter.
-    LevelNormal( const UInt8 *data );
+    LevelNormal( const LevelDescriptor *data );
 
     /**************/
     /* DESTRUCTOR */
@@ -56,7 +56,7 @@
     LevelData dataForLevel;
     
     // Descriptor array of bytes.
-    const UInt8 *descriptorData;
+    const LevelDescriptor *descriptorData;
     
     // Current instance being processed.
     static LevelNormal *currentInstance;