beta 2 + editor for the windows version

main
Martin Felis (berta win) 2011-02-13 15:31:42 +01:00
parent 5359374304
commit 2cb35eab1f
8 changed files with 61 additions and 14 deletions

View File

@ -69,8 +69,6 @@ int Model::OnInit (int argc, char* argv[]) {
mLevelAuthor = ""; mLevelAuthor = "";
mLevelTitle = ""; mLevelTitle = "";
Engine::PlayMusic (Engine::GetResourceFullPath("/data/sounds/intro_music.ogg"));
Engine::RegisterListener (this, EventAccelerateStart); Engine::RegisterListener (this, EventAccelerateStart);
Engine::RegisterListener (this, EventAccelerateStop); Engine::RegisterListener (this, EventAccelerateStop);
@ -427,6 +425,8 @@ void Model::OnNewGame() {
} }
void Model::OnShipExplode () { void Model::OnShipExplode () {
Engine::PlaySound(Engine::GetResourceFullPath("/data/sounds/rock_destroyed.wav"));
mPlayerLives --; mPlayerLives --;
if (mPlayerLives == 0) { if (mPlayerLives == 0) {

View File

@ -7,6 +7,9 @@
namespace asteroids { namespace asteroids {
Engine::Variable RocketEntity::VarTimeToLive ("rocket_timetolive", "1.0");
Engine::Variable RocketEntity::VarSpeed ("rocket_speed", "15");
void RocketEntity::Update (float delta_sec) { void RocketEntity::Update (float delta_sec) {
mSecToLive -= delta_sec; mSecToLive -= delta_sec;

View File

@ -14,6 +14,7 @@ struct RocketEntityPhysicState : public Engine::EntityPhysicState {
mType = GameEntityTypeRocket; mType = GameEntityTypeRocket;
} }
virtual ~RocketEntityPhysicState() {}; virtual ~RocketEntityPhysicState() {};
}; };
struct RocketEntity: public Engine::EntityBase { struct RocketEntity: public Engine::EntityBase {
@ -31,6 +32,9 @@ struct RocketEntity: public Engine::EntityBase {
} }
float mSecToLive; float mSecToLive;
static Engine::Variable VarTimeToLive;
static Engine::Variable VarSpeed;
}; };
} }

View File

@ -107,7 +107,7 @@ void ShipEntity::Attack () {
RocketEntity *rocket_entity = (RocketEntity*) Engine::CreateEntity (GameEntityTypeRocket); 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; RocketEntityPhysicState *rocket_physics = (RocketEntityPhysicState*) rocket_entity->mPhysicState;
rocket_physics->mPosition = attack_dir; rocket_physics->mPosition = attack_dir;
@ -115,7 +115,7 @@ void ShipEntity::Attack () {
rocket_physics->mPosition += entity_physic->mPosition; rocket_physics->mPosition += entity_physic->mPosition;
rocket_physics->mOrientation = entity_physic->mOrientation; rocket_physics->mOrientation = entity_physic->mOrientation;
rocket_physics->mVelocity = attack_dir.normalize(); 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")); Engine::PlaySound (Engine::GetResourceFullPath("/data/sounds/laser.wav"));
} }

View File

@ -476,6 +476,11 @@ void View::DrawPageTitle (const std::string& title) {
void View::DrawUiMainMenu() { void View::DrawUiMainMenu() {
DrawPageTitle ("Asteroids"); 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"); SelectFont("console.ttf size=23");
if (Engine::GUI::Button (1, "New Game", screen_right * 0.5 - 100, 200, button_width, button_height)) { if (Engine::GUI::Button (1, "New Game", screen_right * 0.5 - 100, 200, button_width, button_height)) {
PushViewState(ViewStateEnterPlayername); PushViewState(ViewStateEnterPlayername);
@ -489,10 +494,12 @@ void View::DrawUiMainMenu() {
PushViewState(ViewStateShowHighscore); PushViewState(ViewStateShowHighscore);
} }
/*
if (Engine::GUI::Button (6, "E", screen_right - 48, 20, 32, button_height)) { if (Engine::GUI::Button (6, "E", screen_right - 48, 20, 32, button_height)) {
PushViewState(ViewStateEditor); PushViewState(ViewStateEditor);
GetController()->ResetLevel(); GetController()->ResetLevel();
} }
*/
if (Engine::GUI::Button (4, "Quit", screen_right * 0.5 - 100, 380, button_width, button_height)) { if (Engine::GUI::Button (4, "Quit", screen_right * 0.5 - 100, 380, button_width, button_height)) {
Engine::RunCommand("quit"); Engine::RunCommand("quit");
@ -574,7 +581,7 @@ void View::DrawUiLevelComplete() {
GetModel()->SetGameState(GameStatePaused); GetModel()->SetGameState(GameStatePaused);
if (mEditorState == EditorStateTest) { if (mEditorState == EditorStateTest) {
GetModel()->DoLoadLevel("level_edit_temp.txt"); GetModel()->DoLoadLevel("level_edit_temp.map");
mEditorState = EditorStateUnknown; mEditorState = EditorStateUnknown;
} }
} else { } else {
@ -617,14 +624,14 @@ void View::DrawUiPlayerDied() {
if (Engine::GUI::Button (1, "Continue", screen_right * 0.5 - 100, 380, button_width, button_height)) { if (Engine::GUI::Button (1, "Continue", screen_right * 0.5 - 100, 380, button_width, button_height)) {
PopViewState(); PopViewState();
// we have to take care when we are testing the level to not proceed to // we have to take care when we are testing the level to not proceed to
// the next level... // the next level...
if (GetViewState() == ViewStateEditor) { if (GetViewState() == ViewStateEditor) {
GetModel()->SetGameState(GameStatePaused); GetModel()->SetGameState(GameStatePaused);
if (mEditorState == EditorStateTest) { if (mEditorState == EditorStateTest) {
GetModel()->DoLoadLevel("level_edit_temp.txt"); GetModel()->DoLoadLevel("level_edit_temp.map");
mEditorState = EditorStateUnknown; mEditorState = EditorStateUnknown;
} }
} else { } else {
@ -777,7 +784,7 @@ void View::DrawUiEditor() {
if (mEditorState == EditorStateTest) { if (mEditorState == EditorStateTest) {
mEditorState = EditorStateUnknown; mEditorState = EditorStateUnknown;
GetModel()->DoLoadLevel("level_edit_temp.txt"); GetModel()->DoLoadLevel("level_edit_temp.map");
GetModel()->SetGameState(GameStatePaused); GetModel()->SetGameState(GameStatePaused);
return; return;
} else if (!Engine::GUI::CheckKeyPressed(SDLK_ESCAPE)){ } 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)) { if (Engine::GUI::Button (9, "Test", 475, 20, 64, button_height)) {
mEditorState = EditorStateTest; mEditorState = EditorStateTest;
GetModel()->DoSaveLevel("level_edit_temp.txt"); GetModel()->DoSaveLevel("level_edit_temp.map");
GetModel()->SetGameState(GameStateRunning); GetModel()->SetGameState(GameStateRunning);
} }
} }

View File

@ -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()); 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 // Fire the view state change event to properly clear the IMGUI state
Engine::EventBasePtr changeviewstate_event (new Engine::EventBase()); Engine::EventBasePtr changeviewstate_event (new Engine::EventBase());
changeviewstate_event->mEventType = EventChangeViewState; changeviewstate_event->mEventType = EventChangeViewState;

View File

@ -27,10 +27,22 @@ std::string create_user_path () {
std::string test_file_path = result_dir; std::string test_file_path = result_dir;
// first we check in $HOME/.fysxasteroids // 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"); char* env_home_dir = getenv("HOME");
#endif
cout << "Yo4 " << env_home_dir << endl;
result_dir = env_home_dir; result_dir = env_home_dir;
result_dir += "/.fysxasteroids"; result_dir += "/.fysxasteroids";
cout << "Path = " << result_dir << endl;
boost::filesystem::path result_dir_path(result_dir); boost::filesystem::path result_dir_path(result_dir);
if(!boost::filesystem::is_directory (result_dir_path)) { if(!boost::filesystem::is_directory (result_dir_path)) {
if (!boost::filesystem::create_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); SetLogPrintLevel (Engine::LogLevelMessage);
// we assume the user path to be local folder // 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; std::string log_file_path = user_path;
log_file_path += "/editor.log"; log_file_path += "/editor.log";
@ -146,7 +165,7 @@ int main (int argc, char* argv[]) {
else else
SDL_WM_SetIcon(image,NULL); 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); engine.GetView()->SetGridSize (8,8);
@ -159,6 +178,7 @@ int main (int argc, char* argv[]) {
// run the default commands and load the configuration // run the default commands and load the configuration
Engine::RunCommand ("exec asteroids.rc"); Engine::RunCommand ("exec asteroids.rc");
Engine::RunCommand ("exec config.rc"); Engine::RunCommand ("exec config.rc");
Engine::SetMusicVolume (0.);
asteroids::GetView()->PopViewState(); asteroids::GetView()->PopViewState();
asteroids::GetView()->PushViewState(asteroids::ViewStateEditor); asteroids::GetView()->PushViewState(asteroids::ViewStateEditor);

View File

@ -115,8 +115,15 @@ int main (int argc, char* argv[]) {
SetLogPrintLevel (Engine::LogLevelMessage); 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 // we assume the user path to be local folder
std::string user_path = create_user_path();
std::string log_file_path = user_path; std::string log_file_path = user_path;
log_file_path += "/game.log"; log_file_path += "/game.log";
@ -124,7 +131,6 @@ int main (int argc, char* argv[]) {
engine.SetUserDataPath (user_path); engine.SetUserDataPath (user_path);
Engine::SetLogFilename (log_file_path.c_str()); Engine::SetLogFilename (log_file_path.c_str());
std::string game_data_path = find_game_data_dir();
engine.SetGameDataPath (game_data_path); engine.SetGameDataPath (game_data_path);
cout << "Game Data Dir = " << game_data_path << endl; cout << "Game Data Dir = " << game_data_path << endl;
@ -142,7 +148,7 @@ int main (int argc, char* argv[]) {
else else
SDL_WM_SetIcon(image,NULL); 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); engine.GetView()->SetGridSize (8,8);
@ -156,6 +162,8 @@ int main (int argc, char* argv[]) {
Engine::RunCommand ("exec asteroids.rc"); Engine::RunCommand ("exec asteroids.rc");
Engine::RunCommand ("exec config.rc"); Engine::RunCommand ("exec config.rc");
Engine::PlayMusic (Engine::GetResourceFullPath("/data/sounds/intro_music.ogg"));
engine.MainLoop (); engine.MainLoop ();
// save the configuration // save the configuration