HYPNO: refactor arcade code to use a function to process keys

This commit is contained in:
neuromancer 2022-04-14 20:58:53 +02:00
parent a546023f65
commit 31a772cbca
6 changed files with 55 additions and 45 deletions

View File

@ -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:

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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") {

View File

@ -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);