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

Revision:
6:8bbdb70bc11c
Parent:
5:0b0651ac7832
Child:
10:bfa1c307c99d
--- 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
 }
 
 /*************************************************************************/