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:
Tue Jun 11 19:29:04 2013 +0000
Parent:
12:81926431fea7
Child:
14:46a353b2a8e8
Commit message:
Added virtual LevelRestart method to EnemyObject so that enemies can reset themselves to a particular state when a level restarts after player dies. This currently used in BlueMeanyObject to reset velocities to zero.

Changed in this revision

BlueMeanyObject.h Show annotated file Show diff for this revision Revisions of this file
EnemyObject.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
--- a/BlueMeanyObject.h	Mon Jun 10 20:02:28 2013 +0000
+++ b/BlueMeanyObject.h	Tue Jun 11 19:29:04 2013 +0000
@@ -32,13 +32,13 @@
     virtual ~BlueMeanyObject() {
     }
     
-        /*****************************/
-        /* GET TYPE OF ENEMY THIS IS */
-        /*****************************/
-        // Returns enemy type.
-        virtual EnemyType GetEnemyType( void ) {
-            return BlueMeany;
-        }
+    /*****************************/
+    /* GET TYPE OF ENEMY THIS IS */
+    /*****************************/
+    // Returns enemy type.
+    virtual EnemyType GetEnemyType( void ) {
+        return BlueMeany;
+    }
 
     /*******************************************************/
     /* GET NUMBER OF POINTS AWARDED FOR KILLING THIS ENEMY */
@@ -48,6 +48,16 @@
       return 0x10;  // BCD!
     }
 
+    /*****************************************************************/
+    /* PERFORM ANY INIITALISATION REQUIRED AT LEVEL START OR RESTART */
+    /*****************************************************************/
+    // Derived classes should override this if necessary.
+    virtual void LevelRestart( void ) {
+        // Bring Blue Meany to a halt at the start of the level.
+        hVelocity = 0;
+        vVelocity = 0;
+    }
+    
     /************************/
     /* MOVE THE GAME OBJECT */
     /************************/
