From 2cb35eab1f313f9f87d9afa4c51232145283b84d Mon Sep 17 00:00:00 2001 From: "Martin Felis (berta win)" Date: Sun, 13 Feb 2011 15:31:42 +0100 Subject: [PATCH] beta 2 + editor for the windows version --- asteroids/Model.cc | 4 ++-- asteroids/RocketEntity.cc | 3 +++ asteroids/RocketEntity.h | 4 ++++ asteroids/ShipEntity.cc | 4 ++-- asteroids/View.cc | 17 ++++++++++++----- asteroids/View.h | 5 +++++ asteroids/editormain.cc | 24 ++++++++++++++++++++++-- asteroids/main.cc | 14 +++++++++++--- 8 files changed, 61 insertions(+), 14 deletions(-) diff --git a/asteroids/Model.cc b/asteroids/Model.cc index f1e54f3..60db153 100644 --- a/asteroids/Model.cc +++ b/asteroids/Model.cc @@ -69,8 +69,6 @@ int Model::OnInit (int argc, char* argv[]) { mLevelAuthor = ""; mLevelTitle = ""; - Engine::PlayMusic (Engine::GetResourceFullPath("/data/sounds/intro_music.ogg")); - Engine::RegisterListener (this, EventAccelerateStart); Engine::RegisterListener (this, EventAccelerateStop); @@ -427,6 +425,8 @@ void Model::OnNewGame() { } void Model::OnShipExplode () { + Engine::PlaySound(Engine::GetResourceFullPath("/data/sounds/rock_destroyed.wav")); + mPlayerLives --; if (mPlayerLives == 0) { diff --git a/asteroids/RocketEntity.cc b/asteroids/RocketEntity.cc index 8cd835c..ebd1827 100644 --- a/asteroids/RocketEntity.cc +++ b/asteroids/RocketEntity.cc @@ -7,6 +7,9 @@ namespace asteroids { +Engine::Variable RocketEntity::VarTimeToLive ("rocket_timetolive", "1.0"); +Engine::Variable RocketEntity::VarSpeed ("rocket_speed", "15"); + void RocketEntity::Update (float delta_sec) { mSecToLive -= delta_sec; diff --git a/asteroids/RocketEntity.h b/asteroids/RocketEntity.h index a8c8d1f..eaea850 100644 --- a/asteroids/RocketEntity.h +++ b/asteroids/RocketEntity.h @@ -14,6 +14,7 @@ struct RocketEntityPhysicState : public Engine::EntityPhysicState { mType = GameEntityTypeRocket; } virtual ~RocketEntityPhysicState() {}; + }; struct RocketEntity: public Engine::EntityBase { @@ -31,6 +32,9 @@ struct RocketEntity: public Engine::EntityBase { } float mSecToLive; + + static Engine::Variable VarTimeToLive; + static Engine::Variable VarSpeed; }; } diff --git a/asteroids/ShipEntity.cc b/asteroids/ShipEntity.cc index 887f96e..a2eda63 100644 --- a/asteroids/ShipEntity.cc +++ b/asteroids/ShipEntity.cc @@ -107,7 +107,7 @@ void ShipEntity::Attack () { RocketEntity *rocket_entity = (RocketEntity*) Engine::CreateEntity (GameEntityTypeRocket); - rocket_entity->mSecToLive = 1.5; + rocket_entity->mSecToLive = RocketEntity::VarTimeToLive.GetFloatValue(); RocketEntityPhysicState *rocket_physics = (RocketEntityPhysicState*) rocket_entity->mPhysicState; rocket_physics->mPosition = attack_dir; @@ -115,7 +115,7 @@ void ShipEntity::Attack () { rocket_physics->mPosition += entity_physic->mPosition; rocket_physics->mOrientation = entity_physic->mOrientation; rocket_physics->mVelocity = attack_dir.normalize(); - rocket_physics->mVelocity *= ShipEntity::VarMaxSpeed.GetFloatValue() + 0.5; + rocket_physics->mVelocity *= RocketEntity::VarSpeed.GetFloatValue(); Engine::PlaySound (Engine::GetResourceFullPath("/data/sounds/laser.wav")); } diff --git a/asteroids/View.cc b/asteroids/View.cc index 0826b75..e5e11a7 100644 --- a/asteroids/View.cc +++ b/asteroids/View.cc @@ -476,6 +476,11 @@ void View::DrawPageTitle (const std::string& title) { void View::DrawUiMainMenu() { DrawPageTitle ("Asteroids"); + SelectFont("console.ttf size=23 color=#444444"); + DrawGLString( screen_right - 272, screen_bottom - 16, "http://www.fysx.org"); + SelectFont("console.ttf size=23 color=#cccccc"); + DrawGLString( screen_right - 270, screen_bottom - 18, "http://www.fysx.org"); + SelectFont("console.ttf size=23"); if (Engine::GUI::Button (1, "New Game", screen_right * 0.5 - 100, 200, button_width, button_height)) { PushViewState(ViewStateEnterPlayername); @@ -489,10 +494,12 @@ void View::DrawUiMainMenu() { PushViewState(ViewStateShowHighscore); } + /* if (Engine::GUI::Button (6, "E", screen_right - 48, 20, 32, button_height)) { PushViewState(ViewStateEditor); GetController()->ResetLevel(); } + */ if (Engine::GUI::Button (4, "Quit", screen_right * 0.5 - 100, 380, button_width, button_height)) { Engine::RunCommand("quit"); @@ -574,7 +581,7 @@ void View::DrawUiLevelComplete() { GetModel()->SetGameState(GameStatePaused); if (mEditorState == EditorStateTest) { - GetModel()->DoLoadLevel("level_edit_temp.txt"); + GetModel()->DoLoadLevel("level_edit_temp.map"); mEditorState = EditorStateUnknown; } } else { @@ -617,14 +624,14 @@ void View::DrawUiPlayerDied() { if (Engine::GUI::Button (1, "Continue", screen_right * 0.5 - 100, 380, button_width, button_height)) { PopViewState(); - + // we have to take care when we are testing the level to not proceed to // the next level... if (GetViewState() == ViewStateEditor) { GetModel()->SetGameState(GameStatePaused); if (mEditorState == EditorStateTest) { - GetModel()->DoLoadLevel("level_edit_temp.txt"); + GetModel()->DoLoadLevel("level_edit_temp.map"); mEditorState = EditorStateUnknown; } } else { @@ -777,7 +784,7 @@ void View::DrawUiEditor() { if (mEditorState == EditorStateTest) { mEditorState = EditorStateUnknown; - GetModel()->DoLoadLevel("level_edit_temp.txt"); + GetModel()->DoLoadLevel("level_edit_temp.map"); GetModel()->SetGameState(GameStatePaused); return; } else if (!Engine::GUI::CheckKeyPressed(SDLK_ESCAPE)){ @@ -835,7 +842,7 @@ void View::DrawUiEditor() { if (Engine::GUI::Button (9, "Test", 475, 20, 64, button_height)) { mEditorState = EditorStateTest; - GetModel()->DoSaveLevel("level_edit_temp.txt"); + GetModel()->DoSaveLevel("level_edit_temp.map"); GetModel()->SetGameState(GameStateRunning); } } diff --git a/asteroids/View.h b/asteroids/View.h index 35fb6a8..58f9cfd 100644 --- a/asteroids/View.h +++ b/asteroids/View.h @@ -58,6 +58,11 @@ class View : public Engine::ViewBase { Engine::LogDebug("Popped ViewState: %s current %s remaining: %u", popped_name.c_str(), current_name.c_str(), mViewStateStack.size()); + if (mViewStateStack.size() == 0) { + Engine::LogDebug ("No ViewState on the stack! Quitting."); + Engine::RunCommand("quit"); + } + // Fire the view state change event to properly clear the IMGUI state Engine::EventBasePtr changeviewstate_event (new Engine::EventBase()); changeviewstate_event->mEventType = EventChangeViewState; diff --git a/asteroids/editormain.cc b/asteroids/editormain.cc index 1421c8e..6417c80 100644 --- a/asteroids/editormain.cc +++ b/asteroids/editormain.cc @@ -27,10 +27,22 @@ std::string create_user_path () { std::string test_file_path = result_dir; // first we check in $HOME/.fysxasteroids +#ifdef WIN32 + size_t env_retval; + char env_home_dir[255]; + getenv_s (&env_retval, env_home_dir, 255, "HOME"); + if (env_retval == 0) { + env_home_dir[0] = '\0'; + } +#else char* env_home_dir = getenv("HOME"); +#endif + cout << "Yo4 " << env_home_dir << endl; + result_dir = env_home_dir; result_dir += "/.fysxasteroids"; + cout << "Path = " << result_dir << endl; boost::filesystem::path result_dir_path(result_dir); if(!boost::filesystem::is_directory (result_dir_path)) { if (!boost::filesystem::create_directory(result_dir_path)) { @@ -118,7 +130,14 @@ int main (int argc, char* argv[]) { SetLogPrintLevel (Engine::LogLevelMessage); // we assume the user path to be local folder - std::string user_path = create_user_path(); + std::string user_path; + +#ifdef WIN32 + user_path = "."; +#else + user_path = create_user_path(); +#endif + std::string log_file_path = user_path; log_file_path += "/editor.log"; @@ -146,7 +165,7 @@ int main (int argc, char* argv[]) { else SDL_WM_SetIcon(image,NULL); - SDL_WM_SetCaption("Asteroids -BETA1-","Asteroids -BETA 1-"); + SDL_WM_SetCaption("fysxasteroids -Editor-","fysxasteroids -Editor-"); engine.GetView()->SetGridSize (8,8); @@ -159,6 +178,7 @@ int main (int argc, char* argv[]) { // run the default commands and load the configuration Engine::RunCommand ("exec asteroids.rc"); Engine::RunCommand ("exec config.rc"); + Engine::SetMusicVolume (0.); asteroids::GetView()->PopViewState(); asteroids::GetView()->PushViewState(asteroids::ViewStateEditor); diff --git a/asteroids/main.cc b/asteroids/main.cc index f21a0d1..eaf5ebd 100644 --- a/asteroids/main.cc +++ b/asteroids/main.cc @@ -115,8 +115,15 @@ int main (int argc, char* argv[]) { SetLogPrintLevel (Engine::LogLevelMessage); + std::string user_path = "."; + std::string game_data_path = "."; + +#ifndef WIN32 + user_path = create_user_path(); + game_data_path = find_game_data_dir(); +#endif + // we assume the user path to be local folder - std::string user_path = create_user_path(); std::string log_file_path = user_path; log_file_path += "/game.log"; @@ -124,7 +131,6 @@ int main (int argc, char* argv[]) { engine.SetUserDataPath (user_path); Engine::SetLogFilename (log_file_path.c_str()); - std::string game_data_path = find_game_data_dir(); engine.SetGameDataPath (game_data_path); cout << "Game Data Dir = " << game_data_path << endl; @@ -142,7 +148,7 @@ int main (int argc, char* argv[]) { else SDL_WM_SetIcon(image,NULL); - SDL_WM_SetCaption("Asteroids -BETA1-","Asteroids -BETA 1-"); + SDL_WM_SetCaption("fysxasteroids -BETA 2-","fysxasteroids -BETA 2-"); engine.GetView()->SetGridSize (8,8); @@ -156,6 +162,8 @@ int main (int argc, char* argv[]) { Engine::RunCommand ("exec asteroids.rc"); Engine::RunCommand ("exec config.rc"); + Engine::PlayMusic (Engine::GetResourceFullPath("/data/sounds/intro_music.ogg")); + engine.MainLoop (); // save the configuration