From 69c6e1aaefea9b5c7ea801bc3d724ec1d4ed4b29 Mon Sep 17 00:00:00 2001 From: "Martin Felis (berta)" Date: Wed, 23 Mar 2011 08:13:27 +0100 Subject: [PATCH] added level_assemble_mode for easier switching between levels ingame --- asteroids/Model.cc | 7 +++++++ asteroids/Model.h | 1 + asteroids/View.cc | 22 ++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/asteroids/Model.cc b/asteroids/Model.cc index 17e54d3..cf9902e 100644 --- a/asteroids/Model.cc +++ b/asteroids/Model.cc @@ -604,6 +604,13 @@ int Model::DoSaveLevel (const char* filename) { return 0; } +void Model::LoadLevelFromIndex (unsigned int level_index) { + if (level_index < mLevelList.size()) { + mCurrentLevelIndex = level_index; + DoLoadLevel(mLevelList[mCurrentLevelIndex].c_str()); + } +} + void Model::ReloadLevel () { Engine::LogDebug ("Reloading level %d", mCurrentLevelIndex + 1); diff --git a/asteroids/Model.h b/asteroids/Model.h index d39b062..a44ba43 100644 --- a/asteroids/Model.h +++ b/asteroids/Model.h @@ -23,6 +23,7 @@ class Model : public Engine::ModelBase { /* Level loading etc. */ int DoLoadLevel (const char* filename); int DoSaveLevel (const char* filename); + void LoadLevelFromIndex (unsigned int level_index); void ResetLevel (); void ReloadLevel(); diff --git a/asteroids/View.cc b/asteroids/View.cc index 1c32f5b..70c21a2 100644 --- a/asteroids/View.cc +++ b/asteroids/View.cc @@ -31,6 +31,8 @@ using namespace std; namespace asteroids { +bool level_assemble_mode = true; + int View::OnInit (int argc, char* argv[]) { ViewBase::OnInit (argc, argv); @@ -542,6 +544,26 @@ void View::DrawUiGameRunning() { // revert the font justification SetFontJustification (Engine::FontJustificationLeft); + if (level_assemble_mode) { + if (Engine::GUI::CheckKeyPress(SDLK_PAGEDOWN)) { + Engine::EventBasePtr level_complete_event (new Engine::EventBase()); + level_complete_event->mEventType = EventLevelComplete; + QueueEvent (level_complete_event); + } else if (Engine::GUI::CheckKeyPress(SDLK_PAGEUP)) { + unsigned int current_level = GetModel()->GetCurrentLevelIndex(); + + if (current_level > 0) { + GetModel()->SetGameState(GameStatePaused); + GetModel()->LoadLevelFromIndex(current_level - 1); + PushViewState(ViewStateLevelIntro); + Engine::StartTimer ("LevelIntroLevelNumber", 0.4); + Engine::StartTimer ("LevelIntroLevelTitle", 0.6); + Engine::StartTimer ("LevelIntroLevelAuthor", 0.8); + Engine::StartTimer ("LevelIntroLevelStart", 1.0); + } + } + } + if (Engine::GUI::CheckKeyPress(SDLK_ESCAPE)) { PushViewState(ViewStatePaused); GetModel()->SetGameState(GameStatePaused);