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@4:673eb9735d44, 2013-06-08 (annotated)
- Committer:
- RichardE
- Date:
- Sat Jun 08 11:24:05 2013 +0000
- Revision:
- 4:673eb9735d44
- Parent:
- 3:a6a0cd726ca0
- Child:
- 5:0b0651ac7832
Pulled in more code. Now panel controls are working. Level 0 (attract mode) now goes round an endless loop sending state of panel controls up serial port to PC.
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 | 4:673eb9735d44 | 9 | #include "CharBlocks.h" |
RichardE | 4:673eb9735d44 | 10 | |
RichardE | 4:673eb9735d44 | 11 | // REMOVE THIS! |
RichardE | 4:673eb9735d44 | 12 | extern Serial pc; |
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 | // Draw high score table. |
RichardE | 3:a6a0cd726ca0 | 41 | GDExtra::WriteProgString( gd, 16, 11, StringData::HighScoresString ); |
RichardE | 0:5fa232ee5fdf | 42 | PlayerName name; |
RichardE | 0:5fa232ee5fdf | 43 | UInt32 score; |
RichardE | 0:5fa232ee5fdf | 44 | UInt8 y = 13; |
RichardE | 0:5fa232ee5fdf | 45 | for( UInt8 i = 0; i < highScores->GetCapacity(); ++i ) { |
RichardE | 0:5fa232ee5fdf | 46 | highScores->Get( i, &name, &score ); |
RichardE | 3:a6a0cd726ca0 | 47 | gd->putstr( 18, y, name.Name ); |
RichardE | 3:a6a0cd726ca0 | 48 | GDExtra::WriteBCDNumber( gd, 22, y, score, 8 ); |
RichardE | 0:5fa232ee5fdf | 49 | y += 2; |
RichardE | 0:5fa232ee5fdf | 50 | } |
RichardE | 0:5fa232ee5fdf | 51 | } |
RichardE | 0:5fa232ee5fdf | 52 | |
RichardE | 0:5fa232ee5fdf | 53 | /*************/ |
RichardE | 0:5fa232ee5fdf | 54 | /* PLAY LOOP */ |
RichardE | 0:5fa232ee5fdf | 55 | /*************/ |
RichardE | 0:5fa232ee5fdf | 56 | // Returns code indicating how level ended. |
RichardE | 0:5fa232ee5fdf | 57 | // This method should be called from the Play method after the |
RichardE | 0:5fa232ee5fdf | 58 | // level data has been initialised and the return value returned |
RichardE | 0:5fa232ee5fdf | 59 | // by the Play method. |
RichardE | 0:5fa232ee5fdf | 60 | Level::LevelExitCode Level0::PlayLoop( void ) { |
RichardE | 1:dfd5eaaf96a3 | 61 | // Must have a Gameduino defined. |
RichardE | 1:dfd5eaaf96a3 | 62 | if( gd != (Gameduino*)NULL ) { |
RichardE | 1:dfd5eaaf96a3 | 63 | // Set screen background to black. |
RichardE | 1:dfd5eaaf96a3 | 64 | gd->wr( Gameduino::BG_COLOR, Gameduino::RGB( 0, 0, 0 ) ); |
RichardE | 1:dfd5eaaf96a3 | 65 | GDExtra::ClearScreen( gd, TransparentChar ); |
RichardE | 1:dfd5eaaf96a3 | 66 | GDExtra::HideAllSprites( gd ); |
RichardE | 1:dfd5eaaf96a3 | 67 | // SoundManager::Instance.SilenceAll(); |
RichardE | 1:dfd5eaaf96a3 | 68 | // Draw border around screen. |
RichardE | 2:bb0f631a6068 | 69 | CharFrame::Draw( gd, 0, 0, VISIBLE_CHAR_WIDTH, VISIBLE_CHAR_HEIGHT ); |
RichardE | 1:dfd5eaaf96a3 | 70 | // Draw big block of characters that read "ROBOTRIC". |
RichardE | 1:dfd5eaaf96a3 | 71 | GDExtra::WriteProgCharBlock( gd, 2, 2, CharBlocks::RobotRicText ); |
RichardE | 1:dfd5eaaf96a3 | 72 | // Write message telling user how to start game. |
RichardE | 1:dfd5eaaf96a3 | 73 | GDExtra::WriteProgString( gd, 2, VISIBLE_CHAR_HEIGHT - 3, startText ); |
RichardE | 1:dfd5eaaf96a3 | 74 | // Validate high scores in EEPROM which will re-write the entire |
RichardE | 1:dfd5eaaf96a3 | 75 | // table with default data if it finds nonsense in the EEPROM. |
RichardE | 1:dfd5eaaf96a3 | 76 | // Then check if EEPROM now makes sense. If it does then display |
RichardE | 1:dfd5eaaf96a3 | 77 | // the high score table. If it does not then chances are there |
RichardE | 1:dfd5eaaf96a3 | 78 | // is no EEPROM connected so don't bother with high scores. |
RichardE | 1:dfd5eaaf96a3 | 79 | if( highScores != (HighScoreTable*)NULL ) { |
RichardE | 1:dfd5eaaf96a3 | 80 | highScores->ValidateEEPROM(); |
RichardE | 1:dfd5eaaf96a3 | 81 | if( highScores->EEPROMValid() ) { |
RichardE | 1:dfd5eaaf96a3 | 82 | DrawHighScores(); |
RichardE | 1:dfd5eaaf96a3 | 83 | } |
RichardE | 1:dfd5eaaf96a3 | 84 | } |
RichardE | 1:dfd5eaaf96a3 | 85 | // Must have a player with non-NULL controls. |
RichardE | 1:dfd5eaaf96a3 | 86 | PanelControls *controls; |
RichardE | 1:dfd5eaaf96a3 | 87 | if( |
RichardE | 1:dfd5eaaf96a3 | 88 | ( player != (PlayerObject*)NULL ) && |
RichardE | 1:dfd5eaaf96a3 | 89 | ( ( controls = player->GetControls() ) != (PanelControls*)NULL ) |
RichardE | 1:dfd5eaaf96a3 | 90 | ) { |
RichardE | 1:dfd5eaaf96a3 | 91 | // Wait until all panel controls are released. |
RichardE | 1:dfd5eaaf96a3 | 92 | UInt16 inputs; |
RichardE | 1:dfd5eaaf96a3 | 93 | do { |
RichardE | 1:dfd5eaaf96a3 | 94 | controls->Read(); |
RichardE | 1:dfd5eaaf96a3 | 95 | inputs = controls->GetInputs(); |
RichardE | 1:dfd5eaaf96a3 | 96 | } while( inputs != 0 ); |
RichardE | 1:dfd5eaaf96a3 | 97 | // Wait until a panel control is activated. |
RichardE | 1:dfd5eaaf96a3 | 98 | do { |
RichardE | 1:dfd5eaaf96a3 | 99 | controls->Read(); |
RichardE | 1:dfd5eaaf96a3 | 100 | inputs = controls->GetInputs(); |
RichardE | 4:673eb9735d44 | 101 | pc.printf( "Inputs = %04X\r\n", (int)inputs ); |
RichardE | 4:673eb9735d44 | 102 | } while( true /* inputs == 0 */ ); |
RichardE | 1:dfd5eaaf96a3 | 103 | } |
RichardE | 0:5fa232ee5fdf | 104 | } |
RichardE | 1:dfd5eaaf96a3 | 105 | return Completed; |
RichardE | 0:5fa232ee5fdf | 106 | } |
RichardE | 0:5fa232ee5fdf | 107 |