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:
Sat Jun 08 15:50:38 2013 +0000
Parent:
5:0b0651ac7832
Child:
7:e72691603fd3
Commit message:
Player can now fire bullets and they move. Mayhem!

Changed in this revision

GameObject.cpp Show annotated file Show diff for this revision Revisions of this file
GameObject.h Show annotated file Show diff for this revision Revisions of this file
GameRobotRic.cpp 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
PlayerObject.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/GameObject.cpp	Sat Jun 08 14:40:47 2013 +0000
+++ b/GameObject.cpp	Sat Jun 08 15:50:38 2013 +0000
@@ -7,7 +7,7 @@
 
 #include "GameObject.h"
 #include "GameObjectLocator.h"
-// #include "ArenaConst.h"
+#include "ArenaConst.h"
 #include "GDExtra.h"
 
 /**********************************/
@@ -20,23 +20,21 @@
 // Pass number of pointers in the array in objectCount.
 // Pass pointer to a sprite number in spriteNumber. This number is incremented by this method.
 void GameObject::InitialiseAll( GameObject **objects, UInt8 objectCount, UInt8 *spriteNumber ) {
-#if 0
-  GameObject *object;
-  for( UInt8 i = 0; i < objectCount; ++i ) {
-    object = objects[ i ];
-    if( object != (GameObject*)NULL ) {
-      // Use next sprite number.
-      object->SpriteNumber = *spriteNumber;
-      // Position object randomly.
-      GameObjectLocator::Locate( object );
-      // Restrict movement to arena.
-      object->MovementRestricted = true;
-      object->Bounds = &ArenaRectangle;
-    }
+    GameObject *object;
+    for( UInt8 i = 0; i < objectCount; ++i ) {
+        object = objects[ i ];
+        if( object != (GameObject*)NULL ) {
+            // Use next sprite number.
+            object->SpriteNumber = *spriteNumber;
+            // Position object randomly.
+            GameObjectLocator::Locate( object );
+            // Restrict movement to arena.
+            object->MovementRestricted = true;
+            object->Bounds = &ArenaRectangle;
+        }
         // Next sprite number.
         (*spriteNumber)++;
-  }
-#endif
+    }
 }
 
 /****************************/
@@ -67,10 +65,10 @@
 /****************************/
 /* DRAW AN ARRAY OF OBJECTS */
 /****************************/
+// Pass pointer to Gameduino to draw on in gd.
 // Pass pointer to array of pointers to GameObjects in objects.
 // Pass number of pointers in the array in objectCount.
-void GameObject::DrawAll( GameObject **objects, UInt8 objectCount ) {
-#if 0
+void GameObject::DrawAll( Gameduino *gd, GameObject **objects, UInt8 objectCount ) {
   GameObject *object;
   for( UInt8 i = 0; i < objectCount; ++i ) {
     object = objects[ i ];
@@ -81,14 +79,13 @@
       // and the sprite should be hidden.
       if( ! object->Visible ) {
         objects[ i ] = (GameObject*)NULL;
-        GDExtra::HideSprite( object->SpriteNumber );
+        GDExtra::HideSprite( gd, object->SpriteNumber );
       }
       else {
-        object->Draw();
+        object->Draw( gd );
       }
     }
   }
-#endif
 }
 
 /************************************************/
@@ -115,13 +112,13 @@
 /****************************************************/
 /* FIND COLLISIONS WITH ALL THE OBJECTS IN AN ARRAY */
 /****************************************************/
+// Pass pointer to Gameduino in gd parameter.
 // Pass pointer to array of pointers to GameObjects in objects.
 // Pass number of pointers in the array in objectCount.
 // Pass pointer to a function that takes two UInt8 parameters in func.
 // The first parameter is the index of the object in the objects array that hit something.
 // The second parameter is the sprite number of the sprite which it hit.
-void GameObject::FindCollisions( GameObject **objects, UInt8 objectCount, void (*func)( UInt8, UInt8 ) ) {
-#if 0
+void GameObject::FindCollisions( Gameduino *gd, GameObject **objects, UInt8 objectCount, void (*func)( UInt8, UInt8 ) ) {
   GameObject *object;
   UInt8 hitSpriteNumber;
   // Repeat for each non-null object in the array.
@@ -129,7 +126,7 @@
     object = objects[ i ];
     if( object != (GameObject*)NULL ) {
       // Get sprite number that has collided with the sprite number of the object.
-      hitSpriteNumber = GD.rd( COLLISION + object->SpriteNumber );
+      hitSpriteNumber = gd->rd( Gameduino::COLLISION + object->SpriteNumber );
       // If result is 0xFF then no collision was found.
       if( hitSpriteNumber != 0xFF ) {
         // Collision, so call function to deal with it.
@@ -137,7 +134,6 @@
       }
     }
   }
-#endif
 }
 
 /*************************************************************************/
