www.pudn.com > sxdl.zip > cRocket.cpp


#include "cRocket.h" 
#include "cBoomBastic.h" 
#include "bbUtil.h" 
#include "cParticle.h" 
 
#define ROCKET_SPEED 400.0f 
#define ROCKET_SIZE 26.0f 
 
cRocket::cRocket(Vector3 p_Position, int Direction, int Power, int p_OwnerID) : 
	cExplosiveDevice(Power) 
{ 
	Position = p_Position; 
	OwnerID = p_OwnerID; 
	Velocity = Vector3(0.0f, 0.0f, 0.0f); 
		 
	Scale = Vector3( ROCKET_SIZE, ROCKET_SIZE, 1.0f); 
	//On choisit les angles, le vecteur direction et le scaling en focntion de la direction donnee  
	switch(Direction) 
	{ 
	default: 
	case LEFT_DIRECTION: 
		Velocity.x = -1.0f ; 
		Angles = Vector3(0.0f, 0.0f, Pi ); 
		break; 
		 
	case RIGHT_DIRECTION: 
		Velocity.x = 1.0f ; 
		Angles = Vector3(0.0f, 0.0f, 0.0f); 
		break; 
		 
	case UP_DIRECTION: 
		Velocity.y = 1.0f ; 
		Angles = Vector3(0.0f, 0.0f, Pi / 2.0f); 
		break; 
		 
	case DOWN_DIRECTION: 
		Velocity.y = -1.0f ; 
		Angles = Vector3(0.0f, 0.0f, -Pi / 2.0f); 
		break; 
	} 
	 
	Velocity *= ROCKET_SPEED ; 
	 
	Family = ROCKET_ID ; 
	 
	WillRenderLike(g_BoomBastic.EntitySprites[ROCKET_SPRITE]); 
	Activate(); 
} 
 
bool cRocket::OnAnimate(float ElapsedTime, float AbsoluteTime) 
{ 
	cExplosiveDevice::OnAnimate(ElapsedTime, AbsoluteTime); 
	 
	 
	int RocketX, RocketY; 
	if (g_BoomBastic.Tilemap->ConvertWorldToMap(Position, &RocketX, &RocketY)) 
	{ 
		//Si le missile est sur une tile bloquante, on le fait exploser sur la tile qui se trouve juste avant 
		if (g_BoomBastic.Tilemap->IsBlocking(RocketX, RocketY)) 
		{ 
			Position -= Velocity / ROCKET_SPEED * TILE_SIZE; 
			Explode(); 
		} 
	} 
	//Si le missile est hors de la map, on le fait exploser sur la tile qui se trouve juste avant 
	else 
	{ 
		Position -= Velocity / ROCKET_SPEED * TILE_SIZE; 
		Explode(); 
	} 
	 
	 
	//On cree une particule pour creer la flamme et la fumee du missile 
	new cParticle(Position, Velocity / ROCKET_SPEED, 1.0f, 0.0f, 14.0f, g_BoomBastic.Particles[ROCKET_PARTICLE]); 
	 
	return true; 
}