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:
5:0b0651ac7832
Parent:
4:673eb9735d44
Child:
6:8bbdb70bc11c
--- a/PlayerObject.cpp	Sat Jun 08 11:24:05 2013 +0000
+++ b/PlayerObject.cpp	Sat Jun 08 14:40:47 2013 +0000
@@ -5,10 +5,18 @@
  *
  */
 
+// Define this for debugging messages.
+#undef CHATTY
+
+#ifdef CHATTY
+    #include "mbed.h"
+    extern Serial pc;
+#endif
+
 #include "PlayerObject.h"
 // #include "SoundManager.h"
 // #include "Sounds.h"
-// #include "FrameCounter.h"
+#include "FrameCounter.h"
 
 // Bullet velocity information.
 BulletVelocities PlayerObject::bulletVelocities( FromPixel( 2 ), FromPixel( 2 ) );
@@ -38,15 +46,20 @@
 /* MOVE THE GAME OBJECT */
 /************************/
 void PlayerObject::ProtectedMove( void ) {
-#if 0
   // Do nothing if controls are not specified.
   if( controls != (PanelControls*)NULL ) {
     // Read joysticks and buttons. Buttons are not used.
     UInt16 map = controls->GetInputs();
     // Extract bits relating to joystick 1 (player movement).
     UInt16 joy1Map = ( map >> PanelControls::Joy1 ) & 0x0F;
+    #ifdef CHATTY
+        pc.printf( "Moving player. Joy 1 = %04X.\r\n", (int)joy1Map );
+    #endif
     // Fetch velocities associated with this combination of joystick inputs.
     const Int16Pair *pair = playerVelocities.GetVelocities( joy1Map );
+    #ifdef CHATTY
+        pc.printf( "dx = %d. dy = %d.\r\n", (int)pair->X, (int)pair->Y );
+    #endif
     // Add on velocities to player coordinates.
     Xco += pair->X;
     Yco += pair->Y;
@@ -64,24 +77,25 @@
         // Try and start a new bullet.
         if( playerBullets.StartBullet( Xco, Yco, pair->X, pair->Y ) ) {
           // If bullet was started then make a bullet sound.
+          #if 0
           SoundManager::Instance.PlaySound( Sounds::FireGun, 0, 0 );
+          #endif
         }
         // Reset countdown until another bullet can start.
         bulletCountdown = 8;
       }
     }
   }
-#endif
 }
 
 /************************/
 /* DRAW THE GAME OBJECT */
 /************************/
+// Pass pointer to Gameduino to draw on in gd.
 // This is only called after it has been established that the
 // game object is visible.
-void PlayerObject::Draw( void ) {
-#if 0
-  SpriteTransform transform;
+void PlayerObject::Draw( Gameduino *gd ) {
+  Gameduino::Rotation transform;
   SpriteImageId imageId;
   // Check controls have been specified.
   if( controls != (PanelControls*)NULL ) {
@@ -92,7 +106,7 @@
     bool leftFootUp = ( ( FrameCounter & 4 ) != 0 );
     if( map & PanelControls::Left2 ) {
       // Firing to the left.
-      transform = STNormal;
+      transform = Gameduino::None;
       if( map & PanelControls::Up2 ) {
         // Firing left and up.
         imageId = leftFootUp ? PlayerGunUpLeftFootUpImage : PlayerGunUpRightFootUpImage;
@@ -108,7 +122,7 @@
     }
     else if( map & PanelControls::Right2 ) {
       // Firing to the right.
-      transform = STFlipX;
+      transform = Gameduino::FlipX;
       if( map & PanelControls::Up2 ) {
         // Firing right and up. Image is flipped so left foot becomes right foot.
         imageId = leftFootUp ? PlayerGunUpRightFootUpImage : PlayerGunUpLeftFootUpImage;
@@ -124,18 +138,17 @@
     }
     else {
       // Firing up, down or not firing.
-      transform = leftFootUp ? STNormal : STFlipX;
+      transform = leftFootUp ? Gameduino::None : Gameduino::FlipX;
       // Use a different image if firing up.
       imageId = ( map & PanelControls::Up2 ) ? PlayerBothGunsUpImage : PlayerImage;
     }
   }
   else {
     // Controls have not been specified so use standing still image.
-    transform = STNormal;
+    transform = Gameduino::None;
     imageId = PlayerImage;
   }
-  GD.sprite( SpriteNumber, ToPixel( Xco ), ToPixel( Yco ), imageId, 0, transform, GoodGuy );
-#endif
+  gd->sprite( SpriteNumber, ToPixel( Xco ), ToPixel( Yco ), imageId, 0, transform, GoodGuy );
 }
 
 /*************************/