diff --git a/engines/freescape/freescape.cpp b/engines/freescape/freescape.cpp index 3f4da5fcba4..ac0f5257539 100644 --- a/engines/freescape/freescape.cpp +++ b/engines/freescape/freescape.cpp @@ -124,6 +124,8 @@ void FreescapeEngine::drawFrame() { drawUI(); } +void FreescapeEngine::pressedKey(const int keycode) {} + void FreescapeEngine::processInput() { float currentFrame = g_system->getMillis(); float deltaTime = currentFrame - _lastFrame; @@ -150,42 +152,10 @@ void FreescapeEngine::processInput() { lower(); else if (event.kbd.keycode == Common::KEYCODE_n) gotoArea(_currentArea->getAreaID() + 1, 0); - else if (event.kbd.keycode == Common::KEYCODE_d) { - Common::Point gasPocket = _currentArea->gasPocketPosition; - uint32 gasPocketRadius = _currentArea->gasPocketRadius; - if (isDriller() && gasPocketRadius > 0 && !_currentArea->drillDeployed()) { - if (_gameStateVars[k8bitVariableEnergy] < 5) { - // Show "no enough energy" message - continue; - } - - _gameStateVars[k8bitVariableEnergy] = _gameStateVars[k8bitVariableEnergy] - 5; - _gameStateVars[32]++; - // TODO: check if there is space for the drill - Math::Vector3d drillPosition = _position + _cameraFront * 128; - drillPosition.setValue(1, _position.y() - _playerHeight * _currentArea->getScale()); - debugC(1, kFreescapeDebugMove, "Trying to adding drill at %f %f %f", drillPosition.x(), drillPosition.y(), drillPosition.z()); - const Math::Vector3d gasPocket3D(gasPocket.x, 1, gasPocket.y); - _currentArea->addDrill(globalObjectsArea, drillPosition); - float distance = (gasPocket3D - drillPosition).length(); - debugC(1, kFreescapeDebugMove, "length to gas pocket: %f with radius %d", distance, _currentArea->gasPocketRadius); - // TODO check the result of the drilling - // TODO: reduce energy - } - } else if (event.kbd.keycode == Common::KEYCODE_c) { - - if (isDriller() && _currentArea->drillDeployed()) { - if (_gameStateVars[k8bitVariableEnergy] < 5) { - // Show "no enough energy" message - continue; - } - - _gameStateVars[k8bitVariableEnergy] = _gameStateVars[k8bitVariableEnergy] - 5; - _gameStateVars[32]--; - _currentArea->removeDrill(); - } - } else if (event.kbd.keycode == Common::KEYCODE_ESCAPE) + else if (event.kbd.keycode == Common::KEYCODE_ESCAPE) openMainMenuDialog(); + else + pressedKey(event.kbd.keycode); break; case Common::EVENT_QUIT: diff --git a/engines/freescape/freescape.h b/engines/freescape/freescape.h index 5556ed52c9e..b50e8c6c0fe 100644 --- a/engines/freescape/freescape.h +++ b/engines/freescape/freescape.h @@ -114,6 +114,7 @@ public: // Input bool _flyMode; void processInput(); + virtual void pressedKey(const int keycode); void move(CameraMovement direction, uint8 scale, float deltaTime); void changePlayerHeight(int delta); void rise(); @@ -210,6 +211,8 @@ public: void loadAssets() override; void drawUI() override; + + void pressedKey(const int keycode) override; }; class DarkEngine : public FreescapeEngine { diff --git a/engines/freescape/games/driller.cpp b/engines/freescape/games/driller.cpp index 9845bcde69e..f00b6f27e7a 100644 --- a/engines/freescape/games/driller.cpp +++ b/engines/freescape/games/driller.cpp @@ -20,6 +20,7 @@ */ #include "common/config-manager.h" +#include "common/events.h" #include "common/file.h" #include "freescape/freescape.h" @@ -80,5 +81,41 @@ void DrillerEngine::drawUI() { _gfx->setViewport(_viewArea); } +void DrillerEngine::pressedKey(const int keycode) { + if (keycode == Common::KEYCODE_d) { + Common::Point gasPocket = _currentArea->gasPocketPosition; + uint32 gasPocketRadius = _currentArea->gasPocketRadius; + if (gasPocketRadius > 0 && !_currentArea->drillDeployed()) { + if (_gameStateVars[k8bitVariableEnergy] < 5) { + // Show "no enough energy" message + return; + } + + _gameStateVars[k8bitVariableEnergy] = _gameStateVars[k8bitVariableEnergy] - 5; + _gameStateVars[32]++; + // TODO: check if there is space for the drill + Math::Vector3d drillPosition = _position + _cameraFront * 128; + drillPosition.setValue(1, _position.y() - _playerHeight * _currentArea->getScale()); + debugC(1, kFreescapeDebugMove, "Trying to adding drill at %f %f %f", drillPosition.x(), drillPosition.y(), drillPosition.z()); + const Math::Vector3d gasPocket3D(gasPocket.x, 1, gasPocket.y); + _currentArea->addDrill(globalObjectsArea, drillPosition); + float distance = (gasPocket3D - drillPosition).length(); + debugC(1, kFreescapeDebugMove, "length to gas pocket: %f with radius %d", distance, _currentArea->gasPocketRadius); + // TODO check the result of the drilling + // TODO: reduce energy + } + } else if (keycode == Common::KEYCODE_c) { + if (_currentArea->drillDeployed()) { + if (_gameStateVars[k8bitVariableEnergy] < 5) { + // Show "no enough energy" message + return; + } + + _gameStateVars[k8bitVariableEnergy] = _gameStateVars[k8bitVariableEnergy] - 5; + _gameStateVars[32]--; + _currentArea->removeDrill(); + } + } +} } // End of namespace Freescape \ No newline at end of file