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:
2:bb0f631a6068
Parent:
1:dfd5eaaf96a3
Child:
3:a6a0cd726ca0
--- a/GameRobotRic.cpp	Wed Jun 05 22:05:41 2013 +0000
+++ b/GameRobotRic.cpp	Thu Jun 06 20:11:28 2013 +0000
@@ -8,8 +8,9 @@
 #include "GameRobotRic.h"          // this module's prototypes
 #include "Types.h"                 // various integer types etc.
 #include "LevelCollection.h"       // all the levels
+#include "sprite.h"                // sprite data
+#include "RobotRicCharacterSet.h"  // character set used in this game
 #if 0
-    #include "RobotRicCharacterSet.h"  // character set used in this game
     #include "GDExtra.h"               // extra Gameduino functions
     #include "GDConst.h"               // a few more Gameduino constants
     #include "ArenaConst.h"            // gameplay arena constants
@@ -54,9 +55,15 @@
 /*****************/
 // This NEVER exits.
 void GameRobotRic::Play( void ) {
-    // Make a digital output for use with Gameduino.
-    DigitalOut cs( p8 );
-    // Initialise an SPI link for communications with Gameduino.
+    // Make a digital output for use as the Gameduino chip select pin. Deselect it.
+    DigitalOut gameduinoCS( p8 );
+    gameduinoCS = 1;
+    // Make a digital output for use as the Gameduino chip select pin. Deselect it.
+    DigitalOut eepromCS( p14 );
+    eepromCS = 1;
+    // Initialise an SPI link for communications with Gameduino and the serial EEPROM.
+    // This is different from how the Maple version of RobotRic did it. It used an
+    // I2C EEPROM.
     // Use pin 5 for MOSI.
     // Use pin 6 for MISO.
     // Use pin 7 for SCK.
@@ -68,24 +75,30 @@
     // Use SPI mode 0.
     spi.format( 8, 0 );
     // Make a Gameduino and pass SPI link and digital output for chip select.
-    Gameduino gd( &spi, &cs );
+    Gameduino gd( &spi, &gameduinoCS );
     // Reset the Gameduino.
     gd.begin();
-    // Lets have a default ASCII character set.
-    gd.ascii();
-    // Display sign on message.
-    gd.putstr( 3, 10, "RobotRic is up and running!" );
-#if 0
-    // Initialise I2C communications (to talk to serial EEPROM).
-  Wire.begin( EEPROM_SDA, EEPROM_SCL );
-    // Initialise serial EEPROM object with EEPROM address of zero.
-    I2CEEPROM eeprom;
-    eeprom.Open( &Wire, ADDRESS_OF_EEPROM, EEPROM_WP );
+    gd.copy( Gameduino::RAM_SPRIMG, sprite_sprimg, sizeof( sprite_sprimg ) );
+    // Copy sprite palette data into Gameduino memory.
+    gd.copy( Gameduino::RAM_SPRPAL, sprite_sprpal, sizeof( sprite_sprpal ) );
+    // Initialise character set pixel data RAM.
+    gd.copy( Gameduino::RAM_CHR, RobotRicCharacterSet::PixelData, ( LAST_CHAR_IN_CHARACTER_SET + 1 ) << 4 );
+    // Initialise character set pixel palette RAM.
+    gd.copy( Gameduino::RAM_PAL, RobotRicCharacterSet::PaletteData, ( LAST_CHAR_IN_CHARACTER_SET + 1 ) << 3 );
+    // Turn off JK collision detection. Every sprite collides with every other.
+    // Did it this way because I could not resolve some problems with wandering humans.
+    // Suppose JK collision detection were used. The player sprite is of type J and humans
+    // are of type K so collisions between them will register allowing humans to be rescued.
+    // However, I also need some enemies (Crushers for example) to be able to collide with
+    // humans so they would need to be J type to collide with humans. But then player and
+    // enemies are both J type and so collisions between players and enemies are not detected.
+    gd.wr( Gameduino::JK_MODE, 0 );
+    // Initialise serial EEPROM object which is on same SPI bus as the Gameduino.
+    SPIEEPROM eeprom( &spi, &eepromCS );
     // Create a high score table that uses the EEPROM.
     HighScoreTable highScores( &eeprom );
-#endif
-  // Start on the attract level.
-  UInt8 levelNumber = LevelCollection::AttractLevel;
+    // Start on the attract level.
+    UInt8 levelNumber = LevelCollection::AttractLevel;
 #if 0
   player.Lives = START_LIVES;
 #endif
@@ -144,7 +157,5 @@
     // Wait a bit.
     wait( (float)2 );
   }
-// Finished with Gameduino.
-gd.end();
 }