From 8bbf257525c9b96a4a69cddd668907a0b2657b0d Mon Sep 17 00:00:00 2001 From: Florian Kagerer Date: Sat, 10 May 2008 14:12:48 +0000 Subject: implement item animations for MR svn-id: r31973 --- engines/kyra/animator_mr.cpp | 55 ++++++++++++++++++++++++++++++++++++ engines/kyra/kyra_hof.h | 18 ------------ engines/kyra/kyra_mr.cpp | 8 ++++-- engines/kyra/kyra_mr.h | 15 ++++++++++ engines/kyra/kyra_v2.h | 17 +++++++++++ engines/kyra/staticres.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 160 insertions(+), 20 deletions(-) (limited to 'engines') diff --git a/engines/kyra/animator_mr.cpp b/engines/kyra/animator_mr.cpp index ab3d347549..feea7c905b 100644 --- a/engines/kyra/animator_mr.cpp +++ b/engines/kyra/animator_mr.cpp @@ -196,6 +196,61 @@ void KyraEngine_MR::refreshAnimObjects(int force) { } } +void KyraEngine_MR::updateItemAnimations() { + bool nextFrame = false; + + if (_itemAnimData[0].itemIndex == -1) + return; + + const ItemAnimData_v2 *s = &_itemAnimData[_nextAnimItem]; + ActiveItemAnim *a = &_activeItemAnim[_nextAnimItem]; + + if (++_nextAnimItem == 10) { + _nextAnimItem = 0; + return; + } + + uint32 ctime = _system->getMillis(); + if (ctime < a->nextFrame) + return; + + uint16 shpIdx = s->frames[a->currentFrame].index + 248; + if ((s->itemIndex == _handItemSet || s->itemIndex == _itemInHand) && (!_mouseState && _screen->isMouseVisible())) { + nextFrame = true; + _screen->setMouseCursor(12, 19, getShapePtr(shpIdx)); + } + + if (_inventoryState) { + for (int i = 0; i < 10; i++) { + if (s->itemIndex == _mainCharacter.inventory[i]) { + nextFrame = true; + _screen->drawShape(2, getShapePtr(422 + i), 9, 0, 0, 0); + _screen->drawShape(2, getShapePtr(shpIdx), 9, 0, 0, 0); + _screen->hideMouse(); + _screen->copyRegion(9, 0, _inventoryX[i], _inventoryY[i], 24, 20, 2, 0, Screen::CR_NO_P_CHECK); + _screen->showMouse(); + } + } + } + + _screen->updateScreen(); + + for (int i = 17; i < 66; i++) { + AnimObj *animObject = &_animObjects[i]; + if (animObject->shapeIndex2 == s->itemIndex + 248) { + animObject->shapePtr = getShapePtr(shpIdx); + animObject->shapeIndex1 = shpIdx; + animObject->needRefresh = 1; + nextFrame = true; + } + } + + if (nextFrame) { + a->nextFrame = _system->getMillis() + (s->frames[a->currentFrame].delay * _tickLength); + a->currentFrame = ++a->currentFrame % s->numFrames; + } +} + void KyraEngine_MR::updateCharacterAnim(int charId) { debugC(9, kDebugLevelAnimator, "KyraEngine_MR::updateCharacterAnim(%d)", charId); diff --git a/engines/kyra/kyra_hof.h b/engines/kyra/kyra_hof.h index 3a745fe502..f537bf57d3 100644 --- a/engines/kyra/kyra_hof.h +++ b/engines/kyra/kyra_hof.h @@ -105,11 +105,6 @@ struct TIM; typedef int (KyraEngine_HoF::*SeqProc)(WSAMovieV2*, int, int, int); -struct FrameControl { - uint16 index; - uint16 delay; -}; - struct ActiveWSA { int16 flags; WSAMovieV2 *movie; @@ -179,17 +174,6 @@ struct ItemAnimData_v1 { const uint16 *frames; }; -struct ItemAnimData_v2 { - int16 itemIndex; - uint8 numFrames; - const FrameControl *frames; -}; - -struct ActiveItemAnim { - uint16 currentFrame; - uint32 nextFrame; -}; - class KyraEngine_HoF : public KyraEngine_v2 { friend class Debugger_HoF; friend class TextDisplayer_HoF; @@ -327,8 +311,6 @@ protected: void dinoRide(); - int _mouseState; - void handleInput(int x, int y); bool handleInputUnkSub(int x, int y); diff --git a/engines/kyra/kyra_mr.cpp b/engines/kyra/kyra_mr.cpp index 1ed347953d..d2987d314f 100644 --- a/engines/kyra/kyra_mr.cpp +++ b/engines/kyra/kyra_mr.cpp @@ -79,6 +79,8 @@ KyraEngine_MR::KyraEngine_MR(OSystem *system, const GameFlags &flags) : KyraEngi _mainCharacter.facing = 5; _mainCharacter.animFrame = 0x57; _mainCharacter.walkspeed = 5; + memset(_activeItemAnim, 0, sizeof(_activeItemAnim)); + _nextAnimItem = 0; _text = 0; _commandLineY = 189; _inventoryState = false; @@ -1125,7 +1127,7 @@ void KyraEngine_MR::update() { updateMouse(); updateSpecialSceneScripts(); updateCommandLine(); - //XXX + updateItemAnimations(); musicUpdate(0); _screen->updateScreen(); @@ -1137,7 +1139,7 @@ void KyraEngine_MR::updateWithText() { musicUpdate(0); updateMouse(); - //XXX + updateItemAnimations(); updateSpecialSceneScripts(); updateCommandLine(); musicUpdate(0); @@ -1265,9 +1267,11 @@ void KyraEngine_MR::updateMouse() { } if (type != 0 && type != _handItemSet && !hasItemCollision) { + _mouseState = _handItemSet = type; _handItemSet = type; _screen->setMouseCursor(offsetX, offsetY, _gameShapes[shape]); } else if (type == 0 && _handItemSet != _itemInHand && mouse.x > 8 && mouse.x < 311 && mouse.y < 171 && mouse.y > 8) { + _mouseState = 0; setItemMouseCursor(); } else if (mouse.y > 187 && _handItemSet > -4 && type == 0 && !_inventoryState) { showInventory(); diff --git a/engines/kyra/kyra_mr.h b/engines/kyra/kyra_mr.h index 588154ca3b..6faadf8197 100644 --- a/engines/kyra/kyra_mr.h +++ b/engines/kyra/kyra_mr.h @@ -194,6 +194,7 @@ private: void refreshAnimObjects(int force); bool _loadingState; + void updateItemAnimations(); void updateCharacterAnim(int charId); void updateSceneAnim(int anim, int newFrame); @@ -209,6 +210,20 @@ private: bool _nextIdleType; void showIdleAnim(); + static const FrameControl _itemAnimFrames0[]; + static const FrameControl _itemAnimFrames1[]; + static const FrameControl _itemAnimFrames2[]; + static const FrameControl _itemAnimFrames3[]; + static const FrameControl _itemAnimFrames4[]; + static const FrameControl _itemAnimFrames5[]; + static const FrameControl _itemAnimFrames6[]; + static const FrameControl _itemAnimFrames7[]; + static const FrameControl _itemAnimFrames8[]; + static const FrameControl _itemAnimFrames9[]; + static const ItemAnimData_v2 _itemAnimData[10]; + ActiveItemAnim _activeItemAnim[10]; + int _nextAnimItem; + // interface uint8 *_interface; uint8 *_interfaceCommandLine; diff --git a/engines/kyra/kyra_v2.h b/engines/kyra/kyra_v2.h index 639594e593..e64e51ae37 100644 --- a/engines/kyra/kyra_v2.h +++ b/engines/kyra/kyra_v2.h @@ -35,6 +35,22 @@ namespace Kyra { +struct FrameControl { + uint16 index; + uint16 delay; +}; + +struct ItemAnimData_v2 { + int16 itemIndex; + uint8 numFrames; + const FrameControl *frames; +}; + +struct ActiveItemAnim { + uint16 currentFrame; + uint32 nextFrame; +}; + class Screen_v2; class KyraEngine_v2 : public KyraEngine { @@ -85,6 +101,7 @@ protected: void removeInputTop(); int _mouseX, _mouseY; + int _mouseState; struct Event { Common::Event event; diff --git a/engines/kyra/staticres.cpp b/engines/kyra/staticres.cpp index 8ace7288f2..051d4d9025 100644 --- a/engines/kyra/staticres.cpp +++ b/engines/kyra/staticres.cpp @@ -28,6 +28,7 @@ #include "common/md5.h" #include "kyra/kyra.h" #include "kyra/kyra_v1.h" +#include "kyra/kyra_v2.h" #include "kyra/kyra_hof.h" #include "kyra/kyra_mr.h" #include "kyra/screen.h" @@ -2028,6 +2029,72 @@ const KyraEngine_MR::ShapeDesc KyraEngine_MR::_shapeDescs[] = { const int KyraEngine_MR::_shapeDescsSize = ARRAYSIZE(KyraEngine_MR::_shapeDescs); +const FrameControl KyraEngine_MR::_itemAnimFrames0[] = { + { 0x03, 0x19 }, { 0x48, 0x1E }, { 0x49, 0x1E } +}; + +const FrameControl KyraEngine_MR::_itemAnimFrames1[] = { + { 0x3A, 0x0B }, { 0x4B, 0x0B }, { 0x4C, 0x0B }, { 0x4D, 0x0B }, + { 0x4E, 0x0B }, { 0x4F, 0x0B }, { 0x50, 0x0B } +}; + +const FrameControl KyraEngine_MR::_itemAnimFrames2[] = { + { 0x14, 0x0F }, { 0x51, 0x0F }, { 0x52, 0x0F }, { 0x53, 0x0F } +}; + +const FrameControl KyraEngine_MR::_itemAnimFrames3[] = { + { 0x13, 0x14 }, { 0x54, 0x14 }, { 0x55, 0x14 }, { 0x56, 0x14 } +}; + +const FrameControl KyraEngine_MR::_itemAnimFrames4[] = { + { 0x15, 0x10 }, { 0x57, 0x12 }, { 0x58, 0x10 }, { 0x59, 0x11 }, + { 0x5A, 0x10 }, { 0x5B, 0x11 }, { 0x5C, 0x10 } +}; + +const FrameControl KyraEngine_MR::_itemAnimFrames5[] = { + { 0x09, 0x1E }, { 0x5D, 0x1E }, { 0x5E, 0x1E }, { 0x5D, 0x1E } +}; + +const FrameControl KyraEngine_MR::_itemAnimFrames6[] = { + { 0x39, 0x21 }, { 0x5F, 0x20 }, { 0x60, 0x1E }, { 0x61, 0x20 }, + { 0x62, 0x21 }, { 0x63, 0x1E }, { 0x64, 0x22 } +}; + +const FrameControl KyraEngine_MR::_itemAnimFrames7[] = { + { 0x40, 0x0C }, { 0x6C, 0x10 }, { 0x6B, 0x10 }, { 0x6A, 0x0F }, + { 0x69, 0x0F }, { 0x68, 0x0F }, { 0x67, 0x0F }, { 0x66, 0x0F }, + { 0x65, 0x0F }, { 0x66, 0x11 }, { 0x67, 0x12 }, { 0x68, 0x10 }, + { 0x69, 0x0F }, { 0x6A, 0x10 }, { 0x6B, 0x0F }, { 0x6C, 0x10 }, + { 0x6B, 0x0F }, { 0x6A, 0x10 }, { 0x6B, 0x0F }, { 0x6C, 0x10 }, + { 0x6B, 0x0F }, { 0x6A, 0x10 }, { 0x69, 0x0F }, { 0x68, 0x10 }, + { 0x67, 0x12 }, { 0x66, 0x11 }, { 0x65, 0xC8 }, { 0x66, 0x11 }, + { 0x67, 0x12 }, { 0x68, 0x10 }, { 0x69, 0x0F }, { 0x6A, 0x10 }, + { 0x6B, 0x0F }, { 0x6C, 0x10 } +}; + +const FrameControl KyraEngine_MR::_itemAnimFrames8[] = { + { 0x2B, 0x19 }, { 0x8E, 0x16 }, { 0x8F, 0x14 }, + { 0x90, 0x16 }, { 0x91, 0x50 } +}; + +const FrameControl KyraEngine_MR::_itemAnimFrames9[] = { + { 0x3B, 0x258}, { 0x92, 0x0A }, { 0x93, 0x0A }, { 0x94, 0x0A }, + { 0x93, 0x0A }, { 0x92, 0x0A } +}; + +const ItemAnimData_v2 KyraEngine_MR::_itemAnimData[10] = { + { 0x03, 0x03, _itemAnimFrames0 }, + { 0x3a, 0x07, _itemAnimFrames1 }, + { 0x14, 0x04, _itemAnimFrames2 }, + { 0x13, 0x04, _itemAnimFrames3 }, + { 0x15, 0x07, _itemAnimFrames4 }, + { 0x09, 0x04, _itemAnimFrames5 }, + { 0x39, 0x07, _itemAnimFrames6 }, + { 0x40, 0x22, _itemAnimFrames7 }, + { 0x2B, 0x05, _itemAnimFrames8 }, + { 0x3B, 0x06, _itemAnimFrames9 } +}; + const uint8 KyraEngine_MR::_characterFrameTable[] = { 0x36, 0x35, 0x35, 0x33, 0x32, 0x32, 0x34, 0x34 }; -- cgit v1.2.3