diff options
Diffstat (limited to 'src/T2DLL/T2Animation.cpp')
-rw-r--r-- | src/T2DLL/T2Animation.cpp | 136 |
1 files changed, 123 insertions, 13 deletions
diff --git a/src/T2DLL/T2Animation.cpp b/src/T2DLL/T2Animation.cpp index 5b4aea4..88f6abe 100644 --- a/src/T2DLL/T2Animation.cpp +++ b/src/T2DLL/T2Animation.cpp @@ -1,34 +1,144 @@ +#include "GlobalFunc.h" #include "T2Animation.h" +#include "T2BitImage.h" +#include "T2ImageObj.h" +#include "T2PluginSpecifier.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" -void T2Animation::Rewind() { -} +T2Animation::T2Animation(T2TowerDoc* inDoc, short inNumOfFrame, short inNumOfSprite, const SpriteDef* inSpriteDef, const AnimationDef* inAnimationDef, T2Sprite::ELayer inLayer) { + mDocument = inDoc; + mNumOfFrame = inNumOfFrame; + mNumOfSprite = inNumOfSprite; + mAnimationDef = inAnimationDef; -int T2Animation::HasNextStep() const { -} + mFrame = 0; + SetPt(&mPoint, 0, 0); -int T2Animation::SetFrame(int) { -} + int i; -int T2Animation::GetFrame() const { -} + short maxCount = 0; + for (i = 0; i < mNumOfSprite; i++) { + if (maxCount < inSpriteDef[i].count) + maxCount = inSpriteDef[i].count; + } + + HINSTANCE theModuleHandle = inDoc->mWorldPluginSpecifier->mInstance; + + mSpriteIndices = new int[inNumOfSprite]; +#line 41 + _ASSERT(mSpriteIndices != NULL); + + mImageObjs = (T2ImageObj **) malloc(sizeof(T2ImageObj *) * inNumOfSprite); +#line 43 + _ASSERT(mImageObjs != NULL); + + mImages = (T2BitImage **) malloc(sizeof(T2BitImage *) * inNumOfSprite); +#line 45 + _ASSERT(mImages != NULL); + + for (i = 0; i < mNumOfSprite; i++) { + CString name; + name.Format("__Anime__%d", i); + + T2ImageObj *theImageObj = new T2ImageObj; + mImageObjs[i] = theImageObj; + + T2BitImage *theImage = new T2BitImage(theModuleHandle, inSpriteDef[i].resID, true); + mImages[i] = theImage; -T2Animation::T2Animation(T2TowerDoc*, short, short, const SpriteDef*, const AnimationDef*, T2Sprite::ELayer) { + RECT rect; + rect.left = 0; + rect.top = 0; + rect.right = inSpriteDef[i].width; + rect.bottom = inSpriteDef[i].height; + + for (short j = 0; j < inSpriteDef[i].count; j++) { + theImageObj->AddObject(name, j + 1, *theImage, &rect, true, false); + OffsetRect(&rect, 0, inSpriteDef[i].height); + } + + mSpriteIndices[i] = mDocument->mSprite.NewSprite(*theImageObj, name, inLayer); + } } T2Animation::~T2Animation() { + for (int i = 0; i < mNumOfSprite; i++) + mDocument->mSprite.DeleteSprite(mSpriteIndices[i]); + delete[] mSpriteIndices; + + if (mImageObjs) { + for (int i = 0; i < mNumOfSprite; i++) { + if (mImageObjs[i]) + delete mImageObjs[i]; + } + free(mImageObjs); + } + + if (mImages) { + for (int i = 0; i < mNumOfSprite; i++) { + if (mImages[i]) + delete mImages[i]; + } + free(mImages); + } } -int T2Animation::Start(POINT, int) { +BOOL T2Animation::Start(POINT inPt, int inLen) { + mPoint = inPt; + mInterval = 60 / inLen; + mTickCount = GetTickCount(); + + Draw(); + return HasNextStep(); } -int T2Animation::Idle() { +BOOL T2Animation::Idle() { + int newFrame = (GetTickCount() - mTickCount) / mInterval; + if (newFrame != mFrame) { + mFrame = newFrame; + Draw(); + } + + return HasNextStep(); } -void T2Animation::Play(POINT, int) { +void T2Animation::Play(POINT inPt, int inLen) { + mPoint = inPt; + + int delay = 60 / inLen; + int endTick = GetTickCount() + delay; + BOOL playing = mFrame < mNumOfFrame; + + while (playing) { + playing = Step(); + mDocument->GetTowerMainView()->tmv_vf120(); + + int now; + for (now = GetTickCount(); now < endTick; now = GetTickCount()) { + // nothing there! + } + + endTick = now + delay; + } } -int T2Animation::Step() { +BOOL T2Animation::Step() { + Draw(); + mFrame++; + return (mFrame < mNumOfFrame); } void T2Animation::Draw() { + if (HasNextStep()) { + for (int i = 0; i < mNumOfSprite; i++) { + const AnimationDef *def = mAnimationDef + (mFrame * mNumOfSprite) + i; + + CPoint pt = mPoint; + pt.Offset(def->position); + mDocument->mSprite.MoveSprite(mSpriteIndices[i], pt); + mDocument->mSprite.ChangePattern(mSpriteIndices[i], def->pattern); + mDocument->mSprite.ShowSprite(mSpriteIndices[i], true); + } + } } |