22 #ifndef NEVERHOOD_SPRITE_H 23 #define NEVERHOOD_SPRITE_H 25 #include "neverhood/neverhood.h" 26 #include "neverhood/entity.h" 27 #include "neverhood/graphics.h" 28 #include "neverhood/resource.h" 29 #include "neverhood/subtitles.h" 33 #define SetSpriteUpdate(callback) \ 35 _spriteUpdateCb = static_cast <void (Sprite::*)(void)> (callback); \ 36 debug(2, "SetSpriteUpdate(" #callback ")"); \ 37 _spriteUpdateCbName = #callback; \ 40 #define SetFilterX(callback) \ 42 _filterXCb = static_cast <int16 (Sprite::*)(int16)> (callback); \ 43 debug(2, "SetFilterX(" #callback ")"); \ 46 #define SetFilterY(callback) \ 48 _filterYCb = static_cast <int16 (Sprite::*)(int16)> (callback); \ 49 debug(2, "SetFilterY(" #callback ")"); \ 52 const int16 kDefPosition = -32768;
61 void setDoDeltaX(
int type);
62 void setDoDeltaY(
int type);
63 bool isPointInside(int16 x, int16 y);
64 bool checkCollision(
NRect &rect);
65 int16 getX()
const {
return _x; }
66 int16 getY()
const {
return _y; }
67 void setX(int16 value) { _x = value; }
68 void setY(int16 value) { _y = value; }
69 uint16 getFlags()
const {
return _flags; }
70 bool isDoDeltaX()
const {
return _doDeltaX; }
71 bool isDoDeltaY()
const {
return _doDeltaY; }
72 NRect& getCollisionBounds() {
return _collisionBounds; }
74 void loadDataResource(uint32 fileHash);
75 int16 defFilterY(int16 y);
76 bool getVisible()
const {
return _surface->getVisible(); }
77 void setVisible(
bool value) { _surface->setVisible(value); }
78 NDrawRect& getDrawRect() {
return _surface->getDrawRect(); }
80 NRect& getClipRect() {
return _surface->getClipRect(); }
81 void setClipRect(int16 x1, int16 y1, int16 x2, int16 y2);
82 void setClipRect(
NRect& clipRect);
85 void (
Sprite::*_spriteUpdateCb)();
87 int16 (
Sprite::*_filterXCb)(int16);
88 int16 (
Sprite::*_filterYCb)(int16);
91 bool _doDeltaX, _doDeltaY;
94 NRect _collisionBounds;
98 void createSurface(
int surfacePriority, int16 width, int16 height);
99 void handleSpriteUpdate() {
101 (this->*_spriteUpdateCb)();
103 int16 filterX(int16 x) {
104 return _filterXCb ? (this->*_filterXCb)(x) : x;
106 int16 filterY(int16 y) {
107 return _filterYCb ? (this->*_filterYCb)(y) : y;
112 kSLFDefDrawOffset = 1 << 0,
113 kSLFCenteredDrawOffset = 1 << 1,
114 kSLFDefPosition = 1 << 2,
115 kSLFSetPosition = 1 << 3,
116 kSLFDefCollisionBoundsOffset = 1 << 4
123 void loadSprite(uint32 fileHash, uint flags = 0,
int surfacePriority = 0, int16 x = kDefPosition, int16 y = kDefPosition);
124 void updatePosition();
129 #define AnimationCallback(callback) static_cast <void (AnimatedSprite::*)()> (callback) 130 #define GotoState(callback) gotoState(static_cast <void (AnimatedSprite::*)()> (callback)) 131 #define NextState(callback) \ 133 _nextStateCb = static_cast <void (AnimatedSprite::*)(void)> (callback); \ 134 debug(2, "NextState(" #callback ")"); _nextStateCbName = #callback; \ 136 #define FinalizeState(callback) setFinalizeState(static_cast <void (AnimatedSprite::*)()> (callback)); 138 const int STICK_LAST_FRAME = -2;
145 void updateDeltaXY();
146 void setRepl(byte oldColor, byte newColor);
148 uint32 getCurrAnimFileHash()
const {
return _currAnimFileHash; }
149 int16 getFrameIndex()
const {
return _currFrameIndex; }
150 int16 getFrameIndex(uint32 frameHash) {
return _animResource.getFrameIndex(frameHash); }
151 void setNewHashListIndex(
int value) { _newStickFrameIndex = value; }
152 void startAnimation(uint32 fileHash, int16 plFirstFrameIndex, int16 plLastFrameIndex);
157 void draw()
override;
159 void setFrameIndex(
int currFrameIndex,
int lastFrameIndex);
160 void setHash(uint32 fileHash);
161 void updatePosition(
const NDrawRect &parentDrawRect);
168 static const int kSubtitleWidth = 320;
172 uint32 _currAnimFileHash, _newAnimFileHash, _nextAnimFileHash;
173 int16 _currFrameIndex, _lastFrameIndex;
174 int16 _plFirstFrameIndex, _plLastFrameIndex;
175 uint32 _plFirstFrameHash, _plLastFrameHash;
177 int16 _currFrameTicks;
178 int _currStickFrameIndex, _newStickFrameIndex;
179 uint32 _newStickFrameHash;
180 int16 _deltaX, _deltaY;
181 byte _replOldColor, _replNewColor;
182 bool _playBackwards, _frameChanged;
183 AnimationCb _finalizeStateCb;
184 AnimationCb _currStateCb;
185 AnimationCb _nextStateCb;
192 void updatePosition();
193 void updateFrameIndex();
194 void updateFrameInfo();
195 void createSurface1(uint32 fileHash,
int surfacePriority);
198 void stopAnimation();
199 void startAnimationByHash(uint32 fileHash, uint32 plFirstFrameHash, uint32 plLastFrameHash);
200 void nextAnimationByHash(uint32 fileHash2, uint32 plFirstFrameHash, uint32 plLastFrameHash);
201 void setFinalizeState(AnimationCb finalizeStateCb);
202 void gotoState(AnimationCb currStateCb);
203 void gotoNextState();
Definition: background.h:30
Definition: neverhood.h:60
Definition: resource.h:51
Definition: resource.h:94
Definition: graphics.h:42
Definition: graphics.h:67
Definition: resource.h:162
Definition: graphics.h:85