FREESCAPE: moved key processing code from driller into a separated class

This commit is contained in:
neuromancer
2022-11-06 22:00:08 +01:00
committed by Eugene Sandulenko
parent 95b3be0ad6
commit be64f76e9e
3 changed files with 45 additions and 35 deletions
+5 -35
View File
@@ -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:
+3
View File
@@ -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 {
+37
View File
@@ -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