#include <CSAnimation.h>
<!ENTITY % types SYSTEM "types.dtd"> %types; <!ELEMENT ANIMATION (ID,IS_BREAKABLE,REPEATABLE,(PHASE)+,(IMAGE_DATA)+)> <!ELEMENT ID (#PCDATA)> <!ELEMENT IS_BREAKABLE (#PCDATA)> <!ELEMENT REPEATABLE (#PCDATA)> <!ELEMENT PHASE (#PCDATA)> <!ELEMENT IMAGE_DATA (PICTURE,ANIMATION_RATE,MOVE_X,MOVE_Y)> <!ELEMENT PICTURE (#PCDATA)> <!ELEMENT ANIMATION_RATE (#PCDATA)> <!ELEMENT MOVE_X (#PCDATA)> <!ELEMENT MOVE_Y (#PCDATA)>
Example:
<ANIMATION> <ID>PAC_DOWN</ID> <IS_BREAKABLE>&true;</IS_BREAKABLE> <REPEATABLE>&INVERSE_ONCE;</REPEATABLE> <PHASE>0</PHASE> <PHASE>1</PHASE> <PHASE>2</PHASE> <PHASE>3</PHASE> <PHASE>4</PHASE> <IMAGE_DATA> <PICTURE>picture\\pac_down1.xml</PICTURE> <ANIMATION_RATE>&A_RATE;</ANIMATION_RATE> <MOVE_X>0</MOVE_X> <MOVE_Y>&SPEED;</MOVE_Y> </IMAGE_DATA> <IMAGE_DATA> <PICTURE>picture\\pac_down2.xml</PICTURE> <ANIMATION_RATE>&A_RATE;</ANIMATION_RATE> <MOVE_X>0</MOVE_X> <MOVE_Y>&SPEED;</MOVE_Y> </IMAGE_DATA> ... </ANIMATION>
ID - supposed a unique identifier IS_BREAKABLE - if an animation can be interrupted by some action REAPEATABLE - one of: CS_NOT_REPEATABLE = 0; CS_REPEATABLE = 1; CS_INVERSE_ONCE = 2; CS_INVERSE_REPEATABLE = 3; CS_RANDOM = 4; // (not implemented)
PHASES - many phases, each phase is represented by a number the number corresponse to the IMAGE_DATA that is loaded with the ini - file (numbered from top to bottom. NOTE: REAPEATABLE CS_INVERSE_ONCE PHASES 0 PHASES 1 PHASES 2 PHASES 3 PHASES 4
gives the same result as: REAPEATABLE CS_NOT_REPEATABLE PHASES 0 PHASES 1 PHASES 2 PHASES 3 PHASES 4 PHASES 3 PHASES 2 PHASES 1 PHASES 0
if an animation has only one image, it is not really much of an aniamtion -> thus an aniamtion with only one picture never uses aniamtion rate, and never uses the repeatable flag IMAGE_DATA - many image_data's are possible describes the image to be loaded, PICTURE parameter gives the ini-file for a CSPicture, ANIMATION_RATE parameter gives the delay between two animation phases negative animation rates are not in animtions per second but aniamtion each # of seconds! MOVE_X parameter gives the value (speed) with which the the x-coordinates wil be updated (negative and positive) pixels per second MOVE_Y parameter gives the value (speed) with which the the y-coordinates wil be updated (negative and positive) pixels per second
CSAnimation are singletons in the sense, that two "loaded" CSAnimations of the same "ini" file ARE the same instances.
the animation class has no instance relevant data (state independant) thus one instance can be reused
Definition at line 279 of file CSAnimation.h.
Public Member Functions | |
virtual std::string | getType () |
CSAnimation (const CSAnimation &animation) | |
virtual | ~CSAnimation () |
unsigned int | getMaxX () |
unsigned int | getMaxY () |
void | setSolid (bool b) |
void | scale (int width, int tilesX, int height, int tilesY) |
AnimationState | buildState () |
build an initial state for this aniamtion, sets variables to defaults | |
void | resetState (AnimationState &state) |
void | startAnimation (AnimationState &state) |
void | startNextAnimation (AnimationState &state) |
comment | |
bool | next (AnimationState &state) |
if finished and not repeat -> false, true otherwise | |
void | display (AnimationState &state) |
not much to do here, to display a picture | |
void | setAlpha (int alpha) |
SDL_Surface * | getScaledAnimation (AnimationState &mAnimationState, double factor) |
bool | isSolid () |
bool | isBreakable () |
void | setSecPerFrame (float secPerFrame) |
void | setSpeedX (int speed, AnimationState &state) |
void | setSpeedY (int speed, AnimationState &state) |
void | adjustSpeed (int speed, AnimationState &state) |
void | resetSpeed (AnimationState &state) |
Static Public Attributes | |
const char * | CLASS = "CSAnimation" |
|
Definition at line 20 of file CSAnimation.cpp. References CSPictures, LOG_ENTER, LOG_EXIT, mAnimationRates, mIsBreakable, mIsSolid, mMoveAllowed, mMoveX, mMoveY, mPhases, mPictures, mRepeatable, mSecsPerFrame, mSizePhases, and mSizePictures.
00021 { 00022 static char *functionName="CSAnimation"; 00023 LOG_ENTER 00024 mSecsPerFrame = animation.mSecsPerFrame; 00025 mSizePictures = animation.mSizePictures; 00026 mSizePhases = animation.mSizePhases; 00027 mMoveAllowed = animation.mMoveAllowed; 00028 mRepeatable = animation.mRepeatable; 00029 mIsBreakable = animation.mIsBreakable; 00030 mIsSolid = animation.mIsSolid; 00031 00032 mPhases = new unsigned int[mSizePhases]; 00033 for (int i=0; i < mSizePhases; i++) 00034 { 00035 mPhases[i] = animation.mPhases[i]; 00036 } 00037 00038 mPictures = new CSPictures(); 00039 mAnimationRates = new float[mSizePictures]; 00040 mMoveX = new signed int[mSizePictures]; 00041 mMoveY = new signed int[mSizePictures]; 00042 i = 0; 00043 CSPictures::iterator iter = animation.mPictures->begin(); 00044 while (iter != animation.mPictures->end()) 00045 { 00046 CSPicture *pic = *iter; 00047 // picture need not be loaded again-> 00048 // we can use the same pointer since it is a singleton anyway! 00049 mPictures->push_back(pic); 00050 00051 mAnimationRates[i] = animation.mAnimationRates[i]; 00052 mMoveX[i] = animation.mMoveX[i]; 00053 mMoveY[i] = animation.mMoveY[i]; 00054 i++; 00055 iter++; 00056 } 00057 LOG_EXIT 00058 } |
|
Definition at line 132 of file CSAnimation.cpp. References LOG_ENTER, and LOG_EXIT.
00133 { 00134 static char *functionName="~CSAnimation"; 00135 LOG_ENTER 00136 if (mPictures != 0) 00137 { 00138 // CSPictures are deleted by CSPictureLoader! 00139 delete mPictures; 00140 mPictures = 0; 00141 } 00142 if (mPhases != 0) 00143 { 00144 delete []mPhases; 00145 mPhases = 0; 00146 } 00147 if (mAnimationRates != 0) 00148 { 00149 delete []mAnimationRates; 00150 mAnimationRates = 0; 00151 } 00152 if (mMoveX !=0) 00153 { 00154 delete []mMoveX; 00155 mMoveX = 0; 00156 } 00157 if (mMoveY !=0) 00158 { 00159 delete []mMoveY; 00160 mMoveY = 0; 00161 } 00162 LOG_EXIT 00163 } |
|
Definition at line 310 of file CSAnimation.h. References CLASS.
00310 {return (std::string) CLASS;} |
|
of all pictures belonging to this animation return the largest width Definition at line 268 of file CSAnimation.cpp. References CSPicture::getMaxX(). Referenced by CSAction::getMaxX(), and CSTile::getWitdh().
00269 { 00270 static char *functionName="getMaxX"; 00271 unsigned int maxX = 0; 00272 unsigned int x; 00273 for (CSPictures::iterator iter = mPictures->begin(); iter != mPictures->end(); iter++) 00274 { 00275 CSPicture *pic = *iter; 00276 x = pic->getMaxX(); if (maxX < x) maxX = x; 00277 } 00278 return maxX; 00279 } |
Here is the call graph for this function:
|
of all pictures belonging to this animation return the largest height Definition at line 283 of file CSAnimation.cpp. References CSPicture::getMaxY(). Referenced by CSTile::getHeight(), and CSAction::getMaxY().
00284 { 00285 static char *functionName="getMaxY"; 00286 unsigned int maxY = 0; 00287 unsigned int y; 00288 for (CSPictures::iterator iter = mPictures->begin(); iter != mPictures->end(); iter++) 00289 { 00290 CSPicture *pic = *iter; 00291 y = pic->getMaxY(); if (maxY < y) maxY = y; 00292 } 00293 return maxY; 00294 } |
Here is the call graph for this function:
|
Definition at line 173 of file CSAnimation.cpp. References LOG_ENTER, LOG_EXIT, and CSPicture::setSolid(). Referenced by CSTile::setSolid().
|
Here is the call graph for this function:
|
Definition at line 551 of file CSAnimation.cpp. References LOG_ENTER, LOG_EXIT, and CSPicture::scale(). Referenced by CSTile::scale().
|
Here is the call graph for this function:
|
build an initial state for this aniamtion, sets variables to defaults
Definition at line 199 of file CSAnimation.cpp. References AnimationState::mAnimationRateCounter, AnimationState::mCurrentPhase, AnimationState::mCurrentPicture, AnimationState::mFinished, AnimationState::mForward, AnimationState::mPicture, AnimationState::mXPos, and AnimationState::mYPos. Referenced by CSAction::buildState().
00200 { 00201 static char *functionName="buildState"; 00202 AnimationState state; 00203 state.mXPos = 0; 00204 state.mYPos = 0; 00205 state.mCurrentPhase = 0; 00206 state.mCurrentPicture = mPhases[state.mCurrentPhase]; 00207 state.mPicture = mPictures->at(state.mCurrentPicture); 00208 state.mAnimationRateCounter = 0; 00209 state.mForward = true; 00210 state.mFinished = false; 00211 return state; 00212 } |
|
resets a state to default values doesn't update mDisplayParams! (this position and mDisplayPicture do not change!) Definition at line 217 of file CSAnimation.cpp. References AnimationState::mAnimationRateCounter, AnimationState::mCurrentPhase, AnimationState::mCurrentPicture, AnimationState::mFinished, AnimationState::mForward, AnimationState::mPicture, AnimationState::mSpeedX, AnimationState::mSpeedY, AnimationState::mXPos, and AnimationState::mYPos. Referenced by CSTile::next(), and CSAction::resetState().
00218 { 00219 static char *functionName="resetState"; 00220 state.mCurrentPhase = 0; 00221 state.mCurrentPicture = mPhases[state.mCurrentPhase]; 00222 state.mPicture = mPictures->at(state.mCurrentPicture); 00223 state.mAnimationRateCounter = 0; 00224 state.mSpeedX = ANIMATION_SPEED; 00225 state.mSpeedY = ANIMATION_SPEED; 00226 state.mForward = true; 00227 state.mFinished = false; 00228 state.mXPos = 0; 00229 state.mYPos = 0; 00230 } |
|
|
comment resets a state to start values of this animation this will not be displayed during next display() call happens when one animation ends during update, and a next animation is initiated - this means the next animation is active from the start of next update, doesn't interfere with current mDisplayParams! Definition at line 255 of file CSAnimation.cpp. References AnimationState::mAnimationRateCounter, AnimationState::mCurrentPhase, AnimationState::mCurrentPicture, AnimationState::mFinished, AnimationState::mForward, and AnimationState::mPicture. Referenced by CSAction::startNextAction().
00256 { 00257 static char *functionName="startNextAnimation"; 00258 state.mCurrentPhase = 0; 00259 state.mCurrentPicture = mPhases[state.mCurrentPhase]; 00260 state.mPicture = mPictures->at(state.mCurrentPicture); 00261 state.mAnimationRateCounter = 0; 00262 state.mForward = true; 00263 state.mFinished = false; 00264 } |
|
if finished and not repeat -> false, true otherwise if finished and not repeat -> false, true otherwise does not display anything, but prepares (update) for next displaying Definition at line 298 of file CSAnimation.cpp. References AnimationState::mAdjustSpeed, AnimationState::mAnimationRateCounter, AnimationState::mCurrentPhase, AnimationState::mCurrentPicture, AnimationState::mDisplayParams, AnimationState::mDisplayPicture, AnimationState::mFinished, AnimationState::mForward, AnimationState::mPicture, AnimationState::mSpeedX, AnimationState::mSpeedY, CSDisplayParams::mXPos, AnimationState::mXPos, CSDisplayParams::mYPos, and AnimationState::mYPos. Referenced by CSTile::next(), and CSAction::next().
00299 { 00300 static char *functionName="next"; 00301 if (state.mFinished) 00302 { 00303 return !state.mFinished; 00304 } 00305 00306 // if an animation has only one picture, it is not really 00307 // much of an aniamtion -> display it, regardless 00308 // of any counters, 00309 // thus an aniamtion with only one picture never ends! 00310 if (mSizePictures <= 1) 00311 { 00312 if (mMoveAllowed) 00313 { 00314 // speed calculated vi frame per second 00315 if (state.mSpeedX == ANIMATION_SPEED) 00316 { 00317 state.mXPos += (float) (mMoveX[state.mCurrentPicture]*mSecsPerFrame); 00318 } 00319 else if (state.mSpeedX == ADJUST_SPEED) 00320 { 00321 int speed = 0; 00322 if (mMoveX[state.mCurrentPicture] < 0) 00323 speed = -state.mAdjustSpeed; 00324 if (mMoveX[state.mCurrentPicture] > 0) 00325 speed = state.mAdjustSpeed; 00326 state.mXPos += (float) (speed*mSecsPerFrame); 00327 } 00328 else 00329 { 00330 state.mXPos += (float) (state.mSpeedX*mSecsPerFrame); 00331 } 00332 00333 if (state.mSpeedY == ANIMATION_SPEED) 00334 { 00335 state.mYPos += (float) (mMoveY[state.mCurrentPicture]*mSecsPerFrame); 00336 } 00337 else if (state.mSpeedY == ADJUST_SPEED) 00338 { 00339 int speed = 0; 00340 if (mMoveY[state.mCurrentPicture] < 0) 00341 speed = -state.mAdjustSpeed; 00342 if (mMoveY[state.mCurrentPicture] > 0) 00343 speed = state.mAdjustSpeed; 00344 state.mYPos += (float) (speed*mSecsPerFrame); 00345 } 00346 else 00347 { 00348 state.mYPos += (float) (state.mSpeedY*mSecsPerFrame); 00349 } 00350 } 00351 00352 state.mDisplayParams.mXPos = state.mXPos; 00353 state.mDisplayParams.mYPos = state.mYPos; 00354 state.mDisplayPicture = state.mPicture; 00355 return true; 00356 } 00357 00358 // animation rate calculated vi frame per second 00359 state.mAnimationRateCounter += (float) (mAnimationRates[state.mCurrentPicture] * mSecsPerFrame); 00360 // if animation frame should change 00361 if (state.mAnimationRateCounter >= 1) 00362 { 00363 state.mAnimationRateCounter = 0; 00364 if (mRepeatable == CS_RANDOM) 00365 { 00366 // TODO 00367 } 00368 else 00369 { 00370 if (state.mForward) 00371 { 00372 state.mCurrentPhase++; 00373 if (state.mCurrentPhase == mSizePhases) 00374 { 00375 if (mRepeatable == CS_INVERSE_REPEATABLE) 00376 { 00377 state.mForward = !state.mForward; 00378 if (mSizePhases > 1) 00379 { 00380 state.mCurrentPhase-=2; 00381 } 00382 else 00383 { 00384 state.mCurrentPhase--; 00385 } 00386 } 00387 else 00388 if (mRepeatable == CS_INVERSE_ONCE) 00389 { 00390 state.mForward = !state.mForward; 00391 if (mSizePhases > 1) 00392 { 00393 state.mCurrentPhase-=2; 00394 } 00395 else 00396 { 00397 state.mCurrentPhase--; 00398 } 00399 } 00400 else 00401 { 00402 if (mRepeatable == CS_NOT_REPEATABLE) 00403 { 00404 state.mFinished = true; 00405 return !state.mFinished; 00406 } 00407 state.mCurrentPhase = 0; 00408 } 00409 } 00410 } 00411 else // mForward 00412 { 00413 state.mCurrentPhase--; 00414 if (state.mCurrentPhase == -1) 00415 { 00416 if (mRepeatable == CS_INVERSE_REPEATABLE) 00417 { 00418 state.mForward = !state.mForward; 00419 if (mSizePhases > 1) 00420 { 00421 state.mCurrentPhase+=2; 00422 } 00423 else 00424 { 00425 state.mCurrentPhase++; 00426 } 00427 } 00428 else 00429 { 00430 if (mRepeatable == CS_INVERSE_ONCE) 00431 { 00432 state.mFinished = true; 00433 return !state.mFinished; 00434 } 00435 state.mCurrentPhase = 0; 00436 } 00437 } 00438 } 00439 } // else (mRepeatable == CS_RANDOM) 00440 state.mCurrentPicture = mPhases[state.mCurrentPhase]; 00441 state.mPicture = mPictures->at(state.mCurrentPicture); 00442 } // (state.mDelayCounter == mDelays[mPhases[state.mCurrentPhase]]) 00443 00444 if (mMoveAllowed) 00445 { 00446 // speed calculated vi frame per second 00447 if (state.mSpeedX == ANIMATION_SPEED) 00448 { 00449 state.mXPos += (float) (mMoveX[state.mCurrentPicture]*mSecsPerFrame); 00450 } 00451 else if (state.mSpeedX == ADJUST_SPEED) 00452 { 00453 int speed = 0; 00454 if (mMoveX[state.mCurrentPicture] < 0) 00455 speed = -state.mAdjustSpeed; 00456 if (mMoveX[state.mCurrentPicture] > 0) 00457 speed = state.mAdjustSpeed; 00458 state.mXPos += (float) (speed*mSecsPerFrame); 00459 } 00460 else 00461 { 00462 state.mXPos += (float) (state.mSpeedX*mSecsPerFrame); 00463 } 00464 00465 if (state.mSpeedY == ANIMATION_SPEED) 00466 { 00467 state.mYPos += (float) (mMoveY[state.mCurrentPicture]*mSecsPerFrame); 00468 } 00469 else if (state.mSpeedY == ADJUST_SPEED) 00470 { 00471 int speed = 0; 00472 if (mMoveY[state.mCurrentPicture] < 0) 00473 speed = -state.mAdjustSpeed; 00474 if (mMoveY[state.mCurrentPicture] > 0) 00475 speed = state.mAdjustSpeed; 00476 state.mYPos += (float) (speed*mSecsPerFrame); 00477 } 00478 else 00479 { 00480 state.mYPos += (float) (state.mSpeedY*mSecsPerFrame); 00481 } 00482 00483 state.mDisplayParams.mXPos = state.mXPos; 00484 state.mDisplayParams.mYPos = state.mYPos; 00485 } 00486 state.mDisplayPicture = state.mPicture; 00487 return true; 00488 } |
|
not much to do here, to display a picture
Definition at line 491 of file CSAnimation.cpp. References CSPicture::display(), AnimationState::mDisplayParams, and AnimationState::mDisplayPicture. Referenced by CSTile::display(), and CSAction::display().
00492 { 00493 static char *functionName="display"; 00494 state.mDisplayPicture->display(&(state.mDisplayParams)); 00495 } |
Here is the call graph for this function:
|
Definition at line 186 of file CSAnimation.cpp. References LOG_ENTER, LOG_EXIT, and CSPicture::setAlpha(). Referenced by CSAction::setAlpha().
|
Here is the call graph for this function:
|
Definition at line 327 of file CSAnimation.h. References CSPicture::getScaledPicture(), and AnimationState::mPicture. Referenced by CSSprite::getScaledSprite(), and CSTile::getScaledTile().
00328 { 00329 //! \todo: do all animation states beforehand 00330 return mAnimationState.mPicture->getScaledPicture(factor); 00331 } |
Here is the call graph for this function:
|
Definition at line 334 of file CSAnimation.h.
00334 {return mIsSolid;}
|
|
Definition at line 335 of file CSAnimation.h. Referenced by CSAction::isBreakable().
00335 {return mIsBreakable;}
|
|
Definition at line 165 of file CSAnimation.cpp. References LOG_ENTER, and LOG_EXIT. Referenced by CSTile::setSecPerFrame(), and CSAction::setSecPerFrame().
|
|
Definition at line 337 of file CSAnimation.h. References AnimationState::mSpeedX. Referenced by CSSprite::setSpeedX().
00337 {state.mSpeedX = speed;} |
|
Definition at line 338 of file CSAnimation.h. References AnimationState::mSpeedY. Referenced by CSSprite::setSpeedY().
00338 {state.mSpeedY = speed;} |
|
Definition at line 339 of file CSAnimation.h. References ADJUST_SPEED, AnimationState::mAdjustSpeed, AnimationState::mSpeedX, and AnimationState::mSpeedY. Referenced by CSSprite::adjustSpeed().
00340 {state.mSpeedX = state.mSpeedY = ADJUST_SPEED;state.mAdjustSpeed = speed;} |
|
Definition at line 341 of file CSAnimation.h. References ANIMATION_SPEED, AnimationState::mSpeedX, and AnimationState::mSpeedY. Referenced by CSSprite::resetSpeed().
00341 {state.mSpeedX = state.mSpeedY = ANIMATION_SPEED;} |
|
Definition at line 8 of file CSAnimation.cpp. Referenced by getType(). |