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
Diff: LevelNormal.cpp
- Revision:
- 1:dfd5eaaf96a3
- Parent:
- 0:5fa232ee5fdf
- Child:
- 5:0b0651ac7832
--- a/LevelNormal.cpp Tue Jun 04 20:16:33 2013 +0000 +++ b/LevelNormal.cpp Wed Jun 05 22:05:41 2013 +0000 @@ -87,18 +87,18 @@ /* DRAW THE LEVEL */ /******************/ void LevelNormal::DrawLevel( void ) { -#if 0 // Set screen background to black. - GD.wr( BG_COLOR, RGB( 0, 0, 0 ) ); + gd->wr( Gameduino::BG_COLOR, Gameduino::RGB( 0, 0, 0 ) ); // Clear the screen to zero characters. - GDExtra::ClearScreen( TransparentChar ); + GDExtra::ClearScreen( gd, TransparentChar ); // Hide all sprties. - GDExtra::HideAllSprites(); + GDExtra::HideAllSprites( gd ); // Display level number. - GDExtra::WriteProgString( 0, 0, StringData::LevelString ); - GDExtra::WriteUInt16( 6, 0, LevelNumber, 10, 2 ); + GDExtra::WriteProgString( gd, 0, 0, StringData::LevelString ); + GDExtra::WriteUInt16( gd, 6, 0, LevelNumber, 10, 2 ); // Display score. - GDExtra::WriteProgString( 10, 0, StringData::ScoreString ); + GDExtra::WriteProgString( gd, 10, 0, StringData::ScoreString ); + #if 0 // Update score and lives. DrawScoreAndLives(); // Draw border around screen. @@ -108,7 +108,7 @@ ARENA_BORDER_WIDTH, ARENA_BORDER_HEIGHT ); -#endif + #endif } /************************************************/ @@ -272,22 +272,22 @@ // level data has been initialised and the return value returned // by the Play method. Level::LevelExitCode LevelNormal::PlayLoop( void ) { -#if 0 - // Do nothing if level data is NULL or player has not been specified. - if( ( DataForLevel != (LevelData*)NULL ) || ( player == (PlayerObject*)NULL ) ) { + // Do nothing if Gameduino has not been specified, level data is NULL or player has not been specified. + if( ( gd != (Gameduino*)NULL ) /* || ( DataForLevel != (LevelData*)NULL ) || ( player == (PlayerObject*)NULL ) */ ) { // Point static pointer to current instance. currentInstance = this; // Do some initialisation first. InitialiseLevel(); // Redraw the screen. DrawLevel(); - // Wait for frame flyback once before entering loop so collision data is recalculated. - // At this point there should not be any sprites on the screen so no collisions - // should be found. - GD.waitvblank(); + // Wait for frame flyback once before entering loop so collision data is recalculated. + // At this point there should not be any sprites on the screen so no collisions + // should be found. + gd->waitvblank(); +#if 0 // Repeat until all enemies are dead or player is dead. bool allEnemiesAreDead = false; - bool playerIsDead = false; + bool playerIsDead = false; bool gameIsOver = false; bool firstDraw = true; while( ! allEnemiesAreDead && ! gameIsOver ) { @@ -297,8 +297,8 @@ GD.waitvblank(); // Check for collisions between player and other objects. CheckPlayerCollisions( &playerIsDead ); - // Check for collisions between humans and enemies that squash. - GameObject::FindCollisions( DataForLevel->Humans, LevelData::MaxHumans, &LevelNormal::HandleHumanCollision ); + // Check for collisions between humans and enemies that squash. + GameObject::FindCollisions( DataForLevel->Humans, LevelData::MaxHumans, &LevelNormal::HandleHumanCollision ); // Check for collisions between player bullets and enemies. GameObject::FindCollisions( player->GetBullets(), BulletManager::MaxBullets, &LevelNormal::HandleBulletCollision ); // Redraw the player's score and number of lives. @@ -320,57 +320,59 @@ PlaySoundAndWait( Sounds::StartLevel ); firstDraw = false; } - // If player was killed then play death march and wait for it to finish. - if( playerIsDead ) { - // Player got killed. - PlaySoundAndWait( Sounds::PlayerDead ); - // One less life for player. - if( player->Lives > 0 ) { - player->Lives--; - } - // Game is over when player has no more lives. - gameIsOver = ( player->Lives == 0 ); - // If game is not over then re-initialise level using any remaining enemies. - if( ! gameIsOver ) { - // Remove all objects that do not survive a level restart (like enemy bullets). - GameObject::RemoveUnretainedObjects( DataForLevel->Enemies, LevelData::MaxEnemies ); - InitialiseLevel(); - DrawLevel(); - GD.waitvblank(); - playerIsDead = false; - firstDraw = true; - } + // If player was killed then play death march and wait for it to finish. + if( playerIsDead ) { + // Player got killed. + PlaySoundAndWait( Sounds::PlayerDead ); + // One less life for player. + if( player->Lives > 0 ) { + player->Lives--; + } + // Game is over when player has no more lives. + gameIsOver = ( player->Lives == 0 ); + // If game is not over then re-initialise level using any remaining enemies. + if( ! gameIsOver ) { + // Remove all objects that do not survive a level restart (like enemy bullets). + GameObject::RemoveUnretainedObjects( DataForLevel->Enemies, LevelData::MaxEnemies ); + InitialiseLevel(); + DrawLevel(); + GD.waitvblank(); + playerIsDead = false; + firstDraw = true; } - else { - // Move all the enemies and check if all dead. - allEnemiesAreDead = ! GameObject::MoveAll( DataForLevel->Enemies, LevelData::MaxEnemies ); - // If there are still some enemies alive then check if those that remain are indestructable. - // If only indestructable enemies survive then act as if all enemies are dead. - // You need to do this or you would never be able to complete a level that had indestructable - // enemies on it. - if( ! allEnemiesAreDead ) { - allEnemiesAreDead = EnemyObject::AreAllIndestructable( - (const EnemyObject**)DataForLevel->Enemies, - LevelData::MaxEnemies - ); - } - // Move all the humans. - GameObject::MoveAll( DataForLevel->Humans, LevelData::MaxHumans ); - // Move (update) all the explosions. - GameObject::MoveAll( ExplosionManager::Instance.GetExplosions(), ExplosionManager::MaxExplosions ); - // Read the player's controls. - player->ReadControls(); - // Move the player. - player->Move(); - // Move the player's bullets. - GameObject::MoveAll( player->GetBullets(), BulletManager::MaxBullets ); + } + else { + // Move all the enemies and check if all dead. + allEnemiesAreDead = ! GameObject::MoveAll( DataForLevel->Enemies, LevelData::MaxEnemies ); + // If there are still some enemies alive then check if those that remain are indestructable. + // If only indestructable enemies survive then act as if all enemies are dead. + // You need to do this or you would never be able to complete a level that had indestructable + // enemies on it. + if( ! allEnemiesAreDead ) { + allEnemiesAreDead = EnemyObject::AreAllIndestructable( + (const EnemyObject**)DataForLevel->Enemies, + LevelData::MaxEnemies + ); } + // Move all the humans. + GameObject::MoveAll( DataForLevel->Humans, LevelData::MaxHumans ); + // Move (update) all the explosions. + GameObject::MoveAll( ExplosionManager::Instance.GetExplosions(), ExplosionManager::MaxExplosions ); + // Read the player's controls. + player->ReadControls(); + // Move the player. + player->Move(); + // Move the player's bullets. + GameObject::MoveAll( player->GetBullets(), BulletManager::MaxBullets ); + } } - // Player completed level or game is over. - return gameIsOver ? GameOver : Completed; +#endif + // Player completed level or game is over. + return /* gameIsOver ? GameOver : */ Completed; } -#endif - // Level data or player were not specified. - return Completed; + else { + // Level data or player were not specified. + return Completed; + } }