#include "bunny.h" Bunny::Bunny( char* texturefile, int numOfFrames, int cellWidth, int cellHeight, int numOfRows, int numOfColumns ) { _position = new D3DXVECTOR3(0, 0, 0); _velocity = new D3DXVECTOR3(0, 0, 0); _entType = tBunny; gpKexan->gpEBank->AddToEntityList( this, _entType ); // _texture = gpKexan->gpTBank->AddTexture( texturefile ); gpKexan->gpTBank->AddTexture( texturefile ); _texture = gpKexan->gpTBank->GetTexture( texturefile )->_texture; m_TotalFrames = numOfFrames; m_CurrentFrame = 0; m_CellWidth = cellWidth; m_CellHeight = cellHeight; m_NumOfRows = numOfRows; m_NumOfColumns = numOfColumns; tickCount = 0; m_IsShot = false; m_IsDead = false; m_IsJumping = false; m_DoneJumping = false; m_JumpValue = 25; } void Bunny::Update() { tickCount++; if( m_IsDead ) { return; } else if( m_IsShot && tickCount > 3 ) { m_CurrentFrame++; if( m_CurrentFrame == 8 ) { m_IsDead = true; } tickCount = 0; } BaseSprite::Update(); if( m_IsJumping ) { if( tickCount > 10 ) { SetPosition( GetPosition()->x - 30, GetPosition()->y - m_JumpValue ); m_JumpValue -= 5; if( m_DoneJumping ) { m_IsJumping = false; m_DoneJumping = false; m_CurrentFrame = 0; } if( m_JumpValue <= -25 ) { m_DoneJumping = true; m_CurrentFrame = 0; } tickCount = 0; } } if( !m_IsJumping ) { if( tickCount > 10 ) { switch( m_CurrentFrame ) { case 0: m_CurrentFrame++; tickCount = 0; break; case 1: m_CurrentFrame++; m_IsJumping = true; m_DoneJumping = false; m_JumpValue = 25; tickCount = 0; break; default: m_CurrentFrame = 0; break; } } } /*if( tickCount > 10 ) { m_CurrentFrame++; if( m_CurrentFrame >= 3 ) { m_CurrentFrame = 0; } tickCount = 0; }*/ } void Bunny::FireAtBunny( D3DXVECTOR3* bullet ) { if( m_IsShot || m_IsDead ) { return; } float dx, dy, distance; dx = this->GetPosition()->x - bullet->x; dy = this->GetPosition()->y - bullet->y; distance = sqrt( (dx * dx) + (dy * dy) ); if( distance < 50 ) { // Kill Bunny this->KillBunny(); return; } } void Bunny::KillBunny() { m_IsShot = true; m_CurrentFrame = 3; }