From 31a772cbca7fc1b93609040a67f9f567fb8557d7 Mon Sep 17 00:00:00 2001 From: neuromancer Date: Thu, 14 Apr 2022 20:58:53 +0200 Subject: [PATCH] HYPNO: refactor arcade code to use a function to process keys --- engines/hypno/arcade.cpp | 26 +++----------------------- engines/hypno/hypno.h | 3 +++ engines/hypno/spider/arcade.cpp | 24 ++++++++++++++++++++++++ engines/hypno/spider/hard.cpp | 24 +++++++----------------- engines/hypno/wet/arcade.cpp | 18 ++++++++++++++++++ engines/hypno/wet/wet.cpp | 5 ----- 6 files changed, 55 insertions(+), 45 deletions(-) diff --git a/engines/hypno/arcade.cpp b/engines/hypno/arcade.cpp index cd476df9e3c..c9d4daf58b9 100644 --- a/engines/hypno/arcade.cpp +++ b/engines/hypno/arcade.cpp @@ -167,6 +167,8 @@ void HypnoEngine::missNoTarget(ArcadeShooting *arc) {} void HypnoEngine::runBeforeArcade(ArcadeShooting *arc) {} void HypnoEngine::runAfterArcade(ArcadeShooting *arc) {} +void HypnoEngine::pressedKey(const int keycode) {} + void HypnoEngine::initSegment(ArcadeShooting *arc) { error("Function \"%s\" not implemented", __FUNCTION__); } void HypnoEngine::findNextSegment(ArcadeShooting *arc) { error("Function \"%s\" not implemented", __FUNCTION__); } @@ -246,29 +248,7 @@ void HypnoEngine::runArcade(ArcadeShooting *arc) { break; case Common::EVENT_KEYDOWN: - if (event.kbd.keycode == Common::KEYCODE_c) { - _background->decoder->pauseVideo(true); - showCredits(); - loadPalette(currentPalette); - changeScreenMode("320x200"); - _background->decoder->pauseVideo(false); - updateScreen(*_background); - drawScreen(); - } else if (event.kbd.keycode == Common::KEYCODE_k) { // Added for testing - _health = 0; - } else if (event.kbd.keycode == Common::KEYCODE_LEFT) { - _lastPlayerPosition = _currentPlayerPosition; - _currentPlayerPosition = kPlayerLeft; - } else if (event.kbd.keycode == Common::KEYCODE_DOWN) { - _lastPlayerPosition = _currentPlayerPosition; - _currentPlayerPosition = kPlayerBottom; - } else if (event.kbd.keycode == Common::KEYCODE_RIGHT) { - _lastPlayerPosition = _currentPlayerPosition; - _currentPlayerPosition = kPlayerRight; - } else if (event.kbd.keycode == Common::KEYCODE_UP) { - _lastPlayerPosition = _currentPlayerPosition; - _currentPlayerPosition = kPlayerTop; - } + pressedKey(event.kbd.keycode); break; case Common::EVENT_LBUTTONDOWN: diff --git a/engines/hypno/hypno.h b/engines/hypno/hypno.h index 79bd5ff8a1c..fa8164925f8 100644 --- a/engines/hypno/hypno.h +++ b/engines/hypno/hypno.h @@ -244,6 +244,7 @@ public: uint32 _lastPlayerPosition; virtual Common::Point computeTargetPosition(const Common::Point &mousePos); virtual int detectTarget(const Common::Point &mousePos); + virtual void pressedKey(const int keycode); virtual bool clickedPrimaryShoot(const Common::Point &mousePos); virtual bool clickedSecondaryShoot(const Common::Point &mousePos); virtual void drawShoot(const Common::Point &mousePos); @@ -387,6 +388,7 @@ public: void saveProfile(const Common::String &name, int levelId); // Arcade + void pressedKey(const int keycode) override; void runBeforeArcade(ArcadeShooting *arc) override; void runAfterArcade(ArcadeShooting *arc) override; void findNextSegment(ArcadeShooting *arc) override; @@ -426,6 +428,7 @@ public: void hitPlayer() override; // Arcade + void pressedKey(const int keycode) override; void runBeforeArcade(ArcadeShooting *arc) override; void runAfterArcade(ArcadeShooting *arc) override; void findNextSegment(ArcadeShooting *arc) override; diff --git a/engines/hypno/spider/arcade.cpp b/engines/hypno/spider/arcade.cpp index cdb7bf03a2e..4a4471ed3d2 100644 --- a/engines/hypno/spider/arcade.cpp +++ b/engines/hypno/spider/arcade.cpp @@ -90,6 +90,30 @@ void SpiderEngine::findNextSegment(ArcadeShooting *arc) { _segmentIdx = _segmentIdx + 1; } + +void SpiderEngine::pressedKey(const int keycode) { + if (keycode == Common::KEYCODE_c) { + if (_cheatsEnabled) { + _skipLevel = true; + return; + } + } else if (keycode == Common::KEYCODE_k) { // Added for testing + _health = 0; + } else if (keycode == Common::KEYCODE_LEFT) { + _lastPlayerPosition = _currentPlayerPosition; + _currentPlayerPosition = kPlayerLeft; + } else if (keycode == Common::KEYCODE_DOWN) { + _lastPlayerPosition = _currentPlayerPosition; + _currentPlayerPosition = kPlayerBottom; + } else if (keycode == Common::KEYCODE_RIGHT) { + _lastPlayerPosition = _currentPlayerPosition; + _currentPlayerPosition = kPlayerRight; + } else if (keycode == Common::KEYCODE_UP) { + _lastPlayerPosition = _currentPlayerPosition; + _currentPlayerPosition = kPlayerTop; + } +} + void SpiderEngine::missedTarget(Shoot *s, ArcadeShooting *arc) { if (_arcadeMode != "YC" && _arcadeMode != "YD") return; diff --git a/engines/hypno/spider/hard.cpp b/engines/hypno/spider/hard.cpp index ed7a5870f43..8a973a10785 100644 --- a/engines/hypno/spider/hard.cpp +++ b/engines/hypno/spider/hard.cpp @@ -1096,24 +1096,14 @@ void SpiderEngine::showScore(const Common::String prefix) { } void SpiderEngine::showCredits() { - if (_cheatsEnabled && !_arcadeMode.empty()) { - _skipLevel = true; - return; - } - - if (!_arcadeMode.empty()) - return; // No credits during arcade sequence - - if (!isDemo()) { // No credits in demo - changeScreenMode("640x480"); - MVideo video("cine/credits.smk", Common::Point(0, 0), false, true, false); - runIntro(video); - if (_restoredContentEnabled) { - showScore("Spider-Man saved the day!"); - } - _score = 0; - _nextLevel = "mainmenu.mi_"; + changeScreenMode("640x480"); + MVideo video("cine/credits.smk", Common::Point(0, 0), false, true, false); + runIntro(video); + if (_restoredContentEnabled) { + showScore("Spider-Man saved the day!"); } + _score = 0; + _nextLevel = "mainmenu.mi_"; } } // End of namespace Hypno \ No newline at end of file diff --git a/engines/hypno/wet/arcade.cpp b/engines/hypno/wet/arcade.cpp index f35a0032151..679e57ffb28 100644 --- a/engines/hypno/wet/arcade.cpp +++ b/engines/hypno/wet/arcade.cpp @@ -463,6 +463,24 @@ void WetEngine::runBeforeArcade(ArcadeShooting *arc) { _playerFrameIdx = -1; } +void WetEngine::pressedKey(const int keycode) { + if (keycode == Common::KEYCODE_c) { + if (_cheatsEnabled) { + _skipLevel = true; + return; + } + _background->decoder->pauseVideo(true); + showCredits(); + //loadPalette(currentPalette); //FIXME + changeScreenMode("320x200"); + _background->decoder->pauseVideo(false); + updateScreen(*_background); + drawScreen(); + } else if (keycode == Common::KEYCODE_k) { // Added for testing + _health = 0; + } +} + void WetEngine::drawCursorArcade(const Common::Point &mousePos) { int i = detectTarget(mousePos); if (_arcadeMode == "YT") { diff --git a/engines/hypno/wet/wet.cpp b/engines/hypno/wet/wet.cpp index 0f44d399007..0457851eca3 100644 --- a/engines/hypno/wet/wet.cpp +++ b/engines/hypno/wet/wet.cpp @@ -389,11 +389,6 @@ void WetEngine::loadAssetsFullGame() { } void WetEngine::showCredits() { - if (_cheatsEnabled && !_arcadeMode.empty()) { - _skipLevel = true; - return; - } - if (!isDemo() || (_variant == "Demo" && _language == Common::EN_USA)) { MVideo video("c_misc/credits.smk", Common::Point(0, 0), false, true, false); runIntro(video);