diff options
Diffstat (limited to 'engines/neverhood/sprite.cpp')
-rw-r--r-- | engines/neverhood/sprite.cpp | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/engines/neverhood/sprite.cpp b/engines/neverhood/sprite.cpp index 50880089f9..3611ce1ba2 100644 --- a/engines/neverhood/sprite.cpp +++ b/engines/neverhood/sprite.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -28,11 +28,23 @@ namespace Neverhood { // Sprite Sprite::Sprite(NeverhoodEngine *vm, int objectPriority) - : Entity(vm, objectPriority), _x(0), _y(0), _spriteUpdateCb(NULL), _filterXCb(NULL), _filterYCb(NULL), + : Entity(vm, objectPriority), _x(0), _y(0), _spriteUpdateCb(NULL), _filterXCb(NULL), _filterYCb(NULL), _dataResource(vm), _doDeltaX(false), _doDeltaY(false), _needRefresh(false), _flags(0), _surface(NULL) { + _drawOffset.x = 0; + _drawOffset.y = 0; + _drawOffset.width = 0; + _drawOffset.height = 0; + _collisionBounds.x1 = 0; + _collisionBounds.y1 = 0; + _collisionBounds.x2 = 0; + _collisionBounds.y2 = 0; + _collisionBoundsOffset.x = 0; + _collisionBoundsOffset.y = 0; + _collisionBoundsOffset.width = 0; + _collisionBoundsOffset.height = 0; + SetMessageHandler(&Sprite::handleMessage); - } Sprite::~Sprite() { @@ -71,7 +83,7 @@ bool Sprite::isPointInside(int16 x, int16 y) { } bool Sprite::checkCollision(NRect &rect) { - return (_collisionBounds.x1 < rect.x2) && (rect.x1 < _collisionBounds.x2) && (_collisionBounds.y1 < rect.y2) && (rect.y1 < _collisionBounds.y2); + return (_collisionBounds.x1 < rect.x2) && (rect.x1 < _collisionBounds.x2) && (_collisionBounds.y1 < rect.y2) && (rect.y1 < _collisionBounds.y2); } uint32 Sprite::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { @@ -153,13 +165,13 @@ void StaticSprite::updatePosition() { if (!_surface) return; - + if (_doDeltaX) { _surface->getDrawRect().x = filterX(_x - _drawOffset.x - _drawOffset.width + 1); } else { _surface->getDrawRect().x = filterX(_x + _drawOffset.x); } - + if (_doDeltaY) { _surface->getDrawRect().y = filterY(_y - _drawOffset.y - _drawOffset.height + 1); } else { @@ -211,6 +223,12 @@ void AnimatedSprite::init() { _replNewColor = 0; _animResource.setReplEnabled(false); _playBackwards = false; + _currAnimFileHash = 0; + _lastFrameIndex = 0; + _plLastFrameIndex = 0; + _plFirstFrameHash = 0; + _plLastFrameHash = 0; + _animStatus = 0; } void AnimatedSprite::update() { @@ -261,7 +279,7 @@ void AnimatedSprite::updateAnim() { } if (_newAnimFileHash == 0 && _currFrameIndex != _currStickFrameIndex) { if (_currFrameTicks != 0 && (--_currFrameTicks == 0) && _animResource.getFrameCount() != 0) { - + if (_nextAnimFileHash != 0) { if (_animResource.load(_nextAnimFileHash)) { _currAnimFileHash = _nextAnimFileHash; @@ -270,7 +288,7 @@ void AnimatedSprite::updateAnim() { _currAnimFileHash = 0; } if (_replOldColor != _replNewColor) { - _animResource.setRepl(_replOldColor, _replNewColor); + _animResource.setRepl(_replOldColor, _replNewColor); } _nextAnimFileHash = 0; if (_animStatus != 0) { @@ -278,17 +296,17 @@ void AnimatedSprite::updateAnim() { _lastFrameIndex = _plLastFrameHash != 0 ? MAX<int16>(0, _animResource.getFrameIndex(_plLastFrameHash)) : _animResource.getFrameCount() - 1; } else { _currFrameIndex = _plFirstFrameIndex != -1 ? _plFirstFrameIndex : _animResource.getFrameCount() - 1; - _lastFrameIndex = _plLastFrameIndex != -1 ? _plLastFrameIndex : _animResource.getFrameCount() - 1; + _lastFrameIndex = _plLastFrameIndex != -1 ? _plLastFrameIndex : _animResource.getFrameCount() - 1; } } else { updateFrameIndex(); } if (_newAnimFileHash == 0) updateFrameInfo(); - } + } } } - + if (_newAnimFileHash != 0) { if (_animStatus == 2) { _currStickFrameIndex = _currFrameIndex; @@ -301,7 +319,7 @@ void AnimatedSprite::updateAnim() { _currAnimFileHash = 0; } if (_replOldColor != _replNewColor) { - _animResource.setRepl(_replOldColor, _replNewColor); + _animResource.setRepl(_replOldColor, _replNewColor); } _newAnimFileHash = 0; _currFrameIndex = _plFirstFrameHash != 0 ? MAX<int16>(0, _animResource.getFrameIndex(_plFirstFrameHash)) : 0; @@ -314,7 +332,7 @@ void AnimatedSprite::updateAnim() { _currAnimFileHash = 0; } if (_replOldColor != _replNewColor) { - _animResource.setRepl(_replOldColor, _replNewColor); + _animResource.setRepl(_replOldColor, _replNewColor); } _newAnimFileHash = 0; _currFrameIndex = _plFirstFrameIndex != -1 ? _plFirstFrameIndex : _animResource.getFrameCount() - 1; @@ -366,7 +384,7 @@ void AnimatedSprite::updateFrameIndex() { } else { // Inform self about end of current animation // The caller can then e.g. set a new animation fileHash - sendMessage(this, 0x3002, 0); + sendMessage(this, NM_ANIMATION_STOP, 0); if (_newAnimFileHash == 0) _currFrameIndex = 0; } @@ -374,7 +392,7 @@ void AnimatedSprite::updateFrameIndex() { if (_currFrameIndex > 0) { _currFrameIndex--; } else { - sendMessage(this, 0x3002, 0); + sendMessage(this, NM_ANIMATION_STOP, 0); if (_newAnimFileHash == 0) _currFrameIndex = _lastFrameIndex; } @@ -393,7 +411,7 @@ void AnimatedSprite::updateFrameInfo() { updateBounds(); _needRefresh = true; if (frameInfo.frameHash != 0) - sendMessage(this, 0x100D, frameInfo.frameHash); + sendMessage(this, NM_ANIMATION_START, frameInfo.frameHash); } void AnimatedSprite::createSurface1(uint32 fileHash, int surfacePriority) { |