--- a/GameObject.h	Sat Jun 08 14:40:47 2013 +0000
+++ b/GameObject.h	Sat Jun 08 15:50:38 2013 +0000
@@ -199,9 +199,10 @@
     /****************************/
     /* DRAW AN ARRAY OF OBJECTS */
     /****************************/
+    // Pass pointer to Gameduino to draw on in gd.
     // Pass pointer to array of pointers to GameObjects in objects.
     // Pass number of pointers in the array in objectCount.
-    static void DrawAll( GameObject **objects, UInt8 objectCount );
+    static void DrawAll( Gameduino *gd, GameObject **objects, UInt8 objectCount );
 
     /************************************************/
     /* FIND AN UNUSED OBJECT IN AN ARRAY OF OBJECTS */
@@ -216,12 +217,13 @@
     /****************************************************/
     /* FIND COLLISIONS WITH ALL THE OBJECTS IN AN ARRAY */
     /****************************************************/
+    // Pass pointer to Gameduino in gd parameter.
     // Pass pointer to array of pointers to GameObjects in objects.
     // Pass number of pointers in the array in objectCount.
     // Pass pointer to a function that takes two UInt8 parameters in func.
     // The first parameter is the index of the object in the objects array that hit something.
     // The second parameter is the sprite number of the sprite which it hit.
-    static void FindCollisions( GameObject **objects, UInt8 objectCount, void (*func)( UInt8, UInt8 ) );
+    void FindCollisions( Gameduino *gd, GameObject **objects, UInt8 objectCount, void (*func)( UInt8, UInt8 ) );
     
     /*************************************************************************/
     /* FIND AN OBJECT WITH A PARTICULAR SPRITE NUMBER IN AN ARRAY OF OBJECTS */
--- a/GameRobotRic.cpp	Sat Jun 08 14:40:47 2013 +0000
+++ b/GameRobotRic.cpp	Sat Jun 08 15:50:38 2013 +0000
@@ -49,9 +49,11 @@
 /*****************/
 // This NEVER exits.
 void GameRobotRic::Play( void ) {
-#ifdef CHATTY
-    pc.puts( "Program has restarted!\r\n" );
-#endif
+    // Change baud rate on PC serial link.
+    pc.baud( 115200 );
+    #ifdef CHATTY
+        pc.puts( "Program has restarted!\r\n" );
+    #endif
     // Make a digital output for use as the Gameduino chip select pin. Deselect it.
     DigitalOut gameduinoCS( p8 );
     gameduinoCS = 1;
--- a/LevelNormal.cpp	Sat Jun 08 14:40:47 2013 +0000
+++ b/LevelNormal.cpp	Sat Jun 08 15:50:38 2013 +0000
@@ -328,7 +328,7 @@
             // Draw the player.
             player->Draw( gd );
             // Draw the player's bullets.
-            GameObject::DrawAll( player->GetBullets(), BulletManager::MaxBullets );
+            GameObject::DrawAll( gd, player->GetBullets(), BulletManager::MaxBullets );
             // Increment the frame counter.
             FrameCounter++;
             // After first redraw play level start sound and wait for it to end.
@@ -373,9 +373,9 @@
                 // enemies on it.
                 if( ! allEnemiesAreDead ) {
                     allEnemiesAreDead = EnemyObject::AreAllIndestructable(
-                                            (const EnemyObject**)DataForLevel->Enemies,
-                                            LevelData::MaxEnemies
-                                        );
+                        (const EnemyObject**)DataForLevel->Enemies,
+                        LevelData::MaxEnemies
+                    );
                 }
                 // Move all the humans.
                 GameObject::MoveAll( DataForLevel->Humans, LevelData::MaxHumans );
--- a/PlayerObject.cpp	Sat Jun 08 14:40:47 2013 +0000
+++ b/PlayerObject.cpp	Sat Jun 08 15:50:38 2013 +0000
@@ -72,10 +72,16 @@
       UInt16 joy2Map = ( map >> PanelControls::Joy2 ) & 0x0F;
       // Only start a bullet if at least one joystick contact is closed.
       if( joy2Map != 0 ) {
+        #ifdef CHATTY
+            pc.puts( "Trying to start a new bullet.\r\n" );
+        #endif
         // Fetch velocities associated with this combination of joystick inputs.
         pair = bulletVelocities.GetVelocities( joy2Map );
         // Try and start a new bullet.
         if( playerBullets.StartBullet( Xco, Yco, pair->X, pair->Y ) ) {
+            #ifdef CHATTY
+                pc.printf( "Bullet started at %d, %d with velocities %d, %d.\r\n", (int)Xco, (int)Yco, (int)pair->X, (int)pair->Y );
+            #endif
           // If bullet was started then make a bullet sound.
           #if 0
           SoundManager::Instance.PlaySound( Sounds::FireGun, 0, 0 );