aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/zvision/lever_control.cpp37
-rw-r--r--engines/zvision/lever_control.h5
2 files changed, 34 insertions, 8 deletions
diff --git a/engines/zvision/lever_control.cpp b/engines/zvision/lever_control.cpp
index 3c452c3dd8..91e54075b6 100644
--- a/engines/zvision/lever_control.cpp
+++ b/engines/zvision/lever_control.cpp
@@ -47,7 +47,9 @@ LeverControl::LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStre
_currentFrame(0),
_lastRenderedFrame(0),
_mouseIsCaptured(false),
- _isReturning(false) {
+ _isReturning(false),
+ _accumulatedTime(0),
+ _returnRoutesCurrentFrame(0) {
// Loop until we find the closing brace
Common::String line = stream.readLine();
@@ -204,11 +206,9 @@ void LeverControl::onMouseUp(const Common::Point &screenSpacePos, const Common::
_mouseIsCaptured = false;
_engine->getScriptManager()->setStateValue(_key, _currentFrame);
- if (_frameInfo[_currentFrame].hotspot.contains(backgroundImageSpacePos)) {
-
- }
-
- // TODO: Animation reversal back to origin
+ _isReturning = true;
+ _returnRoutesCurrentProgress = _frameInfo[_currentFrame].returnRoute.begin();
+ _returnRoutesCurrentFrame = _currentFrame;
}
bool LeverControl::onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) {
@@ -247,8 +247,31 @@ bool LeverControl::process(uint32 deltaTimeInMillis) {
return false;
}
- // TODO: Implement reversal over time
+ if (_isReturning) {
+ _accumulatedTime += deltaTimeInMillis;
+ while (_accumulatedTime >= ANIMATION_FRAME_TIME) {
+ _accumulatedTime -= ANIMATION_FRAME_TIME;
+ if (_returnRoutesCurrentFrame == *_returnRoutesCurrentProgress) {
+ _returnRoutesCurrentProgress++;
+ }
+ if (_returnRoutesCurrentProgress == _frameInfo[_currentFrame].returnRoute.end()) {
+ _isReturning = false;
+ _currentFrame = _returnRoutesCurrentFrame;
+ _engine->getScriptManager()->setStateValue(_key, _currentFrame);
+ return false;
+ }
+ uint toFrame = *_returnRoutesCurrentProgress;
+ if (_returnRoutesCurrentFrame < toFrame) {
+ _returnRoutesCurrentFrame++;
+ } else if (_returnRoutesCurrentFrame > toFrame) {
+ _returnRoutesCurrentFrame--;
+ }
+
+ renderFrame(_returnRoutesCurrentFrame);
+ }
+ }
+
return false;
}
diff --git a/engines/zvision/lever_control.h b/engines/zvision/lever_control.h
index d359318d2f..b5677a269e 100644
--- a/engines/zvision/lever_control.h
+++ b/engines/zvision/lever_control.h
@@ -61,7 +61,8 @@ private:
};
enum {
- ANGLE_DELTA = 30 // How far off a mouse angle can be and still be considered valid. This is in both directions, so the total buffer zone is (2 * ANGLE_DELTA)
+ ANGLE_DELTA = 30, // How far off a mouse angle can be and still be considered valid. This is in both directions, so the total buffer zone is (2 * ANGLE_DELTA)
+ ANIMATION_FRAME_TIME = 30 // In millis
};
private:
@@ -85,6 +86,8 @@ private:
bool _isReturning;
Common::Point _lastMousePos;
Common::List<uint>::iterator _returnRoutesCurrentProgress;
+ uint _returnRoutesCurrentFrame;
+ uint32 _accumulatedTime;
public:
void onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos);