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
GameRobotRic.cpp
- Committer:
- RichardE
- Date:
- 2013-06-06
- Revision:
- 2:bb0f631a6068
- Parent:
- 1:dfd5eaaf96a3
- Child:
- 3:a6a0cd726ca0
File content as of revision 2:bb0f631a6068:
/* * 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 #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 // 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 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. 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, &gameduinoCS ); // Reset the Gameduino. gd.begin(); 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 ); // 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 ); } #if 0 // Pass reference to high score table. level->SetHighScores( &highScores ); // 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 ); } }