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

Committer:
RichardE
Date:
Mon Jun 17 15:10:43 2013 +0000
Revision:
18:70190f956a24
Parent:
10:bfa1c307c99d
Improved response to button 1 when entering high scores (HighScoreEntry.cpp).

Who changed what in which revision?

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