From c89fe5f6d56b6d6e11b7d642e85633bc86098ce8 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 6 Jul 2010 11:33:09 +0000 Subject: Added support for idle character animations svn-id: r50723 --- engines/m4/mads_player.cpp | 190 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 176 insertions(+), 14 deletions(-) (limited to 'engines/m4/mads_player.cpp') diff --git a/engines/m4/mads_player.cpp b/engines/m4/mads_player.cpp index 57cb9eefd3..bb7a1b406d 100644 --- a/engines/m4/mads_player.cpp +++ b/engines/m4/mads_player.cpp @@ -38,6 +38,9 @@ MadsPlayer::MadsPlayer() { _direction = 0; _direction2 = 0; _forceRefresh = true; + _stepEnabled = true; + _ticksAmount = 3; + _priorTimer = 0; _visible = true; _priorVisible = false; _visible3 = false; @@ -53,7 +56,7 @@ MadsPlayer::MadsPlayer() { _frameNum = 0; _frameOffset = 0; _unk1 = 0; - _newFrame = 0; + _frameCount = 0; _frameListIndex = 0; _actionIndex = 0; resetActionList(); @@ -154,7 +157,7 @@ void MadsPlayer::update() { if (equal) // Undo the prior expiry of the player sprite - slot.spriteType = SPRITE_ZERO; + s2.spriteType = SPRITE_ZERO; else slotIndex = -1; } @@ -175,13 +178,13 @@ void MadsPlayer::update() { } /** - * Idling animation for player + * Updates the animation frame for the player */ -void MadsPlayer::idle() { +void MadsPlayer::updateFrame() { SpriteAsset &spriteSet = _madsVm->scene()->_spriteSlots.getSprite(_spriteListIdx + _spriteListIdx2); assert(spriteSet._charInfo); - if (!spriteSet._charInfo->_hasIdling) { + if (!spriteSet._charInfo->_numEntries) { _frameNum = 1; } else { _frameListIndex = _actionList[_actionIndex]; @@ -204,7 +207,7 @@ void MadsPlayer::idle() { if (frameIndex == 0) setTicksAmount(); else - _madsVm->scene()->_ticksAmount = spriteSet._charInfo->_ticksList[frameIndex]; + _madsVm->_player._ticksAmount = spriteSet._charInfo->_ticksList[frameIndex]; } } @@ -223,19 +226,103 @@ void MadsPlayer::setupFrame() { _unk1 = MAX(spriteSet._charInfo->_unk1, 100); setTicksAmount(); - _newFrame = spriteSet._charInfo->_frameNumber; - if (_newFrame == 0) - _newFrame = spriteSet.getCount(); + _frameCount = spriteSet._charInfo->_totalFrames; + if (_frameCount == 0) + _frameCount = spriteSet.getCount(); _yScale = spriteSet._charInfo->_yScale; - if ((_frameNum <= 0) || (_frameNum > _newFrame)) + if ((_frameNum <= 0) || (_frameNum > _frameCount)) _frameNum = 1; _forceRefresh = true; } void MadsPlayer::step() { + if (_visible && _stepEnabled && !_moving && (_direction == _direction2) && (_madsVm->_currentTimer >= GET_GLOBAL32(2))) { + if (_actionIndex == 0) { + int randVal = _vm->_random->getRandomNumber(29999); + + if (GET_GLOBAL(0) == SEX_MALE) { + switch (_direction) { + case 1: + case 3: + case 7: + case 9: + if (randVal < 200) { + queueAction(-1, 0); + queueAction(1, 0); + } + break; + + case 2: + if (randVal < 500) { + for (int i = 0; i < 10; ++i) + queueAction((randVal < 250) ? 1 : 2, 0); + } else if (randVal < 750) { + for (int i = 0; i < 5; ++i) + queueAction(1, 0); + queueAction(0, 0); + for (int i = 0; i < 5; ++i) + queueAction(2, 0); + } + break; + + case 4: + case 6: + if (randVal < 500) { + for (int i = 0; i < 10; ++i) + queueAction(1, 0); + } + break; + + case 5: + case 8: + if (randVal < 200) { + queueAction(-1, 0); + queueAction(1, 0); + } + break; + } + } + } + + SET_GLOBAL32(2, GET_GLOBAL32(2) + 6); + } + + if (GET_GLOBAL(138) == 1) { + uint32 diff = _madsVm->_currentTimer - GET_GLOBAL32(142); + if (diff > 60) { + SET_GLOBAL32(144, GET_GLOBAL32(144) + 1); + } else { + SET_GLOBAL32(144, GET_GLOBAL32(144) + diff); + } + + SET_GLOBAL32(142, _madsVm->_currentTimer); + } +} + +void MadsPlayer::nextFrame() { + if (_madsVm->_currentTimer >= (_priorTimer + _ticksAmount)) { + _priorTimer = _madsVm->_currentTimer; + + if (_moving) + move(); + else + idle(); + + // Post update logic + if (_moving) { + ++_frameNum; + if (_frameNum > _frameCount) + _frameNum = 1; + _forceRefresh = true; + } else if (!_forceRefresh) { + idle(); + } + // Final update + update(); + } } int MadsPlayer::getScale(int yp) { @@ -262,9 +349,9 @@ int MadsPlayer::getSpriteSlot() { void MadsPlayer::setTicksAmount() { SpriteAsset &spriteSet = _madsVm->scene()->_spriteSlots.getSprite(_spriteListIdx + _spriteListIdx2); assert(spriteSet._charInfo); - _madsVm->scene()->_ticksAmount = spriteSet._charInfo->_ticksAmount; - if (_madsVm->scene()->_ticksAmount == 0) - _madsVm->scene()->_ticksAmount = 6; + _madsVm->_player._ticksAmount = spriteSet._charInfo->_ticksAmount; + if (_madsVm->_player._ticksAmount == 0) + _madsVm->_player._ticksAmount = 6; } void MadsPlayer::resetActionList() { @@ -279,7 +366,7 @@ int MadsPlayer::queueAction(int action1, int action2) { SpriteAsset &spriteSet = _madsVm->scene()->_spriteSlots.getSprite(_spriteListIdx + _spriteListIdx2); assert(spriteSet._charInfo); - if ((spriteSet._charInfo->_hasIdling) && (_actionIndex < 11)) { + if ((action1 < spriteSet._charInfo->_numEntries) && (_actionIndex < 11)) { ++_actionIndex; _actionList[_actionIndex] = action1; _actionList2[_actionIndex] = action2; @@ -289,4 +376,79 @@ int MadsPlayer::queueAction(int action1, int action2) { return true; } +void MadsPlayer::idle() { + if (_direction != _direction2) { + // The direction has changed, so reset for new direction + dirChanged(); + return; + } + + SpriteAsset &spriteSet = _madsVm->scene()->_spriteSlots.getSprite(_spriteListIdx + _spriteListIdx2); + assert(spriteSet._charInfo); + if (spriteSet._charInfo->_numEntries == 0) + // No entries, so exit immediately + return; + + int frameIndex = ABS(_frameListIndex); + int direction = (_frameListIndex < 0) ? -1 : 1; + + if (frameIndex >= spriteSet._charInfo->_numEntries) + // Reset back to the start of the list + _frameListIndex = 0; + else { + _frameNum += direction; + _forceRefresh = true; + + if (spriteSet._charInfo->_frameList2[frameIndex] < _frameNum) { + _unk3 = _unk2; + updateFrame(); + } + if (spriteSet._charInfo->_frameList[frameIndex] < _frameNum) { + _unk3 = _unk2; + updateFrame(); + } + } +} + +void MadsPlayer::move() { + // TODO: Handle player movement +} + +void MadsPlayer::dirChanged() { + int dirIndex = 0, dirIndex2 = 0; + int newDir = 0, newDir2 = 0; + + if (_direction != _direction2) { + // Find the index for the given direction in the player direction list + int tempDir = _direction; + do { + ++dirIndex; + newDir += tempDir; + tempDir = _directionListIndexes[tempDir + 10]; + } while (tempDir != _direction2); + } + + + if (_direction != _direction2) { + // Find the index for the given direction in the player direction list + int tempDir = _direction; + do { + ++dirIndex2; + newDir2 += tempDir; + tempDir = _directionListIndexes[tempDir + 10]; + } while (tempDir != _direction2); + } + + int diff = dirIndex - dirIndex2; + if (diff == 0) + diff = newDir - newDir2; + + _direction = (diff >= 0) ? _directionListIndexes[_direction] : _directionListIndexes[_direction + 10]; + setupFrame(); + if ((_direction == _direction2) && !_moving) + updateFrame(); + + _priorTimer += 1; +} + } // End of namespace M4 -- cgit v1.2.3