diff options
author | Robert Špalek | 2009-09-29 05:54:59 +0000 |
---|---|---|
committer | Robert Špalek | 2009-09-29 05:54:59 +0000 |
commit | 00a733f7cf33942a0618d99a4f9d0c0aefad1fef (patch) | |
tree | 3ac3aadb9a9e8391381a9dc5629f3d145b21e143 /engines | |
parent | 635769bd5d38847349700f13ffaf56f689582fae (diff) | |
download | scummvm-rg350-00a733f7cf33942a0618d99a4f9d0c0aefad1fef.tar.gz scummvm-rg350-00a733f7cf33942a0618d99a4f9d0c0aefad1fef.tar.bz2 scummvm-rg350-00a733f7cf33942a0618d99a4f9d0c0aefad1fef.zip |
Clean up and unify positioning dragon's animations
svn-id: r44456
Diffstat (limited to 'engines')
-rw-r--r-- | engines/draci/game.cpp | 79 | ||||
-rw-r--r-- | engines/draci/game.h | 2 |
2 files changed, 23 insertions, 58 deletions
diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp index d331347aa2..1bfc6052fb 100644 --- a/engines/draci/game.cpp +++ b/engines/draci/game.cpp @@ -985,10 +985,7 @@ void Game::walkHero(int x, int y) { Surface *surface = _vm->_screen->getSurface(); - Common::Point p = _currentRoom._walkingMap.findNearestWalkable(x, y, surface->getRect()); - - _heroX = p.x; - _heroY = p.y; + _hero = _currentRoom._walkingMap.findNearestWalkable(x, y, surface->getRect()); GameObject *dragon = getObject(kDragonObject); @@ -996,47 +993,14 @@ void Game::walkHero(int x, int y) { _vm->_anims->stop(dragon->_anims[i]); } - debugC(3, kDraciLogicDebugLevel, "Walk to x: %d y: %d", _heroX, _heroY); + debugC(3, kDraciLogicDebugLevel, "Walk to x: %d y: %d", _hero.x, _hero.y); // Fetch dragon's animation ID // FIXME: Need to add proper walking (this only warps the dragon to position) int animID = dragon->_anims[0]; Animation *anim = _vm->_anims->getAnimation(animID); - - // Calculate scaling factors - const double scale = _vm->_game->getPers0() + _vm->_game->getPersStep() * _heroY; - - // Set the Z coordinate for the dragon's animation - anim->setZ(y+1); - - // Fetch current frame - Drawable *frame = anim->getFrame(); - - // Fetch base dimensions of the frame - uint height = frame->getHeight(); - uint width = frame->getWidth(); - - // We naturally want the dragon to position its feet to the location of the - // click but sprites are drawn from their top-left corner so we subtract - // the current height of the dragon's sprite - _heroY -= (int)(scale * height); - _heroX -= (int)(scale * width) / 2; - - // TODO: Check if underflow is handled well everywhere and remove this once sure - - if (_heroX < 0) - _heroX = 0; - - // Since _persons[] is used for placing talking text, we use the non-adjusted x value - // so the text remains centered over the dragon. - _persons[kDragonObject]._x = p.x; - _persons[kDragonObject]._y = _heroY; - - // Set the per-animation scaling factor - anim->setScaleFactors(scale, scale); - - anim->setRelative(_heroX, _heroY); + positionAnimAsHero(anim); // Play the animation _vm->_anims->play(animID); @@ -1396,16 +1360,11 @@ void Game::runGateProgram(int gate) { void Game::positionAnimAsHero(Animation *anim) { - // Fetch dragon's coordinates - int x = _heroX; - int y = _heroY; - // Calculate scaling factors - const double scaleX = getPers0() + getPersStep() * y; - const double scaleY = scaleX; + const double scale = getPers0() + getPersStep() * _hero.y; // Set the Z coordinate for the dragon's animation - anim->setZ(y+1); + anim->setZ(_hero.y + 1); // Fetch current frame Drawable *frame = anim->getFrame(); @@ -1414,27 +1373,33 @@ void Game::positionAnimAsHero(Animation *anim) { uint height = frame->getHeight(); uint width = frame->getWidth(); - // Set the per-animation scaling factor - anim->setScaleFactors(scaleX, scaleY); - - _persons[kDragonObject]._x = x + (lround(scaleX) * width) / 2; - _persons[kDragonObject]._y = y - lround(scaleY) * height; - // We naturally want the dragon to position its feet to the location of the // click but sprites are drawn from their top-left corner so we subtract // the current height of the dragon's sprite - y -= (int)(scaleY * height); - x -= (int)(scaleX * width) / 2; + Common::Point p = _hero; + p.x -= (int)(scale * width) / 2; + p.y -= (int)(scale * height); + // TODO: fix drawScaled() and remove this + if (p.x < 0) + p.x = 0; - anim->setRelative(x, y); + // Since _persons[] is used for placing talking text, we use the non-adjusted x value + // so the text remains centered over the dragon. + _persons[kDragonObject]._x = _hero.x; + _persons[kDragonObject]._y = p.y; + + // Set the per-animation scaling factor + anim->setScaleFactors(scale, scale); + + anim->setRelative(p.x, p.y); } int Game::getHeroX() const { - return _heroX; + return _hero.x; } int Game::getHeroY() const { - return _heroY; + return _hero.y; } double Game::getPers0() const { diff --git a/engines/draci/game.h b/engines/draci/game.h index 021f0c1416..bcc2323272 100644 --- a/engines/draci/game.h +++ b/engines/draci/game.h @@ -352,7 +352,7 @@ private: GameInfo _info; - int _heroX, _heroY; + Common::Point _hero; int *_variables; Person *_persons; |