diff options
author | lukaslw | 2014-04-04 16:16:15 +0200 |
---|---|---|
committer | lukaslw | 2014-06-22 19:24:29 +0200 |
commit | 07a4f82c6336333be6d3d2930830be17184fbb99 (patch) | |
tree | ae62684a60b6b6d84f779068e53e546368d6b75e /engines/prince | |
parent | ebf362571807ca514c521c8fbeac340edead7a1b (diff) | |
download | scummvm-rg350-07a4f82c6336333be6d3d2930830be17184fbb99.tar.gz scummvm-rg350-07a4f82c6336333be6d3d2930830be17184fbb99.tar.bz2 scummvm-rg350-07a4f82c6336333be6d3d2930830be17184fbb99.zip |
PRINCE: Hero animation - beginning of showHero()
Diffstat (limited to 'engines/prince')
-rw-r--r-- | engines/prince/animation.cpp | 34 | ||||
-rw-r--r-- | engines/prince/animation.h | 4 | ||||
-rw-r--r-- | engines/prince/graphics.cpp | 5 | ||||
-rw-r--r-- | engines/prince/hero.cpp | 271 | ||||
-rw-r--r-- | engines/prince/hero.h | 42 | ||||
-rw-r--r-- | engines/prince/prince.cpp | 56 | ||||
-rw-r--r-- | engines/prince/prince.h | 2 | ||||
-rw-r--r-- | engines/prince/script.cpp | 6 |
8 files changed, 396 insertions, 24 deletions
diff --git a/engines/prince/animation.cpp b/engines/prince/animation.cpp index f595e7af68..8edf9d04ee 100644 --- a/engines/prince/animation.cpp +++ b/engines/prince/animation.cpp @@ -29,10 +29,10 @@ namespace Prince { bool Animation::loadFromStream(Common::SeekableReadStream &stream) { - uint32 dataSize = stream.size(); - _data = (byte*) malloc(dataSize); + _dataSize = stream.size(); + _data = (byte*) malloc(_dataSize); - if(stream.read(_data, dataSize) != dataSize) { + if (stream.read(_data, _dataSize) != _dataSize) { free(_data); return false; } @@ -49,7 +49,7 @@ const Graphics::Surface * Animation::getSurface(uint16 frameIndex) { return _frameList[frameIndex]; } */ -Animation::Animation() { +Animation::Animation(): _data(NULL) { } @@ -61,6 +61,22 @@ Animation::~Animation() { free(_data); } +void Animation::clear() { + if (_data != NULL) { + free(_data); + } +} + +// TEMP +/* +int8 Animation::getZoom(uint16 offset) const { + return *(uint8*)(_data+offset); +} +*/ +int16 Animation::getZoom(uint16 offset) const { + return READ_LE_UINT16(_data + offset); +} + int16 Animation::getLoopCount() const { return READ_LE_UINT16(_data + 2); } @@ -93,6 +109,16 @@ int16 Animation::getPhaseFrameIndex(uint phaseIndex) const { return READ_LE_UINT16(getPhaseEntry(phaseIndex) + 4); } +int16 Animation::getFrameWidth(uint frameIndex) const { + byte *frameData = _data + READ_LE_UINT32(_data + 16 + frameIndex * 4); + return READ_LE_UINT16(frameData + 0); +} + +int16 Animation::getFrameHeight(uint frameIndex) const { + byte *frameData = _data + READ_LE_UINT32(_data + 16 + frameIndex * 4); + return READ_LE_UINT16(frameData + 2); +} + Graphics::Surface *Animation::getFrame(uint frameIndex) { byte *frameData = _data + READ_LE_UINT32(_data + 16 + frameIndex * 4); int16 width = READ_LE_UINT16(frameData + 0); diff --git a/engines/prince/animation.h b/engines/prince/animation.h index 9eb7a703e2..710f8730cc 100644 --- a/engines/prince/animation.h +++ b/engines/prince/animation.h @@ -47,6 +47,10 @@ public: int16 getPhaseOffsetY(uint phaseIndex) const; int16 getPhaseFrameIndex(uint phaseIndex) const; Graphics::Surface *getFrame(uint frameIndex); + int16 getFrameWidth(uint frameIndex) const; + int16 getFrameHeight(uint frameIndex) const; + int16 getZoom(uint16 offset) const; + void clear(); private: Common::Array<Graphics::Surface *> _frameList; diff --git a/engines/prince/graphics.cpp b/engines/prince/graphics.cpp index 97e2686f54..3f9517a6e9 100644 --- a/engines/prince/graphics.cpp +++ b/engines/prince/graphics.cpp @@ -72,9 +72,10 @@ void GraphicsMan::drawTransparent(uint16 posX, uint16 posY, const Graphics::Surf { for (uint y = 0; y < s->h; ++y) { for (uint x = 0; x < s->w; ++x) { - byte pixel = *((byte*)s->getBasePtr(x,y)); + byte pixel = *((byte*)s->getBasePtr(x, y)); if (pixel != 255) { - *((byte*)_frontScreen->getBasePtr(x, y)) = pixel; + //*((byte*)_frontScreen->getBasePtr(x, y)) = pixel; + *((byte*)_frontScreen->getBasePtr(x + posX, y + posY)) = pixel; } } } diff --git a/engines/prince/hero.cpp b/engines/prince/hero.cpp index 3e3c5d6929..81e686c740 100644 --- a/engines/prince/hero.cpp +++ b/engines/prince/hero.cpp @@ -20,6 +20,7 @@ * */ #include "common/debug.h" +#include "common/random.h" #include "prince/hero.h" #include "prince/hero_set.h" @@ -29,11 +30,17 @@ namespace Prince { -static const uint32 kMoveSetSize = 26; +Hero::Hero() : _number(0), _visible(false), _state(MOVE), _middleX(0), _middleY(0) + , _boreNum(1), _currHeight(0), _moveDelay(0), _shadMinus(1), _moveSetType(0) + , _lastDirection(DOWN), _destDirection(DOWN), _talkTime(0), _boredomTime(0), _phase(0) + , _specAnim(0), _drawX(0), _drawY(0), _randomSource("prince"), _zoomFactor(0), _scaleValue(0) +{ + _zoomBitmap = new Animation(); +} -Hero::Hero() : _number(0), _visible(false), _state(STAY), _middleX(0), _middleY(0) - , _boreNum(0), _currHeight(0), _moveDelay(0), _shadMinus(1), _moveSetType(0), _frame(0) { -} +Hero::~Hero() { + delete _zoomBitmap; +} bool Hero::loadAnimSet(uint32 animSetNr) { if (animSetNr > sizeof(heroSetTable)) { @@ -57,18 +64,270 @@ bool Hero::loadAnimSet(uint32 animSetNr) { _moveSet[i] = anim; } - return true; } const Graphics::Surface * Hero::getSurface() { if (_moveSet[_moveSetType]) { - int16 phaseFrameIndex = _moveSet[_moveSetType]->getPhaseFrameIndex(_frame); + //debug("BaseX: %d", _moveSet[_moveSetType]->getBaseX()); + //debug("BaseY: %d", _moveSet[_moveSetType]->getBaseY()); + //debug("FrameCount: %d", _moveSet[_moveSetType]->getFrameCount()); + //debug("LoopCount: %d", _moveSet[_moveSetType]->getLoopCount()); + //debug("PhaseCount: %d", _moveSet[_moveSetType]->getPhaseCount()); + //debug("PhaseFrameIndex(%d): %d", _frame, _moveSet[_moveSetType]->getPhaseFrameIndex(_frame)); + //debug("PhaseOffsetX(%d): %d", _frame, _moveSet[_moveSetType]->getPhaseOffsetX(_frame)); + //debug("PhaseOffsetY(%d) %d", _frame, _moveSet[_moveSetType]->getPhaseOffsetY(_frame)); + //debug("FrameSizeX(%d) %d", _frame, _moveSet[_moveSetType]->getFrameWidth(_frame)); + //debug("FrameSizeY(%d) %d", _frame, _moveSet[_moveSetType]->getFrameHeight(_frame)); + //getState(); + int16 phaseFrameIndex = _moveSet[_moveSetType]->getPhaseFrameIndex(_phase); return _moveSet[_moveSetType]->getFrame(phaseFrameIndex); } return NULL; } +//TEMP +void Hero::getState() { + switch (_state) { + case STAY: + debug("STAY"); + break; + case TURN: + debug("TURN"); + break; + case MOVE: + debug("MOVE"); + break; + case BORE: + debug("BORE"); + break; + case SPEC: + debug("SPEC"); + break; + case TALK: + debug("TALK"); + break; + case MVAN: + debug("MVAN"); + break; + case TRAN: + debug("TRAN"); + break; + case RUN: + debug("RUN"); + break; + case DMOVE: + debug("DMOVE"); + break; + } +} + +//TODO +void Hero::countDrawPosition() { + int16 frameXSize = _moveSet[_moveSetType]->getFrameWidth(_phase); + int16 frameYSize = _moveSet[_moveSetType]->getFrameHeight(_phase); + _drawX = _middleX - frameXSize/2; + _drawY = _middleY - frameYSize; +} + +void Hero::showHeroAnimFrame() { + if (_phase < _moveSet[_moveSetType]->getFrameCount() - 1) { + _phase++; + } else { + _phase = 0; + } + countDrawPosition(); + //debug("_drawX: %d", _drawX); + //debug("_drawY: %d", _drawY); + //debug("_middleX: %d", _middleX); + //debug("_middleY: %d", _middleY); +} + +void Hero::setScale(int8 zoomBitmapValue) { + if (zoomBitmapValue == 0) { + _zoomFactor = 1; + } else { + _zoomFactor = zoomBitmapValue; + } + _scaleValue = 10000 / _zoomFactor; + debug("_scaleValue: %d", _scaleValue); +} + +void Hero::selectZoom() { + int8 zoomBitmapValue = _zoomBitmap->getZoom(_middleY / 4 * kZoomBitmapWidth + _middleX / 4); + debug("offset: %d", _middleY / 4 * kZoomBitmapWidth + _middleX / 4); + debug("zoomBitmapValue: %d", _zoomFactor); + setScale(zoomBitmapValue); +} + +void Hero::specialAnim() { +} + +void Hero::rotateHero() { + switch (_lastDirection) { + case LEFT: + switch (_destDirection) { + case RIGHT: + _moveSetType = Move_MLR; + break; + case UP: + _moveSetType = Move_MLU; + break; + case DOWN: + _moveSetType = Move_MLD; + break; + } + break; + case RIGHT: + switch (_destDirection) { + case LEFT: + _moveSetType = Move_MRL; + break; + case UP: + _moveSetType = Move_MRU; + break; + case DOWN: + _moveSetType = Move_MRD; + break; + } + break; + case UP: + switch (_destDirection) { + case LEFT: + _moveSetType = Move_MUL; + break; + case RIGHT: + _moveSetType = Move_MUR; + break; + case DOWN: + _moveSetType = Move_MUD; + break; + } + break; + case DOWN: + switch (_destDirection) { + case LEFT: + _moveSetType = Move_MDL; + break; + case RIGHT: + _moveSetType = Move_MDR; + break; + case UP: + _moveSetType = Move_MDU; + break; + } + break; + } +} + +void Hero::showHero() { + if (_visible) { + // Is he talking? + if (_talkTime == 0) { //? + // Scale of hero + selectZoom(); + switch (_state) { + case STAY: + //if(OptionsFlag == false) { + //if(OpcodePC == null) { + _boredomTime++; + if (_boredomTime == 200) { // 140 for second hero + _boredomTime = 0; + _state = BORE; + } + switch (_lastDirection) { + case LEFT: + _moveSetType = Move_SL; + break; + case RIGHT: + _moveSetType = Move_SR; + break; + case UP: + _moveSetType = Move_SU; + break; + case DOWN: + _moveSetType = Move_SD; + break; + } + break; + case TURN: + /* + if(_lastDirection == _destDirection) { + _state = STAY; + } else { + _frame = 0; + rotateHero(); + _lastDirection = _destDirection; + } + */ + break; + case MOVE: + switch (_lastDirection) { + case LEFT: + _moveSetType = Move_ML; + break; + case RIGHT: + _moveSetType = Move_MR; + break; + case UP: + _moveSetType = Move_MU; + break; + case DOWN: + _moveSetType = Move_MD; + break; + } + break; + case BORE: + //if (_direction == UP) { + switch (_boreNum) { + case 0: + _moveSetType = Move_BORED1; + break; + case 1: + _moveSetType = Move_BORED2; + break; + } + if (_phase == _moveSet[_moveSetType]->getFrameCount() - 1) { + _boreNum = _randomSource.getRandomNumber(1); // rand one of two 'bored' animation + _lastDirection = DOWN; + _state = STAY; + } + break; + case SPEC: + //specialAnim(); + break; + case TALK: + switch (_lastDirection) { + case LEFT: + _moveSetType = Move_TL; + break; + case RIGHT: + _moveSetType = Move_TR; + break; + case UP: + _moveSetType = Move_TU; + break; + case DOWN: + _moveSetType = Move_TD; + break; + } + break; + case TRAN: + break; + case RUN: + break; + case DMOVE: + break; + } + } else { + _talkTime--; // o ile? + } + showHeroAnimFrame(); + } else { + // no hero visible + return; + } +} } /* vim: set tabstop=4 noexpandtab: */ diff --git a/engines/prince/hero.h b/engines/prince/hero.h index 45c0d700e3..e01a5c071f 100644 --- a/engines/prince/hero.h +++ b/engines/prince/hero.h @@ -34,6 +34,11 @@ class Animation; class Hero { public: + static const uint32 kMoveSetSize = 26; + static const int16 kZoomStep = 4; + static const int16 kMaxPicWidth = 1280; + static const int16 kZoomBitmapWidth = kMaxPicWidth / kZoomStep; + enum State { STAY = 0, TURN = 1, @@ -84,22 +89,38 @@ public: }; Hero(); - + ~Hero(); + Common::RandomSource _randomSource; bool loadAnimSet(uint32 heroAnimNumber); const Graphics::Surface * getSurface(); - void setPos(int16 x, int16 y) { _middleX = x; _middleX = y; } + void setPos(int16 x, int16 y) { _middleX = x; _middleY = y; } void setVisible(bool flag) { _visible = flag; } + void showHero(); + void moveHero(); + void rotateHero(); + void setScale(int8 zoomBitmapValue); + void selectZoom(); + void countDrawPosition(); + void showHeroAnimFrame(); + void specialAnim(); + void getState(); + //private: uint16 _number; uint16 _visible; - State _state; - int16 _middleX; - int16 _middleY; + int16 _state; + int16 _middleX; // middle of X + int16 _middleY; // lower part of hero + int16 _drawX; + int16 _drawY; + int16 _lastDirection; + int16 _destDirection; int16 _moveSetType; - int16 _frame; + int8 _zoomFactor; + int16 _scaleValue; // Coords array of coordinates // DirTab array of directions @@ -109,13 +130,13 @@ public: // DestDir // LeftRight previous left/right direction // UpDown previous up/down direction - // Phase animation phase + uint _phase; // Phase animation phase // Step x/y step size depends on direction // MaxBoredom stand still timeout - // Boredom current boredom time in frames + int16 _boredomTime;// Boredom current boredom time in frames uint16 _boreNum; // Bore anim frame - // TalkTime time of talk anim - // SpecAnim additional anim + int16 _talkTime; // TalkTime time of talk anim + int32 _specAnim; // SpecAnim additional anim uint16 _currHeight; // height of current anim phase @@ -126,6 +147,7 @@ public: // AnimSet number of animation set Common::Array<Animation *> _moveSet; // MoveAnims MoveSet // TurnAnim ?? + Animation *_zoomBitmap; // change to sth else, not Animation ?? uint32 _moveDelay; uint32 _shadMinus; //?? diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp index 685c397edb..324c4592ae 100644 --- a/engines/prince/prince.cpp +++ b/engines/prince/prince.cpp @@ -59,6 +59,7 @@ #include "prince/archive.h" #include "prince/hero.h" #include "prince/resource.h" +#include "prince/animation.h" namespace Prince { @@ -279,6 +280,9 @@ bool PrinceEngine::loadLocation(uint16 locationNr) { _sceneWidth = _roomBmp->getSurface()->w; } + _mainHero->_zoomBitmap->clear(); + Resource::loadResource(_mainHero->_zoomBitmap, "zoom", false); + _mobList.clear(); Resource::loadResource(_mobList, "mob.lst", false); @@ -475,6 +479,54 @@ void PrinceEngine::keyHandler(Common::Event event) { case Common::KEYCODE_ESCAPE: _flags->setFlagValue(Flags::ESCAPED2, 1); break; + case Common::KEYCODE_UP: + _mainHero->_phase++; + debugEngine("%d", _mainHero->_phase); + break; + case Common::KEYCODE_DOWN: + if(_mainHero->_phase > 0) { + _mainHero->_phase--; + } + debugEngine("%d", _mainHero->_phase); + break; + case Common::KEYCODE_w: + _mainHero->_lastDirection = _mainHero->UP; + debugEngine("UP"); + break; + case Common::KEYCODE_s: + _mainHero->_lastDirection = _mainHero->DOWN; + debugEngine("DOWN"); + break; + case Common::KEYCODE_a: + _mainHero->_lastDirection = _mainHero->LEFT; + debugEngine("LEFT"); + break; + case Common::KEYCODE_f: + _mainHero->_lastDirection = _mainHero->RIGHT; + debugEngine("RIGHT"); + break; + case Common::KEYCODE_1: + if(_mainHero->_state > 0) { + _mainHero->_state--; + } + debugEngine("%d", _mainHero->_state); + break; + case Common::KEYCODE_2: + _mainHero->_state++; + debugEngine("%d", _mainHero->_state); + break; + case Common::KEYCODE_i: + _mainHero->_middleY -= 10; + break; + case Common::KEYCODE_k: + _mainHero->_middleY += 10; + break; + case Common::KEYCODE_j: + _mainHero->_middleX -= 10; + break; + case Common::KEYCODE_l: + _mainHero->_middleX += 10; + break; } } @@ -575,7 +627,8 @@ void PrinceEngine::drawScreen() { const Graphics::Surface *mainHeroSurface = _mainHero->getSurface(); if (mainHeroSurface) - _graph->drawTransparent(_mainHero->_middleX, _mainHero->_middleY, mainHeroSurface); + //_graph->drawTransparent(_mainHero->_middleX, _mainHero->_middleY, mainHeroSurface); + _graph->drawTransparent(_mainHero->_drawX, _mainHero->_drawY, mainHeroSurface); } playNextFrame(); @@ -627,6 +680,7 @@ void PrinceEngine::mainLoop() { return; // TODO: Update all structures, animations, naks, heros etc. + _mainHero -> showHero(); _interpreter->step(); diff --git a/engines/prince/prince.h b/engines/prince/prince.h index f1707c04ec..a48f056d4d 100644 --- a/engines/prince/prince.h +++ b/engines/prince/prince.h @@ -62,6 +62,7 @@ class Cursor; class MhwanhDecoder; class Font; class Hero; +class Animation; struct Text { const char *_str; @@ -174,6 +175,7 @@ private: Common::SeekableReadStream *_voiceStream[MAX_SAMPLES]; Audio::SoundHandle _soundHandle[MAX_SAMPLES]; + Animation *_zoom; Common::Array<Mob> _mobList; Common::Array<Object *> _objList; Common::Array<AnimListItem> _animList; diff --git a/engines/prince/script.cpp b/engines/prince/script.cpp index 84174ec23c..84ae64791e 100644 --- a/engines/prince/script.cpp +++ b/engines/prince/script.cpp @@ -181,7 +181,7 @@ void Interpreter::debugInterpreter(const char *s, ...) { str += Common::String::format("op %04d: ", _lastOpcode); //debugC(10, DebugChannel::kScript, "PrinceEngine::Script %s %s", str.c_str(), buf); - debug("Prince::Script frame %08ld mode %s %s %s", _vm->_frameNr, _mode, str.c_str(), buf); + //debug("Prince::Script frame %08ld mode %s %s %s", _vm->_frameNr, _mode, str.c_str(), buf); } void Interpreter::step() { @@ -631,6 +631,10 @@ void Interpreter::O_SETHERO() { uint16 dir = readScriptFlagValue(); debugInterpreter("O_SETHERO hero %d, x %d, y %d, dir %d", hero, x, y, dir); _vm->_mainHero->setPos(x, y); + _vm->_mainHero->_lastDirection = dir; + _vm->_mainHero->_state = _vm->_mainHero->STAY; + _vm->_mainHero->_moveSetType = _vm->_mainHero->_lastDirection - 1; // for countDrawPosition + _vm->_mainHero->countDrawPosition(); //setting drawX, drawY } void Interpreter::O_HEROOFF() { |