diff options
author | Chris Xiong <chirs241097@gmail.com> | 2015-10-26 22:52:36 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2015-10-26 22:52:36 +0800 |
commit | 3bd383baf6a17e734329e1fc677c7e86283db772 (patch) | |
tree | 69a9148087577f797624ceb9c71323a2563d6bb4 /archive/hgehelp/hgeanim.cpp | |
parent | 543e4f570be9b279ba558ca61cc02cda251af384 (diff) | |
download | bullet-lab-remix-3bd383baf6a17e734329e1fc677c7e86283db772.tar.xz |
Added support for relative line numbers.
Added instructions for, brk and cont. (They are still untested...)
Parser code cleanup. Removed garbage output to stderr.
Reorganize the repository structure.
Updated BLR2 code move it into archive.
Added BLR1 files.
Diffstat (limited to 'archive/hgehelp/hgeanim.cpp')
-rw-r--r-- | archive/hgehelp/hgeanim.cpp | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/archive/hgehelp/hgeanim.cpp b/archive/hgehelp/hgeanim.cpp new file mode 100644 index 0000000..0e370db --- /dev/null +++ b/archive/hgehelp/hgeanim.cpp @@ -0,0 +1,165 @@ +/* +** Haaf's Game Engine 1.7 +** Copyright (C) 2003-2007, Relish Games +** hge.relishgames.com +** +** hgeAnimation helper class implementation +*/ + + +#include "hgeanim.h" + + +hgeAnimation::hgeAnimation(HTEXTURE tex, int nframes, float FPS, float x, float y, float w, float h) + : hgeSprite(tex, x, y, w, h) +{ + orig_width = hge->Texture_GetWidth(tex, true); + + fSinceLastFrame=-1.0f; + fSpeed=1.0f/FPS; + bPlaying=false; + nFrames=nframes; + + Mode=HGEANIM_FWD | HGEANIM_LOOP; + nDelta=1; + SetFrame(0); +} + +hgeAnimation::hgeAnimation(const hgeAnimation & anim) +: hgeSprite(anim) +{ + // Copy hgeAnimation parameters: + this->orig_width = anim.orig_width; + this->bPlaying = anim.bPlaying; + this->fSpeed = anim.fSpeed; + this->fSinceLastFrame = anim.fSinceLastFrame; + this->Mode = anim.Mode; + this->nDelta = anim.nDelta; + this->nFrames = anim.nFrames; + this->nCurFrame = anim.nCurFrame; +} + +void hgeAnimation::SetMode(int mode) +{ + Mode=mode; + + if(mode & HGEANIM_REV) + { + nDelta = -1; + SetFrame(nFrames-1); + } + else + { + nDelta = 1; + SetFrame(0); + } +} + + +void hgeAnimation::Play() +{ + bPlaying=true; + fSinceLastFrame=-1.0f; + if(Mode & HGEANIM_REV) + { + nDelta = -1; + SetFrame(nFrames-1); + } + else + { + nDelta = 1; + SetFrame(0); + } +} + + +void hgeAnimation::Update(float fDeltaTime) +{ + if(!bPlaying) return; + + if(fSinceLastFrame == -1.0f) + fSinceLastFrame=0.0f; + else + fSinceLastFrame += fDeltaTime; + + while(fSinceLastFrame >= fSpeed) + { + fSinceLastFrame -= fSpeed; + + if(nCurFrame + nDelta == nFrames) + { + switch(Mode) + { + case HGEANIM_FWD: + case HGEANIM_REV | HGEANIM_PINGPONG: + bPlaying = false; + break; + + case HGEANIM_FWD | HGEANIM_PINGPONG: + case HGEANIM_FWD | HGEANIM_PINGPONG | HGEANIM_LOOP: + case HGEANIM_REV | HGEANIM_PINGPONG | HGEANIM_LOOP: + nDelta = -nDelta; + break; + } + } + else if(nCurFrame + nDelta < 0) + { + switch(Mode) + { + case HGEANIM_REV: + case HGEANIM_FWD | HGEANIM_PINGPONG: + bPlaying = false; + break; + + case HGEANIM_REV | HGEANIM_PINGPONG: + case HGEANIM_REV | HGEANIM_PINGPONG | HGEANIM_LOOP: + case HGEANIM_FWD | HGEANIM_PINGPONG | HGEANIM_LOOP: + nDelta = -nDelta; + break; + } + } + + if(bPlaying) SetFrame(nCurFrame+nDelta); + } +} + +void hgeAnimation::SetFrame(int n) +{ + float tx1, ty1, tx2, ty2; + bool bX, bY, bHS; + int ncols = int(orig_width) / int(width); + + + n = n % nFrames; + if(n < 0) n = nFrames + n; + nCurFrame = n; + + // calculate texture coords for frame n + ty1 = ty; + tx1 = tx + n*width; + + if(tx1 > orig_width-width) + { + n -= int(orig_width-tx) / int(width); + tx1 = width * (n%ncols); + ty1 += height * (1 + n/ncols); + } + + tx2 = tx1 + width; + ty2 = ty1 + height; + + tx1 /= tex_width; + ty1 /= tex_height; + tx2 /= tex_width; + ty2 /= tex_height; + + quad.v[0].tx=tx1; quad.v[0].ty=ty1; + quad.v[1].tx=tx2; quad.v[1].ty=ty1; + quad.v[2].tx=tx2; quad.v[2].ty=ty2; + quad.v[3].tx=tx1; quad.v[3].ty=ty2; + + bX=bXFlip; bY=bYFlip; bHS=bHSFlip; + bXFlip=false; bYFlip=false; + SetFlip(bX,bY,bHS); +} + |