1
0
Fork 0
mirror of https://github.com/k4zmu2a/SpaceCadetPinball.git synced 2024-12-18 10:37:53 +01:00

Simplified game mode, pause.

This commit is contained in:
Muzychenko Andrey 2022-01-05 11:38:50 +03:00
parent d8ee1b9bfe
commit 43af97127b
7 changed files with 75 additions and 111 deletions

View file

@ -197,7 +197,7 @@ void TDemo::FlipLeft(int timerId, void* caller)
void TDemo::NewGameRestartTimer(int timerId, void* caller) void TDemo::NewGameRestartTimer(int timerId, void* caller)
{ {
auto demo = static_cast<TDemo*>(caller); auto demo = static_cast<TDemo*>(caller);
pb::replay_level(1); pb::replay_level(true);
demo->PinballTable->Message(1014, static_cast<float>(demo->PinballTable->PlayerCount)); demo->PinballTable->Message(1014, static_cast<float>(demo->PinballTable->PlayerCount));
demo->RestartGameTimer = 0; demo->RestartGameTimer = 0;
} }

View file

@ -381,7 +381,7 @@ int TPinballTable::Message(int code, float value)
{ {
timer::kill(EndGameTimeoutTimer); timer::kill(EndGameTimeoutTimer);
EndGame_timeout(0, this); EndGame_timeout(0, this);
pb::mode_change(1); pb::mode_change(GameModes::InGame);
} }
if (LightShowTimer) if (LightShowTimer)
{ {

View file

@ -2870,7 +2870,7 @@ void control::GameoverController(int code, TPinballComponent* caller)
if (code == 66) if (code == 66)
{ {
control_goal_lights_tag.Component->Message(20, 0.0); control_goal_lights_tag.Component->Message(20, 0.0);
pb::mode_change(2); pb::mode_change(GameModes::GameOver);
control_flip1_tag.Component->Message(1022, 0.0); control_flip1_tag.Component->Message(1022, 0.0);
control_flip2_tag.Component->Message(1022, 0.0); control_flip2_tag.Component->Message(1022, 0.0);
control_mission_text_box_tag.Component->MessageField = 0; control_mission_text_box_tag.Component->MessageField = 0;

View file

@ -29,10 +29,11 @@
TPinballTable* pb::MainTable = nullptr; TPinballTable* pb::MainTable = nullptr;
DatFile* pb::record_table = nullptr; DatFile* pb::record_table = nullptr;
int pb::time_ticks = 0, pb::demo_mode = 0, pb::game_mode = 2; int pb::time_ticks = 0;
float pb::mode_countdown_, pb::time_now = 0, pb::time_next = 0, pb::ball_speed_limit, pb::time_ticks_remainder = 0; GameModes pb::game_mode = GameModes::GameOver;
float pb::time_now = 0, pb::time_next = 0, pb::ball_speed_limit, pb::time_ticks_remainder = 0;
high_score_struct pb::highscore_table[5]; high_score_struct pb::highscore_table[5];
bool pb::FullTiltMode = false, pb::FullTiltDemoMode = false, pb::cheat_mode = false; bool pb::FullTiltMode = false, pb::FullTiltDemoMode = false, pb::cheat_mode = false, pb::demo_mode = false;
std::string pb::DatFileName; std::string pb::DatFileName;
@ -89,10 +90,7 @@ int pb::init()
loader::loadfrom(record_table); loader::loadfrom(record_table);
if (pinball::quickFlag) mode_change(GameModes::InGame);
mode_change(1);
else
mode_change(3);
time_ticks = 0; time_ticks = 0;
timer::init(150); timer::init(150);
@ -171,11 +169,11 @@ void pb::firsttime_setup()
render::update(); render::update();
} }
void pb::mode_change(int mode) void pb::mode_change(GameModes mode)
{ {
switch (mode) switch (mode)
{ {
case 1: case GameModes::InGame:
if (demo_mode) if (demo_mode)
{ {
winmain::LaunchBallEnabled = false; winmain::LaunchBallEnabled = false;
@ -199,7 +197,7 @@ void pb::mode_change(int mode)
} }
} }
break; break;
case 2: case GameModes::GameOver:
winmain::LaunchBallEnabled = false; winmain::LaunchBallEnabled = false;
if (!demo_mode) if (!demo_mode)
{ {
@ -209,12 +207,6 @@ void pb::mode_change(int mode)
if (MainTable && MainTable->LightGroup) if (MainTable && MainTable->LightGroup)
MainTable->LightGroup->Message(29, 1.4f); MainTable->LightGroup->Message(29, 1.4f);
break; break;
case 3:
case 4:
winmain::LaunchBallEnabled = false;
winmain::HighScoresEnabled = false;
mode_countdown_ = 5000.f;
break;
} }
game_mode = mode; game_mode = mode;
} }
@ -223,23 +215,23 @@ void pb::toggle_demo()
{ {
if (demo_mode) if (demo_mode)
{ {
demo_mode = 0; demo_mode = false;
MainTable->Message(1024, 0.0); MainTable->Message(1024, 0.0);
mode_change(2); mode_change(GameModes::GameOver);
pinball::MissTextBox->Clear(); pinball::MissTextBox->Clear();
auto text = pinball::get_rc_string(24, 0); auto text = pinball::get_rc_string(24, 0);
pinball::InfoTextBox->Display(text, -1.0); pinball::InfoTextBox->Display(text, -1.0);
} }
else else
{ {
replay_level(1); replay_level(true);
} }
} }
void pb::replay_level(int demoMode) void pb::replay_level(bool demoMode)
{ {
demo_mode = demoMode; demo_mode = demoMode;
mode_change(1); mode_change(GameModes::InGame);
if (options::Options.Music) if (options::Options.Music)
midi::play_pb_theme(); midi::play_pb_theme();
MainTable->Message(1014, static_cast<float>(options::Options.Players)); MainTable->Message(1014, static_cast<float>(options::Options.Players));
@ -261,9 +253,8 @@ void pb::frame(float dtMilliSec)
dtMilliSec = 100; dtMilliSec = 100;
if (dtMilliSec <= 0) if (dtMilliSec <= 0)
return; return;
float dtSec = dtMilliSec * 0.001f; float dtSec = dtMilliSec * 0.001f;
if (!mode_countdown(dtMilliSec))
{
time_next = time_now + dtSec; time_next = time_now + dtSec;
timed_frame(time_now, dtSec, true); timed_frame(time_now, dtSec, true);
time_now = time_next; time_now = time_next;
@ -297,7 +288,6 @@ void pb::frame(float dtMilliSec)
MainTable->tilt(time_now); MainTable->tilt(time_now);
} }
} }
}
void pb::timed_frame(float timeNow, float timeDelta, bool drawBalls) void pb::timed_frame(float timeNow, float timeDelta, bool drawBalls)
{ {
@ -380,7 +370,7 @@ void pb::pause_continue()
{ {
char* text; char* text;
float textTime; float textTime;
if (game_mode == 2) if (game_mode == GameModes::GameOver)
{ {
textTime = -1.0; textTime = -1.0;
text = pinball::get_rc_string(24, 0); text = pinball::get_rc_string(24, 0);
@ -406,7 +396,7 @@ void pb::loose_focus()
void pb::InputUp(GameInput input) void pb::InputUp(GameInput input)
{ {
if (game_mode != 1 || winmain::single_step || demo_mode) if (game_mode != GameModes::InGame || winmain::single_step || demo_mode)
return; return;
if (AnyBindingMatchesInput(options::Options.Key.LeftFlipper, input)) if (AnyBindingMatchesInput(options::Options.Key.LeftFlipper, input))
@ -438,15 +428,9 @@ void pb::InputUp(GameInput input)
void pb::InputDown(GameInput input) void pb::InputDown(GameInput input)
{ {
options::InputDown(input); options::InputDown(input);
if (winmain::single_step || demo_mode) if (game_mode != GameModes::InGame || winmain::single_step || demo_mode)
return; return;
if (game_mode != 1)
{
mode_countdown(-1.f);
return;
}
if (input.Type == InputTypes::Keyboard) if (input.Type == InputTypes::Keyboard)
control::pbctrl_bdoor_controller(static_cast<char>(input.Value)); control::pbctrl_bdoor_controller(static_cast<char>(input.Value));
@ -529,29 +513,6 @@ void pb::InputDown(GameInput input)
} }
} }
int pb::mode_countdown(float time)
{
if (!game_mode || game_mode <= 0)
return 1;
if (game_mode > 2)
{
if (game_mode == 3)
{
mode_countdown_ -= time;
if (mode_countdown_ < 0.f || time < 0.f)
mode_change(4);
}
else if (game_mode == 4)
{
mode_countdown_ -= time;
if (mode_countdown_ < 0.f || time < 0.f)
mode_change(1);
}
return 1;
}
return 0;
}
void pb::launch_ball() void pb::launch_ball()
{ {
MainTable->Plunger->Message(1017, 0.0f); MainTable->Plunger->Message(1017, 0.0f);
@ -563,7 +524,7 @@ void pb::end_game()
int scoreIndex[4]{}; int scoreIndex[4]{};
char String1[200]; char String1[200];
mode_change(2); mode_change(GameModes::GameOver);
int playerCount = MainTable->PlayerCount; int playerCount = MainTable->PlayerCount;
score_struct_super* scorePtr = MainTable->PlayerScores; score_struct_super* scorePtr = MainTable->PlayerScores;

View file

@ -6,6 +6,12 @@ class TPinballTable;
class DatFile; class DatFile;
class TBall; class TBall;
enum class GameModes
{
InGame = 1,
GameOver = 2,
};
class UsingSdlHint class UsingSdlHint
{ {
public: public:
@ -35,7 +41,7 @@ class pb
public: public:
static int time_ticks; static int time_ticks;
static float ball_speed_limit, time_now, time_next, time_ticks_remainder; static float ball_speed_limit, time_now, time_next, time_ticks_remainder;
static int game_mode; static GameModes game_mode;
static bool cheat_mode; static bool cheat_mode;
static DatFile* record_table; static DatFile* record_table;
static TPinballTable* MainTable; static TPinballTable* MainTable;
@ -48,9 +54,9 @@ public:
static void SelectDatFile(const std::vector<const char*>& dataSearchPaths); static void SelectDatFile(const std::vector<const char*>& dataSearchPaths);
static void reset_table(); static void reset_table();
static void firsttime_setup(); static void firsttime_setup();
static void mode_change(int mode); static void mode_change(GameModes mode);
static void toggle_demo(); static void toggle_demo();
static void replay_level(int demoMode); static void replay_level(bool demoMode);
static void ballset(float dx, float dy); static void ballset(float dx, float dy);
static void frame(float dtMilliSec); static void frame(float dtMilliSec);
static void timed_frame(float timeNow, float timeDelta, bool drawBalls); static void timed_frame(float timeNow, float timeDelta, bool drawBalls);
@ -59,7 +65,6 @@ public:
static void loose_focus(); static void loose_focus();
static void InputUp(GameInput input); static void InputUp(GameInput input);
static void InputDown(GameInput input); static void InputDown(GameInput input);
static int mode_countdown(float time);
static void launch_ball(); static void launch_ball();
static void end_game(); static void end_game();
static void high_scores(); static void high_scores();
@ -68,8 +73,7 @@ public:
static float collide(float timeNow, float timeDelta, TBall* ball); static float collide(float timeNow, float timeDelta, TBall* ball);
static void PushCheat(const std::string& cheat); static void PushCheat(const std::string& cheat);
private: private:
static int demo_mode; static bool demo_mode;
static float mode_countdown_;
static bool AnyBindingMatchesInput(GameInput (&options)[3], GameInput key); static bool AnyBindingMatchesInput(GameInput (&options)[3], GameInput key);
}; };

View file

@ -171,7 +171,7 @@ int winmain::WinMain(LPCSTR lpCmdLine)
if (strstr(lpCmdLine, "-demo")) if (strstr(lpCmdLine, "-demo"))
pb::toggle_demo(); pb::toggle_demo();
else else
pb::replay_level(0); pb::replay_level(false);
unsigned updateCounter = 0, frameCounter = 0; unsigned updateCounter = 0, frameCounter = 0;
@ -381,8 +381,7 @@ void winmain::RenderUi()
if (ImGui::MenuItem("High Scores...", nullptr, false, HighScoresEnabled)) if (ImGui::MenuItem("High Scores...", nullptr, false, HighScoresEnabled))
{ {
if (!single_step) pause(false);
pause();
pb::high_scores(); pb::high_scores();
} }
if (ImGui::MenuItem("Demo", nullptr, DemoActive)) if (ImGui::MenuItem("Demo", nullptr, DemoActive))
@ -454,8 +453,7 @@ void winmain::RenderUi()
if (ImGui::MenuItem("Player Controls...", "F8")) if (ImGui::MenuItem("Player Controls...", "F8"))
{ {
if (!single_step) pause(false);
pause();
options::ShowControlDialog(); options::ShowControlDialog();
} }
if (ImGui::BeginMenu("Table Resolution")) if (ImGui::BeginMenu("Table Resolution"))
@ -556,8 +554,8 @@ void winmain::RenderUi()
#endif #endif
if (ImGui::MenuItem("Sprite Viewer", nullptr, ShowSpriteViewer)) if (ImGui::MenuItem("Sprite Viewer", nullptr, ShowSpriteViewer))
{ {
if (!ShowSpriteViewer && !single_step) if (!ShowSpriteViewer)
pause(); pause(false);
ShowSpriteViewer ^= true; ShowSpriteViewer ^= true;
} }
if (pb::cheat_mode && ImGui::MenuItem("Frame Times", nullptr, DispGRhistory)) if (pb::cheat_mode && ImGui::MenuItem("Frame Times", nullptr, DispGRhistory))
@ -585,8 +583,7 @@ void winmain::RenderUi()
if (ImGui::MenuItem("About Pinball")) if (ImGui::MenuItem("About Pinball"))
{ {
if (!single_step) pause(false);
pause();
ShowAboutDialog = true; ShowAboutDialog = true;
} }
ImGui::EndMenu(); ImGui::EndMenu();
@ -677,8 +674,7 @@ int winmain::event_handler(const SDL_Event* event)
options::toggle(Menu1::Music); options::toggle(Menu1::Music);
break; break;
case SDLK_F8: case SDLK_F8:
if (!single_step) pause(false);
pause();
options::ShowControlDialog(); options::ShowControlDialog();
break; break;
case SDLK_F9: case SDLK_F9:
@ -928,14 +924,17 @@ void winmain::end_pause()
void winmain::new_game() void winmain::new_game()
{ {
end_pause(); end_pause();
pb::replay_level(0); pb::replay_level(false);
} }
void winmain::pause() void winmain::pause(bool toggle)
{
if (toggle || !single_step)
{ {
pb::pause_continue(); pb::pause_continue();
no_time_loss = true; no_time_loss = true;
} }
}
void winmain::Restart() void winmain::Restart()
{ {

View file

@ -81,7 +81,7 @@ public:
static void a_dialog(); static void a_dialog();
static void end_pause(); static void end_pause();
static void new_game(); static void new_game();
static void pause(); static void pause(bool toggle = true);
static void Restart(); static void Restart();
static bool RestartRequested() { return restart; } static bool RestartRequested() { return restart; }
static void UpdateFrameRate(); static void UpdateFrameRate();