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
Level0.cpp@2:bb0f631a6068, 2013-06-06 (annotated)
- Committer:
- RichardE
- Date:
- Thu Jun 06 20:11:28 2013 +0000
- Revision:
- 2:bb0f631a6068
- Parent:
- 1:dfd5eaaf96a3
- Child:
- 3:a6a0cd726ca0
More code brought in from Maple version. Now uses fancy character set and displays Robotric logo. Started re-writing I2C EEPROM code as SPI EEPROM code since now using an SPI EEPROM but not finished yet.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RichardE | 0:5fa232ee5fdf | 1 | /* |
RichardE | 0:5fa232ee5fdf | 2 | * SOURCE FILE : Level0.cpp |
RichardE | 0:5fa232ee5fdf | 3 | * |
RichardE | 0:5fa232ee5fdf | 4 | * Definition of class Level0. |
RichardE | 0:5fa232ee5fdf | 5 | * |
RichardE | 0:5fa232ee5fdf | 6 | */ |
RichardE | 0:5fa232ee5fdf | 7 | |
RichardE | 0:5fa232ee5fdf | 8 | #include "Level0.h" |
RichardE | 0:5fa232ee5fdf | 9 | #if 0 |
RichardE | 0:5fa232ee5fdf | 10 | #include "CharBlocks.h" |
RichardE | 0:5fa232ee5fdf | 11 | #include "EEPROMDump.h" |
RichardE | 0:5fa232ee5fdf | 12 | #endif |
RichardE | 0:5fa232ee5fdf | 13 | |
RichardE | 0:5fa232ee5fdf | 14 | /***************/ |
RichardE | 0:5fa232ee5fdf | 15 | /* CONSTRUCTOR */ |
RichardE | 0:5fa232ee5fdf | 16 | /***************/ |
RichardE | 0:5fa232ee5fdf | 17 | Level0::Level0() { |
RichardE | 0:5fa232ee5fdf | 18 | } |
RichardE | 0:5fa232ee5fdf | 19 | |
RichardE | 0:5fa232ee5fdf | 20 | /**************/ |
RichardE | 0:5fa232ee5fdf | 21 | /* DESTRUCTOR */ |
RichardE | 0:5fa232ee5fdf | 22 | /**************/ |
RichardE | 0:5fa232ee5fdf | 23 | Level0::~Level0() { |
RichardE | 0:5fa232ee5fdf | 24 | } |
RichardE | 0:5fa232ee5fdf | 25 | |
RichardE | 0:5fa232ee5fdf | 26 | /**************/ |
RichardE | 0:5fa232ee5fdf | 27 | /* PLAY LEVEL */ |
RichardE | 0:5fa232ee5fdf | 28 | /**************/ |
RichardE | 0:5fa232ee5fdf | 29 | // Returns code indicating how level ended. |
RichardE | 0:5fa232ee5fdf | 30 | Level::LevelExitCode Level0::Play( void ) { |
RichardE | 0:5fa232ee5fdf | 31 | return PlayLoop(); |
RichardE | 0:5fa232ee5fdf | 32 | } |
RichardE | 0:5fa232ee5fdf | 33 | |
RichardE | 0:5fa232ee5fdf | 34 | static const char startText[] = "OPERATE EITHER JOYSTICK TO START GAME"; |
RichardE | 0:5fa232ee5fdf | 35 | |
RichardE | 0:5fa232ee5fdf | 36 | /********************/ |
RichardE | 0:5fa232ee5fdf | 37 | /* DRAW HIGH SCORES */ |
RichardE | 0:5fa232ee5fdf | 38 | /********************/ |
RichardE | 0:5fa232ee5fdf | 39 | void Level0::DrawHighScores( void ) { |
RichardE | 0:5fa232ee5fdf | 40 | #if 0 |
RichardE | 0:5fa232ee5fdf | 41 | // Draw high score table. |
RichardE | 0:5fa232ee5fdf | 42 | GDExtra::WriteProgString( 16, 11, StringData::HighScoresString ); |
RichardE | 0:5fa232ee5fdf | 43 | PlayerName name; |
RichardE | 0:5fa232ee5fdf | 44 | UInt32 score; |
RichardE | 0:5fa232ee5fdf | 45 | UInt8 y = 13; |
RichardE | 0:5fa232ee5fdf | 46 | for( UInt8 i = 0; i < highScores->GetCapacity(); ++i ) { |
RichardE | 0:5fa232ee5fdf | 47 | highScores->Get( i, &name, &score ); |
RichardE | 0:5fa232ee5fdf | 48 | GD.putstr( 18, y, name.Name ); |
RichardE | 0:5fa232ee5fdf | 49 | GDExtra::WriteBCDNumber( 22, y, score, 8 ); |
RichardE | 0:5fa232ee5fdf | 50 | y += 2; |
RichardE | 0:5fa232ee5fdf | 51 | } |
RichardE | 0:5fa232ee5fdf | 52 | #endif |
RichardE | 0:5fa232ee5fdf | 53 | } |
RichardE | 0:5fa232ee5fdf | 54 | |
RichardE | 0:5fa232ee5fdf | 55 | /*************/ |
RichardE | 0:5fa232ee5fdf | 56 | /* PLAY LOOP */ |
RichardE | 0:5fa232ee5fdf | 57 | /*************/ |
RichardE | 0:5fa232ee5fdf | 58 | // Returns code indicating how level ended. |
RichardE | 0:5fa232ee5fdf | 59 | // This method should be called from the Play method after the |
RichardE | 0:5fa232ee5fdf | 60 | // level data has been initialised and the return value returned |
RichardE | 0:5fa232ee5fdf | 61 | // by the Play method. |
RichardE | 0:5fa232ee5fdf | 62 | Level::LevelExitCode Level0::PlayLoop( void ) { |
RichardE | 1:dfd5eaaf96a3 | 63 | // Must have a Gameduino defined. |
RichardE | 1:dfd5eaaf96a3 | 64 | if( gd != (Gameduino*)NULL ) { |
RichardE | 1:dfd5eaaf96a3 | 65 | // Set screen background to black. |
RichardE | 1:dfd5eaaf96a3 | 66 | gd->wr( Gameduino::BG_COLOR, Gameduino::RGB( 0, 0, 0 ) ); |
RichardE | 1:dfd5eaaf96a3 | 67 | GDExtra::ClearScreen( gd, TransparentChar ); |
RichardE | 1:dfd5eaaf96a3 | 68 | GDExtra::HideAllSprites( gd ); |
RichardE | 1:dfd5eaaf96a3 | 69 | // SoundManager::Instance.SilenceAll(); |
RichardE | 1:dfd5eaaf96a3 | 70 | // Draw border around screen. |
RichardE | 2:bb0f631a6068 | 71 | CharFrame::Draw( gd, 0, 0, VISIBLE_CHAR_WIDTH, VISIBLE_CHAR_HEIGHT ); |
RichardE | 1:dfd5eaaf96a3 | 72 | // Draw big block of characters that read "ROBOTRIC". |
RichardE | 1:dfd5eaaf96a3 | 73 | GDExtra::WriteProgCharBlock( gd, 2, 2, CharBlocks::RobotRicText ); |
RichardE | 1:dfd5eaaf96a3 | 74 | // Write message telling user how to start game. |
RichardE | 1:dfd5eaaf96a3 | 75 | GDExtra::WriteProgString( gd, 2, VISIBLE_CHAR_HEIGHT - 3, startText ); |
RichardE | 1:dfd5eaaf96a3 | 76 | // Validate high scores in EEPROM which will re-write the entire |
RichardE | 1:dfd5eaaf96a3 | 77 | // table with default data if it finds nonsense in the EEPROM. |
RichardE | 1:dfd5eaaf96a3 | 78 | // Then check if EEPROM now makes sense. If it does then display |
RichardE | 1:dfd5eaaf96a3 | 79 | // the high score table. If it does not then chances are there |
RichardE | 1:dfd5eaaf96a3 | 80 | // is no EEPROM connected so don't bother with high scores. |
RichardE | 1:dfd5eaaf96a3 | 81 | if( highScores != (HighScoreTable*)NULL ) { |
RichardE | 1:dfd5eaaf96a3 | 82 | highScores->ValidateEEPROM(); |
RichardE | 1:dfd5eaaf96a3 | 83 | if( highScores->EEPROMValid() ) { |
RichardE | 1:dfd5eaaf96a3 | 84 | DrawHighScores(); |
RichardE | 1:dfd5eaaf96a3 | 85 | } |
RichardE | 1:dfd5eaaf96a3 | 86 | } |
RichardE | 2:bb0f631a6068 | 87 | #if 0 |
RichardE | 1:dfd5eaaf96a3 | 88 | // Must have a player with non-NULL controls. |
RichardE | 1:dfd5eaaf96a3 | 89 | PanelControls *controls; |
RichardE | 1:dfd5eaaf96a3 | 90 | if( |
RichardE | 1:dfd5eaaf96a3 | 91 | ( player != (PlayerObject*)NULL ) && |
RichardE | 1:dfd5eaaf96a3 | 92 | ( ( controls = player->GetControls() ) != (PanelControls*)NULL ) |
RichardE | 1:dfd5eaaf96a3 | 93 | ) { |
RichardE | 1:dfd5eaaf96a3 | 94 | // Wait until all panel controls are released. |
RichardE | 1:dfd5eaaf96a3 | 95 | UInt16 inputs; |
RichardE | 1:dfd5eaaf96a3 | 96 | do { |
RichardE | 1:dfd5eaaf96a3 | 97 | controls->Read(); |
RichardE | 1:dfd5eaaf96a3 | 98 | inputs = controls->GetInputs(); |
RichardE | 1:dfd5eaaf96a3 | 99 | } while( inputs != 0 ); |
RichardE | 1:dfd5eaaf96a3 | 100 | // Wait until a panel control is activated. |
RichardE | 1:dfd5eaaf96a3 | 101 | do { |
RichardE | 1:dfd5eaaf96a3 | 102 | controls->Read(); |
RichardE | 1:dfd5eaaf96a3 | 103 | inputs = controls->GetInputs(); |
RichardE | 1:dfd5eaaf96a3 | 104 | } while( inputs == 0 ); |
RichardE | 1:dfd5eaaf96a3 | 105 | } |
RichardE | 1:dfd5eaaf96a3 | 106 | #endif |
RichardE | 0:5fa232ee5fdf | 107 | } |
RichardE | 1:dfd5eaaf96a3 | 108 | return Completed; |
RichardE | 0:5fa232ee5fdf | 109 | } |
RichardE | 0:5fa232ee5fdf | 110 |