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