00001 00002 // 00003 // Das Tank - Copyright (C) 2006, 2007 Windsor Schmidt <windsor@windsorworld.net> 00004 // 00005 // This program is free software; you can redistribute it and/or modify it 00006 // under the terms of the GNU General Public License as published by the Free 00007 // Software Foundation; either version 2 of the License, or (at your option) 00008 // any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, but WITHOUT 00011 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00013 // more details. 00014 // 00015 // You should have received a copy of the GNU General Public License along with 00016 // this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00017 // Place, Suite 330, Boston, MA 02111-1307 USA 00018 // 00020 00021 00022 #ifndef STDAFX 00023 #include "stdafx.h" 00024 #endif 00025 00026 TileAnim::TileAnim(void) 00027 { 00028 vPosition.x = 0; 00029 vPosition.y = 0; 00030 vPosition.z = 0; 00031 fAngle = 0; 00032 iAnimation = ANIMID_NULL; 00033 fFrameDelay = 100; 00034 fFrameTimer = 0; 00035 iSetupTimer = 0; 00036 iSetupFrames = 0; 00037 iCurrentFrame = 0; 00038 iDuration = 1000; 00039 bOver = false; 00040 } 00041 00042 TileAnim::TileAnim(Vector vPos, float angle, float duration, int animID, float delay, int setup, bool over) 00043 { 00044 vPosition = vPos; 00045 fAngle = angle; 00046 iAnimation = animID; 00047 fFrameDelay = delay; 00048 fFrameTimer = 0; 00049 iSetupTimer = 0; 00050 iSetupFrames = setup; 00051 iCurrentFrame = 0; 00052 iDuration = duration; 00053 bOver = over; 00054 } 00055 00056 TileAnim::~TileAnim(void) 00057 { 00058 } 00059 00064 bool TileAnim::Step(float timeStep) 00065 { 00066 iDuration -= timeStep; 00067 if(iDuration <= 0) 00068 { 00069 return true; // expired 00070 } 00071 00072 fFrameTimer += timeStep; 00073 00074 if(fFrameTimer >= fFrameDelay) 00075 { 00076 fFrameTimer = 0; 00077 00078 if(iSetupTimer >= iSetupFrames) 00079 { 00080 iCurrentFrame++; 00081 } 00082 00083 iSetupTimer++; 00084 00085 if(iCurrentFrame == GetAnimation(iAnimation)->iTotalFrames) 00086 { 00087 iCurrentFrame = GetAnimation(iAnimation)->iTotalFrames - 1; 00088 } 00089 } 00090 return false; // not expired yet 00091 } 00092 00093 void TileAnim::Draw(void) 00094 { 00095 float alpha; 00096 00097 glEnable (GL_BLEND); 00098 glEnable(GL_TEXTURE_2D); 00099 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00100 00101 glPushMatrix(); // save matrix state 00102 glTranslatef(vPosition.x, vPosition.y, 0.0f); // position in WCS 00103 00104 if(iDuration <= TILEANIM_FADEOUT_TIME) // begin to fade out 00105 { 00106 alpha = iDuration / TILEANIM_FADEOUT_TIME; 00107 glColor4f(1.0,1.0,1.0,alpha); 00108 } 00109 else 00110 { 00111 glColor4f(1.0,1.0,1.0,1.0); 00112 } 00113 00114 glScalef(GetAnimation(iAnimation)->fScale, GetAnimation(iAnimation)->fScale, 1); 00115 glRotatef(fAngle,0,0,1); 00116 00117 if(bOver) 00118 { 00119 glTranslatef(0,0,0.2); 00120 } 00121 00122 glBindTexture( GL_TEXTURE_2D, GetFrame(iAnimation, iCurrentFrame)); 00123 glBegin(GL_QUADS); // start drawing a polygon (4 sided) 00124 glTexCoord2d(0.0,1.0); glVertex3f(-2.2, 2.4, 0.0f); // top left 00125 glTexCoord2d(1.0,1.0); glVertex3f(2.2, 2.4, 0.0f); // top right 00126 glTexCoord2d(1.0,0.0); glVertex3f(2.2, -2.4, 0.0f); // bottom right 00127 glTexCoord2d(0.0,0.0); glVertex3f(-2.2, -2.4, 0.0f); // bottom left 00128 glEnd(); // done with the polygon 00129 00130 glPopMatrix(); 00131 }
Copyright Windsor Schmidt 2006 - All rights reserved.