aboutsummaryrefslogtreecommitdiff
path: root/engines/pink/objects
diff options
context:
space:
mode:
authorAndrei Prykhodko2018-06-23 16:26:24 +0300
committerEugene Sandulenko2018-06-28 23:51:32 +0200
commit633649398f3901b00bd8de7bc113f52971ccd940 (patch)
tree0be027a5def354409cf5647cae8a0caf768e2298 /engines/pink/objects
parentab44490673e2b8c04ba1ebe0a0ceb476f413a5b9 (diff)
downloadscummvm-rg350-633649398f3901b00bd8de7bc113f52971ccd940.tar.gz
scummvm-rg350-633649398f3901b00bd8de7bc113f52971ccd940.tar.bz2
scummvm-rg350-633649398f3901b00bd8de7bc113f52971ccd940.zip
PINK: added position recalculation of walking sprites
Diffstat (limited to 'engines/pink/objects')
-rw-r--r--engines/pink/objects/actions/action_cel.cpp4
-rw-r--r--engines/pink/objects/actions/walk_action.cpp52
-rw-r--r--engines/pink/objects/actions/walk_action.h9
-rw-r--r--engines/pink/objects/walk/walk_mgr.cpp35
-rw-r--r--engines/pink/objects/walk/walk_mgr.h10
5 files changed, 82 insertions, 28 deletions
diff --git a/engines/pink/objects/actions/action_cel.cpp b/engines/pink/objects/actions/action_cel.cpp
index a2cf1923d6..f31db4cbc9 100644
--- a/engines/pink/objects/actions/action_cel.cpp
+++ b/engines/pink/objects/actions/action_cel.cpp
@@ -77,9 +77,7 @@ Coordinates ActionCEL::getCoordinates() {
loadDecoder();
Coordinates coords;
- Common::Point point = _decoder.getCenter();
- coords.x = point.x;
- coords.y = point.y;
+ coords.point = _decoder.getCenter();
coords.z = getZ();
return coords;
diff --git a/engines/pink/objects/actions/walk_action.cpp b/engines/pink/objects/actions/walk_action.cpp
index 24b43dbdcc..cc02ef611e 100644
--- a/engines/pink/objects/actions/walk_action.cpp
+++ b/engines/pink/objects/actions/walk_action.cpp
@@ -39,16 +39,54 @@ void WalkAction::toConsole() {
}
void WalkAction::onStart() {
- // not implemented
+ if (_toCalcFramePositions) {
+ _start = _mgr->getStartCoords().point;
+ _end = _mgr->getEndCoords().point;
+
+ if (!_horizontal) {
+ _end.y = getCoordinates().point.y;
+ _start.y = _end.y;
+ _frameCount = _decoder.getFrameCount();
+ }
+ else {
+ _frameCount = (uint) abs(3 * (_start.x - _end.x) / (int)_z);
+ if (!_frameCount)
+ _frameCount = 1;
+ }
+ setCenter(_start);
+ _curFrame = 0;
+ }
}
void WalkAction::update() {
- ActionCEL::update();
- if (_decoder.getCurFrame() < (int)_decoder.getFrameCount() - 1)
- decodeNext();
- else {
- _decoder.setEndOfTrack();
- _actor->endAction();
+ if (_toCalcFramePositions) {
+ if (_curFrame < _frameCount)
+ _curFrame++;
+ const double k = _curFrame / (double) _frameCount;
+ Common::Point newCenter;
+ newCenter.x = (_end.x - _start.x) * k + _start.x;
+ if (_horizontal) {
+ newCenter.y = (_end.y - _start.y) * k + _start.y;
+ } else {
+ newCenter.y = getCoordinates().point.y;
+ }
+ if (_decoder.getCurFrame() < (int)_decoder.getFrameCount() - 1)
+ decodeNext();
+ else {
+ setFrame(0);
+ }
+ setCenter(newCenter);
+ if (_curFrame >= _frameCount - 1) {
+ _decoder.setEndOfTrack();
+ _actor->endAction();
+ }
+ } else {
+ if (_decoder.getCurFrame() < (int)_decoder.getFrameCount() - 1)
+ decodeNext();
+ else {
+ _decoder.setEndOfTrack();
+ _actor->endAction();
+ }
}
}
diff --git a/engines/pink/objects/actions/walk_action.h b/engines/pink/objects/actions/walk_action.h
index d311b9e9bb..b49bb45530 100644
--- a/engines/pink/objects/actions/walk_action.h
+++ b/engines/pink/objects/actions/walk_action.h
@@ -35,10 +35,19 @@ public:
void update() override;
+ void setWalkMgr(WalkMgr *mgr) { _mgr = mgr; }
+ void setType(bool horizontal) { _horizontal = horizontal; }
+
protected:
void onStart() override;
private:
+ WalkMgr *_mgr;
+ Common::Point _start;
+ Common::Point _end;
+ uint _curFrame;
+ uint _frameCount;
+ bool _horizontal;
bool _toCalcFramePositions;
};
diff --git a/engines/pink/objects/walk/walk_mgr.cpp b/engines/pink/objects/walk/walk_mgr.cpp
index e9d2bb06c9..9b23f7b72b 100644
--- a/engines/pink/objects/walk/walk_mgr.cpp
+++ b/engines/pink/objects/walk/walk_mgr.cpp
@@ -64,7 +64,7 @@ void WalkMgr::start(WalkLocation *destination) {
if (_current.name.empty()) {
_current.name = _locations[0]->getName();
- _current.coord = getLocationCoordinates(_locations[0]->getName());
+ _current.coords = getLocationCoordinates(_locations[0]->getName());
}
_destination = destination;
@@ -83,29 +83,34 @@ void WalkMgr::start(WalkLocation *destination) {
void WalkMgr::initNextWayPoint(WalkLocation *location) {
_next.name = location->getName();
- _next.coord = getLocationCoordinates(location->getName());
+ _next.coords = getLocationCoordinates(location->getName());
}
WalkAction *WalkMgr::getWalkAction() {
Common::String walkActionName;
- if (_current.coord.z == _next.coord.z) {
- if (_next.coord.x > _current.coord.x) {
- walkActionName = Common::String::format("%dRight", _current.coord.z);
+ bool horizontal = false;
+ if (_current.coords.z == _next.coords.z) {
+ if (_next.coords.point.x > _current.coords.point.x) {
+ walkActionName = Common::String::format("%dRight", _current.coords.z);
} else
- walkActionName = Common::String::format("%dLeft", _next.coord.z);
+ walkActionName = Common::String::format("%dLeft", _next.coords.z);
+ horizontal = true;
} else
- walkActionName = Common::String::format("%dTo%d", _current.coord.z, _next.coord.z);
+ walkActionName = Common::String::format("%dTo%d", _current.coords.z, _next.coords.z);
- Action *action = _leadActor->findAction(walkActionName);
-
- return static_cast<WalkAction *>(action);
+ WalkAction *action = (WalkAction *) _leadActor->findAction(walkActionName);
+ if (action) {
+ action->setWalkMgr(this);
+ action->setType(horizontal);
+ }
+ return action;
}
double WalkMgr::getLengthBetweenLocations(WalkLocation *first, WalkLocation *second) {
Coordinates firstCoord = getLocationCoordinates(first->getName());
Coordinates secondCoord = getLocationCoordinates(second->getName());
- return sqrt((secondCoord.x - firstCoord.x) * (secondCoord.x - firstCoord.x) +
- (secondCoord.y - firstCoord.y) * (secondCoord.y - firstCoord.y));
+ return sqrt((secondCoord.point.x - firstCoord.point.x) * (secondCoord.point.x - firstCoord.point.x) +
+ (secondCoord.point.y - firstCoord.point.y) * (secondCoord.point.y - firstCoord.point.y));
}
Coordinates WalkMgr::getLocationCoordinates(const Common::String &locationName) {
@@ -115,7 +120,7 @@ Coordinates WalkMgr::getLocationCoordinates(const Common::String &locationName)
void WalkMgr::setCurrentWayPoint(WalkLocation *location) {
_current.name = location->getName();
- _current.coord = getLocationCoordinates(_current.name);
+ _current.coords = getLocationCoordinates(_current.name);
}
void WalkMgr::update() {
@@ -142,12 +147,12 @@ void WalkMgr::loadState(Archive &archive) {
_isWalking = archive.readByte();
_current.name = archive.readString();
if (!_current.name.empty()) {
- _current.coord = getLocationCoordinates(_current.name);
+ _current.coords = getLocationCoordinates(_current.name);
}
if (_isWalking) {
_next.name = archive.readString();
_destination = findLocation(archive.readString());
- _next.coord = getLocationCoordinates(_next.name);
+ _next.coords = getLocationCoordinates(_next.name);
}
}
diff --git a/engines/pink/objects/walk/walk_mgr.h b/engines/pink/objects/walk/walk_mgr.h
index dd08e61236..07b0bebcc0 100644
--- a/engines/pink/objects/walk/walk_mgr.h
+++ b/engines/pink/objects/walk/walk_mgr.h
@@ -23,6 +23,8 @@
#ifndef PINK_WALK_MGR_H
#define PINK_WALK_MGR_H
+#include "common/rect.h"
+
#include "pink/objects/object.h"
#include "pink/objects/walk/walk_shortest_path.h"
#include "pink/utils.h"
@@ -34,8 +36,7 @@ class LeadActor;
class WalkAction;
struct Coordinates {
- int x;
- int y;
+ Common::Point point;
int z;
};
@@ -58,10 +59,13 @@ public:
void skip();
+ const Coordinates &getStartCoords() { return _current.coords; }
+ const Coordinates &getEndCoords() { return _next.coords; }
+
private:
struct WayPoint {
Common::String name;
- Coordinates coord;
+ Coordinates coords;
};
Coordinates getLocationCoordinates(const Common::String &locationName);