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:
- 0:5fa232ee5fdf
- Child:
- 1:dfd5eaaf96a3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GameRobotRic.cpp Tue Jun 04 20:16:33 2013 +0000 @@ -0,0 +1,142 @@ +/* + * SOURCE FILE : GameRobotRic.cpp + * + * The RobotRic game class. + * + */ + +#include "GameRobotRic.h" // this module's prototypes +#include "Types.h" // various integer types etc. +#include "LevelCollection.h" // all the levels +#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 + #include "I2CEEPROM.h" // for access to serial EEPROM + #include "HighScoreEntry.h" // for getting player's name for high score table +#endif + +// 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 + +/**************************/ +/* CHECK FOR A HIGH SCORE */ +/**************************/ +// Pass pointer to high score table in highScores. +// Pass score that was achieved in score. +void GameRobotRic::CheckForHighScore( HighScoreTable *highScores, UInt32 score ) { +#if 0 + UInt8 tablePos; + // Enter name into high score table if score is high enough. + if( ( tablePos = highScores->GetPositionInTable( player.Score ) ) < highScores->GetCapacity() ) { + // Player has made it onto the high score table. + // Get player to input name. + HighScoreEntry nameGetter; + PlayerName name; + nameGetter.GetName( &name, &controls ); + // Add name and score to table. + highScores->Add( tablePos, &name, score ); + } +#endif +} + +/*****************/ +/* PLAY THE GAME */ +/*****************/ +// 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. + // Use pin 5 for MOSI. + // Use pin 6 for MISO. + // Use pin 7 for SCK. + SPI spi( p5, p6, p7 ); + // 8MHz clock should be OK. + spi.frequency( 8000000 ); + // Set SPI format to use. + // Use 8 bits per SPI frame. + // 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 ); + // 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 ); + // Create a high score table that uses the EEPROM. + HighScoreTable highScores( &eeprom ); +#endif + // 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 ) { +#if 0 + // 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 ); + // 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( &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; + } +#endif + // Finished with Gameduino. + gd.end(); + } +} +