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
Diff: GameRobotRic.cpp
- Revision:
- 4:673eb9735d44
- Parent:
- 3:a6a0cd726ca0
- Child:
- 5:0b0651ac7832
--- a/GameRobotRic.cpp Fri Jun 07 20:29:59 2013 +0000 +++ b/GameRobotRic.cpp Sat Jun 08 11:24:05 2013 +0000 @@ -10,13 +10,10 @@ #include "LevelCollection.h" // all the levels #include "sprite.h" // sprite data #include "RobotRicCharacterSet.h" // character set used in this game -#if 0 - #include "GDExtra.h" // extra Gameduino functions - #include "GDConst.h" // a few more Gameduino constants - #include "ArenaConst.h" // gameplay arena constants - #include "I2CEEPROM.h" // for access to serial EEPROM - #include "HighScoreEntry.h" // for getting player's name for high score table -#endif +#include "HighScoreEntry.h" // for getting player's name for high score table +#include "GDExtra.h" // extra Gameduino functions +#include "GDConst.h" // a few more Gameduino constants +#include "ArenaConst.h" // gameplay arena constants // Define following for debugging messages to serial port. #define CHATTY @@ -24,24 +21,16 @@ // Number of lives player starts with. #define START_LIVES 5 -// Pin allocations for I2C communications link. -#define EEPROM_SCL 5 -#define EEPROM_SDA 7 -#define EEPROM_WP 8 - -// Address of EEPROM set using A0, A1 and A2 pins. -#define ADDRESS_OF_EEPROM 0 - // Serial link to PC over USB cable. Globally accessible. Serial pc( USBTX, USBRX ); /**************************/ /* CHECK FOR A HIGH SCORE */ /**************************/ +// Pass pointer to a Gameduino to display on in gd. // Pass pointer to high score table in highScores. // Pass score that was achieved in score. -void GameRobotRic::CheckForHighScore( HighScoreTable *highScores, UInt32 score ) { -#if 0 +void GameRobotRic::CheckForHighScore( Gameduino *gd, HighScoreTable *highScores, UInt32 score ) { UInt8 tablePos; // Enter name into high score table if score is high enough. if( ( tablePos = highScores->GetPositionInTable( player.Score ) ) < highScores->GetCapacity() ) { @@ -49,11 +38,10 @@ // Get player to input name. HighScoreEntry nameGetter; PlayerName name; - nameGetter.GetName( &name, &controls ); + nameGetter.GetName( &name, &controls, gd ); // Add name and score to table. highScores->Add( tablePos, &name, score ); } -#endif } /*****************/ @@ -61,9 +49,9 @@ /*****************/ // This NEVER exits. void GameRobotRic::Play( void ) { - #ifdef CHATTY - pc.puts( "Program has restarted!\r\n" ); - #endif +#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; @@ -105,63 +93,55 @@ HighScoreTable highScores( &eeprom ); // Start on the attract level. UInt8 levelNumber = LevelCollection::AttractLevel; -#if 0 - player.Lives = START_LIVES; -#endif - LevelCollection levels; - Level *level; - Level::LevelExitCode exitCode; -#if 0 - // Initialise panel controls. - controls.InitialisePins(); - // Specify controls player should use. - player.SetControls( &controls ); - // Restrict players movement. - player.MovementRestricted = true; - player.Bounds = &ArenaRectangle; -#endif - // Repeat forever. - while( true ) { - // Get level specified by level number. - level = levels.GetLevel( levelNumber ); - // If failed to get level with that number go back to first normal level. - // This will happen if player completes last level. - if( level == NULL ) { - levelNumber = LevelCollection::FirstNormalLevel; - // Refetch level. - level = levels.GetLevel( levelNumber ); + player.Lives = START_LIVES; + LevelCollection levels; + Level *level; + Level::LevelExitCode exitCode; + // Initialise panel controls. + controls.InitialisePins(); + // Specify controls player should use. + player.SetControls( &controls ); + // Restrict players movement. + player.MovementRestricted = true; + player.Bounds = &ArenaRectangle; + // Repeat forever. + while( true ) { + // Get level specified by level number. + level = levels.GetLevel( levelNumber ); + // If failed to get level with that number go back to first normal level. + // This will happen if player completes last level. + if( level == NULL ) { + levelNumber = LevelCollection::FirstNormalLevel; + // Refetch level. + level = levels.GetLevel( levelNumber ); + } + // Pass reference to high score table. + level->SetHighScores( &highScores ); + // Set player that is playing the level. + level->SetPlayer( &player ); + // Set Gameduino to use. + level->SetGameduino( &gd ); + // Play the level. + exitCode = level->Play(); + // If player was killed then decrement lives otherwise + // advance to next level. + switch( exitCode ) { + case Level::GameOver : + // TODO : Do some sort of game over fuss. + CheckForHighScore( &gd, &highScores, player.Score ); + // Go back to attract level and reset player lives and score. + levelNumber = LevelCollection::AttractLevel; + player.Lives = START_LIVES; + player.Score = 0; + break; + case Level::Completed : + levelNumber++; + break; + } + // Wait a bit. + wait( (float)2 ); } - // Pass reference to high score table. - level->SetHighScores( &highScores ); -#if 0 - // Set player that is playing the level. - level->SetPlayer( &player ); -#endif - // Set Gameduino to use. - level->SetGameduino( &gd ); - // Play the level. - exitCode = level->Play(); - // If player was killed then decrement lives otherwise - // advance to next level. - switch( exitCode ) { - case Level::GameOver : -#if 0 - // TODO : Do some sort of game over fuss. - CheckForHighScore( &highScores, player.Score ); -#endif - // Go back to attract level and reset player lives and score. - levelNumber = LevelCollection::AttractLevel; -#if 0 - player.Lives = START_LIVES; - player.Score = 0; -#endif - break; - case Level::Completed : - levelNumber++; - break; - } - // Wait a bit. - wait( (float)2 ); - } } + +