From cc37d2216498f41d82206cdebab89b14a33c7771 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Wed, 16 Jul 2008 11:06:53 +0100 Subject: [PATCH] Bounce ship only once when exploding --- src/Game.cpp | 53 ++++++++++++++++++---------------------------------- src/Game.hpp | 6 ++---- src/Main.cpp | 2 ++ 3 files changed, 22 insertions(+), 39 deletions(-) diff --git a/src/Game.cpp b/src/Game.cpp index 14303fd..cafe7d4 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -18,6 +18,8 @@ */ #include "Game.hpp" +#include "Menu.hpp" +#include "HighScores.hpp" #include "LoadOnce.hpp" /* @@ -32,9 +34,9 @@ /* * Constants affecting state transitions. */ +const int Game::DEATH_TIMEOUT(50); // Frames to wait for ending level #define GAME_FADE_IN_SPEED 0.1f // Rate of alpha change at level start #define GAME_FADE_OUT_SPEED 0.1f // Rate of alpha change at level end -#define DEATH_TIMEOUT 50 // Frames to wait for ending level #define LIFE_ALPHA_BASE 2.0f #define LEVEL_TEXT_TIMEOUT 75 @@ -49,6 +51,7 @@ const int Game::SCORE_FUEL_DIV(10); const int Game::SCORE_Y(30); + const float SpeedMeter::LAND_SPEED(2.0f); const int FuelMeter::FUELBAR_Y(15); @@ -114,6 +117,12 @@ void Game::CalculateScore(int padIndex) newscore_width = bigFont.GetStringWidth(i18n("Score: %d"), newscore); } +void Game::EnterDeathWait(int timeout) +{ + state = gsDeathWait; + death_timeout = timeout; +} + void Game::Process() { Input &input = Input::GetInstance(); @@ -161,11 +170,7 @@ void Game::Process() if (input.GetKeyState(SDLK_SPACE) && state == gsExplode) { // Skip explosion - state = gsDeathWait; - if (lives == 0) - death_timeout = DEATH_TIMEOUT; - else - death_timeout = 1; + EnterDeathWait(lives == 0 ? DEATH_TIMEOUT : 1); } if (input.GetKeyState(SDLK_ESCAPE) && state == gsInGame) { @@ -218,15 +223,8 @@ void Game::Process() ship.Bounce(); } } - else if (state == gsExplode) { - ship.Bounce(); - - // See if we need to stop the madness - if (state == gsExplode && -ship.GetYSpeed() < 0.05f) { - state = gsDeathWait; - death_timeout = DEATH_TIMEOUT; - } - } + else if (state == gsExplode) + EnterDeathWait(); } // Check for collisions with asteroids @@ -240,15 +238,8 @@ void Game::Process() ExplodeShip(); ship.Bounce(); } - else if (state == gsExplode) { - ship.Bounce(); - - // See if we need to stop the madness - if (state == gsExplode && -ship.GetYSpeed() < 0.05f) { - state = gsDeathWait; - death_timeout = DEATH_TIMEOUT; - } - } + else if (state == gsExplode) + EnterDeathWait(); } } } @@ -263,8 +254,7 @@ void Game::Process() } else if (state == gsExplode) { // Destroy the ship anyway - state = gsDeathWait; - death_timeout = DEATH_TIMEOUT; + EnterDeathWait(); } } } @@ -277,15 +267,8 @@ void Game::Process() ExplodeShip(); ship.Bounce(); } - else if (state == gsExplode) { - ship.Bounce(); - - // See if we need to stop the madness - if (state == gsExplode && -ship.GetYSpeed() < 0.05f) { - state = gsDeathWait; - death_timeout = DEATH_TIMEOUT; - } - } + else if (state == gsExplode) + EnterDeathWait(); } } diff --git a/src/Game.hpp b/src/Game.hpp index c43c106..89103a3 100644 --- a/src/Game.hpp +++ b/src/Game.hpp @@ -28,9 +28,6 @@ #include "Font.hpp" #include "SoundEffect.hpp" -#include "Menu.hpp" -#include "HighScores.hpp" - #include "Viewport.hpp" #include "ObjectGrid.hpp" #include "Asteroid.hpp" @@ -100,9 +97,10 @@ private: static const float TURN_ANGLE, DEATH_SPIN_RATE; static const int FUEL_BASE, FUEL_PER_LEVEL; static const int SCORE_PAD_SIZE, SCORE_LEVEL, SCORE_FUEL_DIV; - static const int SCORE_Y; + static const int SCORE_Y, DEATH_TIMEOUT; void ExplodeShip(); + void EnterDeathWait(int timeout = DEATH_TIMEOUT); void CalculateScore(int padIndex); Viewport viewport; diff --git a/src/Main.cpp b/src/Main.cpp index 7246dba..0a824c7 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -18,6 +18,8 @@ */ #include "Game.hpp" +#include "Menu.hpp" +#include "HighScores.hpp" #include "Options.hpp" #include "ConfigFile.hpp" #include "SoundEffect.hpp" -- 2.39.2