object.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:16k
- #include "global.h"
- #include "object.h"
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- CObject::CObject() {
- m_dwObjType = OBJTYPE_NONE;
- m_dwObjStat = OBJSTAT_UNUSED;
- m_nStatCounter = 0;
- m_nWidth = 0;
- m_nHeight = 0;
- m_nLeft = 0;
- m_nTop = 0;
-
- m_dwFrameType = 0;
- m_nTotalFrame = 0;
- m_nCurrentFrame = 0;
- m_dwPersistTime = 0;
- m_dwLastTime = 0;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- CObject::~CObject() {
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- RECT CObject::GetRect() {
- RECT rc;
- SetRect( &rc, m_nLeft, m_nTop, m_nLeft+m_nWidth, m_nTop+m_nHeight );
- return rc;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- void CObject::NextFrame( DWORD nowtime ) {
- if ( nowtime > m_dwPersistTime + m_dwLastTime ) {
- INCSCOPE( m_nCurrentFrame, 0, m_nTotalFrame );
- m_dwLastTime = nowtime;
- }
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- CMobileObject::CMobileObject() {
- m_uiDirection = DIR_NONE;
- m_nMoveStep = 0;
- m_uiTeamType = TEAM_NEUTRAL;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- CMobileObject::~CMobileObject() {
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- RECT CMobileObject::GetNextRect() {
- RECT rc = this->GetRect();
- POINT pt = this->GetDirectionUnit();
- rc.left = m_nLeft + m_nMoveStep * pt.x;
- rc.top = m_nTop + m_nMoveStep * pt.y;
- rc.right = rc.left + m_nWidth;
- rc.bottom = rc.top + m_nHeight;
- return rc;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- RECT CMobileObject::GetNextRectStep( int step ) {
- RECT rc = this->GetRect();
- POINT pt = this->GetDirectionUnit();
- rc.left = m_nLeft + step * pt.x;
- rc.top = m_nTop + step * pt.y;
- rc.right = rc.left + m_nWidth;
- rc.bottom = rc.top + m_nHeight;
- return rc;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- POINT CMobileObject::GetDirectionUnit() {
- POINT pt = {0,0};
- if ( m_uiDirection == DIR_RIGHT ) // right
- pt.x = 1;
- else if ( m_uiDirection == DIR_LEFT ) // left
- pt.x = -1;
- else if ( m_uiDirection == DIR_UP ) // up
- pt.y = -1;
- else if ( m_uiDirection == DIR_DOWN ) // down
- pt.y = 1;
-
- return pt;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- CObjTank::CObjTank() {
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- CObjTank::~CObjTank() {
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- void CObjTank::CreateTank( int left, int top, bool bHome ) {
- m_dwObjType = OBJTYPE_TANK;
- m_dwObjStat = OBJSTAT_LIVE;
- m_dwEquip = 0;
- m_nWidth = 32;
- m_nHeight = 32;
- m_nLeft = left;
- m_nTop = top;
-
- m_dwFrameType = LOC_OBJECT_TANK0;
- m_nTotalFrame = 2;
- m_nCurrentFrame = 0;
- m_dwPersistTime = 0;
- m_uiDirection = DIR_UP;
- m_nMoveStep = DEFTANKSPEED;
- m_bMoving = false;
- m_bOnIce = false;
- m_nIceStep = 0;
- m_uiIceDir = DIR_NONE;
- m_nIndex = 0;
- m_bHome = bHome;
- if ( m_bHome )
- m_uiTeamType = TEAM_HOME;
- else
- m_uiTeamType = TEAM_ENEMY;
- m_bBoom = false;
- m_bHaveBullet = false;
- m_prtBlood.CreateProperty( 30, 50, 0 );
- m_nAttack = 10;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- void CObjTank::Hited( int attack ) {
- if ( !m_prtBlood.Minus( attack ) ) {
- m_nStatCounter = 2;
- m_dwObjStat = OBJSTAT_DIE;
- m_nTotalFrame = 2;
- m_nCurrentFrame = 0;
- // m_nPersistTime = 100;
- }
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- void CObjTank::NextStat() {
- if ( m_dwObjStat == OBJSTAT_DIE ) {
- if ( --m_nStatCounter == 0 )
- m_dwObjStat = OBJSTAT_CADAVER;
- }
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- RECT CObjTank::GetNextRectOnIce() {
- RECT rc = this->GetRect();
- POINT pt = this->GetDirUnitOnIce();
- rc.left = m_nLeft + m_nIceStep * pt.x;
- rc.top = m_nTop + m_nIceStep * pt.y;
- rc.right = rc.left + m_nWidth;
- rc.bottom = rc.top + m_nHeight;
- return rc;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- POINT CObjTank::GetDirUnitOnIce() {
- POINT pt = {0,0};
- if ( m_uiIceDir == DIR_RIGHT ) // right
- pt.x = 1;
- else if ( m_uiIceDir == DIR_LEFT ) // left
- pt.x = -1;
- else if ( m_uiIceDir == DIR_UP ) // up
- pt.y = -1;
- else if ( m_uiIceDir == DIR_DOWN ) // down
- pt.y = 1;
-
- return pt;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- CObjBullet::CObjBullet() {
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- CObjBullet::~CObjBullet() {
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- void CObjBullet::CreateBullet( CObjTank *ptk )
- {
- m_dwFrameType = 0;
- m_nTotalFrame = 1;
- m_nCurrentFrame = 0;
- m_dwPersistTime = 0;
- m_nMoveStep = DEFBULLETSPEED;
- if ( ptk && ( ptk->GetStat() & OBJSTAT_LIVE )) {
- m_dwObjStat = OBJSTAT_LIVE;
- m_nLeft = ptk->GetLeft()+8+(ptk->GetDirectionUnit().x)*8;
- m_nTop = ptk->GetTop()+8+(ptk->GetDirectionUnit().y)*8;
- m_uiDirection = ptk->m_uiDirection;
- m_bHome = ptk->IsHomeTeam();
- m_uiTeamType = ptk->m_uiTeamType;
- m_obkTank = ptk;
- ptk->SetBullet();
- m_nAttack = ptk->m_nAttack;
- }
- else {
- m_dwObjType = OBJTYPE_BULLET;
- m_nWidth = DEFBULLETWIDTH;
- m_nHeight = DEFBULLETHEIGHT;
- m_dwObjStat = OBJSTAT_CADAVER;
- m_nLeft = 0;
- m_nTop = 0;
- m_uiDirection = DIR_NONE;
- }
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- void CObjBullet::NextStat() {
- if ( m_dwObjStat & OBJSTAT_LIVE ) {
- m_nStatCounter = 2;
- m_dwObjStat = OBJSTAT_DIE;
- m_nTotalFrame = 2;
- m_nCurrentFrame = 0;
- // m_nPersistTime = 100;
- if ( m_obkTank->GetStat() & OBJSTAT_LIVE )
- m_obkTank->RemoveBullet();
- } else if ( m_dwObjStat == OBJSTAT_DIE ) {
- if ( --m_nStatCounter == 0 )
- m_dwObjStat = OBJSTAT_CADAVER;
- }
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- void CObjBullet::Hit( CObjTank *ptk ) {
- NextStat();
- ptk->Hited( GetAttack() );
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- void CObjBullet::Hit( CObjBullet *pblt ) {
- NextStat();
- pblt->NextStat();
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- CObjEffect::CObjEffect() {
- m_dwEffect = EFFECT_NONE;
- m_nAttack = 0;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- CObjEffect::~CObjEffect() {
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- void CObjEffect::CreateEffect( CObject *pobj ) {
- DWORD type = pobj->GetType();
- m_dwObjStat = OBJSTAT_LIVE;
- if ( type == OBJTYPE_TANK ) {
- m_dwEffect = EFFECT_TANKBOOM;
-
- m_dwObjType = OBJTYPE_EFFECT;
- m_nLeft = pobj->GetLeft();
- m_nTop = pobj->GetTop();
- m_nWidth = g_FrameSmall;
- m_nHeight = g_FrameSmall;
-
- m_nTotalFrame = 3;
- m_nCurrentFrame = 0;
- m_dwPersistTime = 100;
- }
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- CObjBase::CObjBase() {
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- CObjBase::~CObjBase() {
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- void CObjBase::CreateBase( int x, int y, bool bHome ) {
- m_bHome = bHome;
- if ( m_bHome )
- m_uiTeamType = TEAM_HOME;
- else
- m_uiTeamType = TEAM_ENEMY;
- m_dwObjType = OBJTYPE_BASE;
- m_dwObjStat = OBJSTAT_LIVE;
- m_nWidth = 32;
- m_nHeight = 32;
- m_nLeft = x;
- m_nTop = y;
- m_nMoveStep = 0;
- m_uiDirection = DIR_NONE;
- m_ptyBlood.CreateProperty( 40, 40, 0 );
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- RECT CObjBase::GetSurroundRect() {
- RECT rt = GetRect();
- rt.left -= 16;
- rt.right += 16;
- rt.top -= 16;
- rt.bottom += 16;
- if ( rt.top < 0 )
- rt.top = 0;
- if ( rt.bottom > g_FrameHeight )
- rt.bottom = g_FrameHeight;
- return rt;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- CObjBlock::CObjBlock() {
- m_nbx = -1;
- m_nby = -1;
- m_nLand = LAND_NONE;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- void CObjBlock::CreateObjBlock( int x, int y, int land )
- {
- m_nbx = x;
- m_nby = y;
- m_nLand = land;
- m_dwObjType = OBJTYPE_BLOCK;
- m_dwObjStat = OBJSTAT_LIVE;
- m_nTotalFrame = 3;
- m_nCurrentFrame = 0;
- m_dwPersistTime = 200;
- m_nWidth = 32;
- m_nHeight = 32;
- m_nLeft = x<<5;
- m_nTop = y<<5;
- }
-
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- CObjBlock::~CObjBlock() {
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- CObjFood::CObjFood() {
- m_dwObjType = OBJTYPE_FOOD;
- m_dwObjStat = OBJSTAT_LIVE;
- m_nTotalFrame = 0;
- m_nCurrentFrame = 0;
- m_dwPersistTime = 0;
- m_nWidth = 32;
- m_nHeight = 32;
- m_bPresent = false;
- m_bExsit = false;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- CObjFood::~CObjFood() {
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- void CObjFood::CreateFood( DWORD type, int left, int top ) {
- m_bExsit = true;
- m_bPresent = true;
- m_dwType = type;
- m_nLeft = left;
- m_nTop = top;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- RECT CObjFood::GetPermitRect() {
- RECT rc;
- SetRect( &rc, m_nLeft+8, m_nTop+8, m_nLeft+m_nWidth-8, m_nTop+m_nHeight-8 );
- return rc;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- void CObjFood::Benefit( CObjTank *ptk ) {
- switch ( m_dwType ) {
- case FOOD_SHIP:
- ptk->m_dwEquip |= EQUIP_SHIP;
- break;
- case FOOD_POWERUP:
- ptk->m_nAttack += 10;
- break;
- case FOOD_BLOODUP:
- ptk->m_prtBlood.Add(10);
- break;
- case FOOD_SPEEDUP:
- ptk->SetStep( MIN( ptk->GetStep()+2, MAXTANKSPEED ) );
- break;
- }
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- CProperty::CProperty() {
- m_nDefaultValue = 0;
- m_nCurrentValue = 0;
- m_nMaxValue = 0;
- m_nMinValue = 0;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- CProperty::~CProperty() {
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- void CProperty::CreateProperty( int def, int max, int min ) {
- m_nDefaultValue = def;
- m_nCurrentValue = def;
- m_nMaxValue = max;
- m_nMinValue = min;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- void CProperty::Add( int step ) {
- m_nCurrentValue += step;
- if ( m_nCurrentValue > m_nMaxValue )
- m_nCurrentValue = m_nMaxValue;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- bool CProperty::Minus( int step ) {
- m_nCurrentValue -= step;
- if ( m_nCurrentValue <= m_nMinValue ) {
- m_nCurrentValue = m_nMinValue;
- return false;
- }
- return true;
- }
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- // Name:
- // Desc:
- //-----------------------------------------------------------------------------