From 638305fcbb9a1c53425b546a0deb2ea6c3208f5a Mon Sep 17 00:00:00 2001 From: Robert Špalek Date: Sat, 7 Nov 2009 01:54:47 +0000 Subject: The hero turns the right direction after walking svn-id: r45713 --- engines/draci/game.cpp | 3 ++- engines/draci/walking.cpp | 21 ++++++++++----------- engines/draci/walking.h | 7 +++++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp index ed5768fd42..baaca70508 100644 --- a/engines/draci/game.cpp +++ b/engines/draci/game.cpp @@ -983,7 +983,8 @@ void Game::setHeroPosition(const Common::Point &p) { void Game::positionHero(const Common::Point &p, SightDirection dir) { setHeroPosition(p); - playHeroAnimation(_walkingState.animationForSightDirection(dir)); + Common::Point mousePos(_vm->_mouse->getPosX(), _vm->_mouse->getPosY()); + playHeroAnimation(_walkingState.animationForSightDirection(dir, _hero, mousePos, WalkingPath())); } Common::Point Game::findNearestWalkable(int x, int y) const { diff --git a/engines/draci/walking.cpp b/engines/draci/walking.cpp index 9edffc6996..fc194bf9d8 100644 --- a/engines/draci/walking.cpp +++ b/engines/draci/walking.cpp @@ -435,7 +435,7 @@ void WalkingState::startWalking(const Common::Point &p1, const Common::Point &p2 _dir = dir; if (!_path.size()) { - return; + _path.push_back(p1); } if (_path.size() == 1 && p2 != p1) { // Although the first and last point belong to the same @@ -611,7 +611,7 @@ Movement WalkingState::animationForDirection(const Common::Point &here, const Co Movement WalkingState::directionForNextPhase() const { if (_segment >= (int) (_path.size() - 2)) { - return animationForSightDirection(_dir); + return animationForSightDirection(_dir, _path[_path.size()-1], _mouse, _path); } else { return animationForDirection(_path[_segment+1], _path[_segment+2]); } @@ -698,24 +698,23 @@ Movement WalkingState::transitionBetweenAnimations(Movement previous, Movement n } } -Movement WalkingState::animationForSightDirection(SightDirection dir) const { +Movement WalkingState::animationForSightDirection(SightDirection dir, const Common::Point &hero, const Common::Point &mouse, const WalkingPath &path) const { switch (dir) { + case kDirectionMouse: + return mouse.x < hero.x ? kStopLeft : kStopRight; case kDirectionLeft: return kStopLeft; case kDirectionRight: return kStopRight; default: { - const GameObject *dragon = _vm->_game->getObject(kDragonObject); - const int anim_index = _vm->_game->playingObjectAnimation(dragon); - if (anim_index >= 0) { - return static_cast (anim_index); - } else { - return kStopRight; // TODO + // Find the last horizontal direction on the path. + int i = path.size() - 1; + while (i >= 0 && path[i].x == hero.x) { + --i; } - break; + return (i >= 0 && path[i].x < hero.x) ? kStopRight : kStopLeft; } } - // TODO: implement all needed functionality } } diff --git a/engines/draci/walking.h b/engines/draci/walking.h index 180c3cf855..6c8d9b9b07 100644 --- a/engines/draci/walking.h +++ b/engines/draci/walking.h @@ -128,8 +128,11 @@ public: // scheduled animation. void heroAnimationFinished(); - // Returns the hero's animation corresponding to looking into given direction. - Movement animationForSightDirection(SightDirection dir) const; + // Returns the hero's animation corresponding to looking into given + // direction. The direction can be smart and in that case this + // function needs to know the whole last path, the current position of + // the hero, or the mouse position. + Movement animationForSightDirection(SightDirection dir, const Common::Point &hero, const Common::Point &mouse, const WalkingPath &path) const; private: DraciEngine *_vm; -- cgit v1.2.3