--- a/EnemyObject.h	Mon Jun 10 20:02:28 2013 +0000
+++ b/EnemyObject.h	Tue Jun 11 19:29:04 2013 +0000
@@ -1,112 +1,120 @@
-/*
- * SOURCE FILE : EnemyObject.h
- *
- * Base class for enemy objects.
- *
- */
-
-#ifndef EnemyObjectIncluded
-  
-  #define EnemyObjectIncluded
-
-  #include "GameObject.h"
-  #include "PlayerObject.h"
-    #include "EnemyType.h"
-
-  class EnemyObject : public GameObject {
-    
-  public :
-
-        enum {
-            Indestructable = 0xFF,
-        };
-
-        // Number of hit points remaining.
-        // When this reaches zero the enemy dies.
-        // However, if this has the special value Indestructable then enemy cannot be killed.
-        UInt8 HitPoints;
-        
-        // Set to true of the enemy squashes humans.
-        bool SquashesHumans;
-        
-        // Pointer to array of pointers to enemies.
-        // Some enemies may need to add new enemies (such as bullets or new spawning enemies) to this array.
-        GameObject **Enemies;
-        
-    /***************/
-    /* CONSTRUCTOR */
-    /***************/
-    EnemyObject() :
-            HitPoints( 1 ),
-            SquashesHumans( false ),
-            Enemies( (GameObject**)NULL ),
-      chaseObject( &defaultChaseObject )
-    {
-    }
-
-    /**************/
-    /* DESTRUCTOR */
-    /**************/
-    virtual ~EnemyObject() {
-    }
-    
-    /************************/
-    /* GET GAME OBJECT TYPE */
-    /************************/
-    // Returns type of game object.
-    virtual GameObjectTypes GetType( void ) {
-      return EnemyObjectType;
-    }
-
-        /*****************************/
-        /* GET TYPE OF ENEMY THIS IS */
-        /*****************************/
-        // Returns enemy type.
-        virtual EnemyType GetEnemyType( void ) = 0;
-        
-    /*******************************************************/
-    /* GET NUMBER OF POINTS AWARDED FOR KILLING THIS ENEMY */
-    /*******************************************************/
-    // Returns number of points (in BCD).
-    virtual UInt8 GetPoints( void ) = 0;
-
-    /***********************/
-    /* SET OBJECT TO CHASE */
-    /***********************/
-    // Pass pointer to object to chase in co.
-    void SetChaseObject( GameObject *co ) {
-      chaseObject = co;
-    }
-    
-        /********************************************/
-        /* INFORM ENEMY IT HAS BEEN HIT BY A BULLET */
-        /********************************************/
-        // Default implementation does nothing but if special behaviour
-        // is required in a derived class then this should be overridden.
-        // Note that this does NOT deal with determining if the enemy is dead or not.
-        // An enemy ALWAYS dies if HitPoints reaches zero.
-        virtual void RegisterHitByBullet( void ) {}
-        
-        /*****************************************************/
-        /* CHECK IF ALL SURVIVING ENEMIES ARE INDESTRUCTABLE */
-        /*****************************************************/
-        // Pass pointer to array of pointers to EnemyObjects in enemies.
-        // Pass number of pointers in the array in enemyCount.
-        static bool AreAllIndestructable( const EnemyObject **enemies, UInt8 enemyCount );
-        
-  protected :
-
-    // Object to chase.
-    GameObject *chaseObject;
-    
-  private :
-  
-    // Default object to chase.
-    static PlayerObject defaultChaseObject;
-    
-  };
-    
-#endif
-
-/* END of EnemyObject.h */
+/*
+ * SOURCE FILE : EnemyObject.h
+ *
+ * Base class for enemy objects.
+ *
+ */
+
+#ifndef EnemyObjectIncluded
+  
+  #define EnemyObjectIncluded
+
+  #include "GameObject.h"
+  #include "PlayerObject.h"
+    #include "EnemyType.h"
+
+  class EnemyObject : public GameObject {
+    
+  public :
+
+    enum {
+        Indestructable = 0xFF,
+    };
+
+    // Number of hit points remaining.
+    // When this reaches zero the enemy dies.
+    // However, if this has the special value Indestructable then enemy cannot be killed.
+    UInt8 HitPoints;
+    
+    // Set to true of the enemy squashes humans.
+    bool SquashesHumans;
+    
+    // Pointer to array of pointers to enemies.
+    // Some enemies may need to add new enemies (such as bullets or new spawning enemies) to this array.
+    GameObject **Enemies;
+        
+    /***************/
+    /* CONSTRUCTOR */
+    /***************/
+    EnemyObject() :
+            HitPoints( 1 ),
+            SquashesHumans( false ),
+            Enemies( (GameObject**)NULL ),
+      chaseObject( &defaultChaseObject )
+    {
+    }
+
+    /**************/
+    /* DESTRUCTOR */
+    /**************/
+    virtual ~EnemyObject() {
+    }
+    
+    /************************/
+    /* GET GAME OBJECT TYPE */
+    /************************/
+    // Returns type of game object.
+    virtual GameObjectTypes GetType( void ) {
+      return EnemyObjectType;
+    }
 
+    /*****************************/
+    /* GET TYPE OF ENEMY THIS IS */
+    /*****************************/
+    // Returns enemy type.
+    virtual EnemyType GetEnemyType( void ) = 0;
+        
+    /*******************************************************/
+    /* GET NUMBER OF POINTS AWARDED FOR KILLING THIS ENEMY */
+    /*******************************************************/
+    // Returns number of points (in BCD).
+    virtual UInt8 GetPoints( void ) = 0;
+
+    /***********************/
+    /* SET OBJECT TO CHASE */
+    /***********************/
+    // Pass pointer to object to chase in co.
+    void SetChaseObject( GameObject *co ) {
+      chaseObject = co;
+    }
+
+    /*****************************************************************/
+    /* PERFORM ANY INIITALISATION REQUIRED AT LEVEL START OR RESTART */
+    /*****************************************************************/
+    // Derived classes should override this if necessary.
+    virtual void LevelRestart( void ) {
+    }
+        
+    /********************************************/
+    /* INFORM ENEMY IT HAS BEEN HIT BY A BULLET */
+    /********************************************/
+    // Default implementation does nothing but if special behaviour
+    // is required in a derived class then this should be overridden.
+    // Note that this does NOT deal with determining if the enemy is dead or not.
+    // An enemy ALWAYS dies if HitPoints reaches zero.
+    virtual void RegisterHitByBullet( void ) {}
+    
+    /*****************************************************/
+    /* CHECK IF ALL SURVIVING ENEMIES ARE INDESTRUCTABLE */
+    /*****************************************************/
+    // Pass pointer to array of pointers to EnemyObjects in enemies.
+    // Pass number of pointers in the array in enemyCount.
+    static bool AreAllIndestructable( const EnemyObject **enemies, UInt8 enemyCount );
+        
+  protected :
+
+    // Object to chase.
+    GameObject *chaseObject;
+    
+  private :
+  
+    // Default object to chase.
+    static PlayerObject defaultChaseObject;
+    
+  };
+    
+#endif
+
+/* END of EnemyObject.h */
+
+
--- a/LevelNormal.cpp	Mon Jun 10 20:02:28 2013 +0000
+++ b/LevelNormal.cpp	Tue Jun 11 19:29:04 2013 +0000
@@ -49,6 +49,8 @@
 /* INITIALISE LEVEL */
 /********************/
 // Pass pointer to Gameduino to draw on in gd.
+// Note that this is called at the start of every level but also when the player
+// is killed and the level restarts with the remaining enemies.
 void LevelNormal::InitialiseLevel( Gameduino *gd )
 {
     // Note that if you re-arrange the following code you may need to adjust the
@@ -66,6 +68,9 @@
     for( UInt8 e = 0; e < LevelData::MaxEnemies; ++e ) {
         object = (EnemyObject*)dataForLevel.Enemies[ e ];
         if( object != (EnemyObject*)NULL ) {
+            // Perform any further initialisation required
+            // at level start or restart.
+            object->LevelRestart();
             // Get enemy to chase the player.
             object->SetChaseObject( player );
             // Pass array of all enemies to this enemy.
@@ -384,9 +389,6 @@
             }
             // If player was killed then play death march and wait for it to finish.
             if( playerIsDead ) {
-                #ifdef CHATTY
-                    pc.puts( "Player got killed.\r\n" );
-                #endif
                 // Player got killed.
                 PlaySoundAndWait( Sounds::PlayerDead );
                 // One less life for player.
@@ -397,9 +399,6 @@
                 gameIsOver = ( player->Lives == 0 );
                 // If game is not over then re-initialise level using any remaining enemies.
                 if( ! gameIsOver ) {
-                    #ifdef CHATTY
-                        pc.puts( "Game is over.\r\n" );
-                    #endif
                     // Remove all objects that do not survive a level restart (like enemy bullets).
                     GameObject::RemoveUnretainedObjects( dataForLevel.Enemies, LevelData::MaxEnemies );
                     InitialiseLevel( gd );