Sprite.cpp
上传用户:hkb425
上传日期:2007-06-16
资源大小:34191k
文件大小:5k
- // Sprite.cpp: implementation of the CSprite class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Sprite.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CSprite::CSprite()
- {
- m_RunSpeed=0.1f;
- m_bHasWeapon=false;
- m_startFrame=0;
- m_endFrame=1;
- m_percent=0;
- m_Health=1.5f;
- }
- CSprite::~CSprite()
- {
- }
- bool CSprite::InitSprite(int id,VERTEX startPos,float rotY,int totalFrames,
- float height,BOUNDARY_3D boundary,bool bControlled)
- {
- m_nID=id;
- m_nFrames=totalFrames;
- m_height=height;
- m_bControlled =bControlled;
- m_Boundary=boundary;
- /*
- if(!m_cAmmoManger.InitAmmoManager())
- {
- MessageBox(0, "cMD2 error", "Error", MB_OK | MB_ICONERROR);
- return FALSE;
- }*/
- m_Camera.UpdateCamera(startPos,0,rotY,0);
- m_nState=1-rand()%2;
- SetSpriteState(m_nState);
- return true;
- }
- void CSprite::ResetSpriteState(VERTEX resetPos,float rotY,int state)
- {
- m_nState=state;
- m_Camera.UpdateCamera(resetPos,0,rotY,0);
- }
- void CSprite::DrawSprite()
- {
- }
- void CSprite::UpdateSprite()
- {
- if(m_nState==0)m_percent+=0.125f;
- else m_percent+=0.25f;
- if(m_percent>1)
- {
- m_percent=0;
- m_startFrame++;
- m_endFrame++;
- if(m_startFrame>m_stateEnd)
- {
- m_startFrame = m_stateStart;
- }
- if(m_endFrame>m_stateEnd)
- {
- m_endFrame = m_stateStart;
- }
- }
- ///////////////////////////////
- if(m_nState==RUN && m_Camera.m_CamPos.xpos<2100 && m_Camera.m_CamPos.zpos<3000 )
- {
- m_Camera.m_CamPos.xpos+=m_Camera.m_CamDirection.nx*0.4f;
- m_Camera.m_CamPos.zpos+=m_Camera.m_CamDirection.nz*0.4f;
- m_Camera.m_CamPos.ypos=m_cHmap.GetHeight(&m_Camera.m_CamPos)+m_height*0.5f;
- }
- CheckSunVisible();
- }
- /////////////////////////////////////////
- void CSprite::SetSpriteState(int state)
- {
- switch(state)
- {
- case IDLE1:
- m_stateStart = IDLE1_START;
- m_stateEnd = IDLE1_END;
- CheckState();
- break;
- case RUN:
- m_stateStart = RUN_START;
- m_stateEnd = RUN_END;
- CheckState();
- break;
- case SHOT_STAND:
- m_stateStart = SHOT_STAND_START;
- m_stateEnd = SHOT_STAND_END;
- CheckState();
- break;
- case SHOT_SHOULDER:
- m_stateStart = SHOT_SHOULDER_START;
- m_stateEnd = SHOT_SHOULDER_END;
- CheckState();
- break;
- case JUMP:
- m_stateStart = JUMP_START;
- m_stateEnd = JUMP_END;
- CheckState();
- break;
- case IDLE2:
- m_stateStart = IDLE2_START;
- m_stateEnd = IDLE2_END;
- CheckState();
- break;
- case SHOT_FALLDOWN:
- m_stateStart = SHOT_FALLDOWN_START;
- m_stateEnd = SHOT_FALLDOWN_END;
- CheckState();
- break;
- case IDLE3:
- m_stateStart = IDLE3_START;
- m_stateEnd = IDLE3_END;
- CheckState();
- break;
- case IDLE4:
- m_stateStart = IDLE4_START;
- m_stateEnd = IDLE4_END;
- CheckState();
- break;
- case CROUCH:
- m_stateStart = CROUCH_START;
- m_stateEnd = CROUCH_END;
- CheckState();
- break;
- case CROUCH_CRAWL:
- m_stateStart = CROUCH_CRAWL_START;
- m_stateEnd = CROUCH_CRAWL_END;
- CheckState();
- break;
- case CROUCH_IDLE:
- m_stateStart = CROUCH_IDLE_START;
- m_stateEnd = CROUCH_IDLE_END;
- CheckState();
- break;
- case CROUCH_DEATH:
- m_stateStart = CROUCH_DEATH_START;
- m_stateEnd = CROUCH_DEATH_END;
- CheckState();
- break;
- case DEATH_FALLBACK:
- m_stateStart = DEATH_FALLBACK_START;
- m_stateEnd = DEATH_FALLBACK_END;
- CheckState();
- break;
- case DEATH_FALLFORWARD:
- m_stateStart = DEATH_FALLFORWARD_START;
- m_stateEnd = DEATH_FALLFORWARD_END;
- CheckState();
- break;
- case DEATH_FALLBACKSLOW:
- m_stateStart = DEATH_FALLBACKSLOW_START;
- m_stateEnd = DEATH_FALLBACKSLOW_END;
- CheckState();
- break;
- }
- }
- void CSprite::CheckState()
- {
- m_startFrame = m_stateStart+rand()%5;
- m_endFrame = m_startFrame+1 ;
- if(m_stateEnd>(m_nFrames-1))
- {
- m_stateStart=IDLE1_START;
- m_stateEnd =IDLE1_END;
- m_startFrame=0;
- m_endFrame =1;
- }
- }
- void CSprite::CheckSunVisible()
- {
- if(!m_cHmap.m_bSunVisible)return;
- BOUNDARY_3D boundary;
- VERTEX position=m_Camera.m_CamPos;
- boundary.minx = m_Boundary.minx+position.xpos;
- boundary.maxx = m_Boundary.maxx+position.xpos;
- boundary.miny = m_Boundary.miny+position.ypos + m_height*0.5f;
- boundary.maxy = m_Boundary.maxy+position.ypos + m_height*0.5f;
- boundary.minz = m_Boundary.minz+position.zpos;
- boundary.maxz = m_Boundary.maxz+position.zpos;
- if(m_cMath.IsLineSegmentCutBy3DBoundary(*m_cHmap.m_pViewPos ,
- *m_cHmap.m_pSunPos,
- boundary))
- m_cHmap.m_bSunVisible=false;
- }