Exemplo n.º 1
0
static void flyToTarget()
{
	if (self->x == self->targetX || self->dirX == 0)
	{
		changeTarget(NULL);
	}

	self->face = (self->dirX > 0 ? RIGHT : LEFT);

	self->thinkTime += 5;

	self->dirY = cos(DEG_TO_RAD(self->thinkTime));

	if (abs(self->x - self->targetX) > self->speed)
	{
		self->dirX = (self->x < self->targetX ? self->speed : -self->speed);
	}

	else
	{
		self->x = self->targetX;

		self->dirX = 0;
	}

	checkToMap(self);
}
Exemplo n.º 2
0
void ComponentAIBomber::onMessage(const Message& message)
{
	std::list<GameObject*>::iterator it;
	switch (message.type)
	{
	case Message::NEW_VISION:
		addObject(message.gameObject);
		break;
	case Message::LOST_VISION:
		deleteObject(message.gameObject);
		break;
	case Message::TARGET_REACHED:
		changeTarget(false);
		break;
	case Message::DEATH:
		for (it=defenders.begin(); it!=defenders.end(); ++it)
		{
			(*it)->kill();
		}
		break;
	case Message::START_SHOOTING:
		charging = true;
		break;
	case Message::STOP_SHOOTING:
		charging = false;
		break;
	}
}
Exemplo n.º 3
0
bool EnemyShip::Update(const float& dt, bool& warp, ParticleSystem& Psystem, BulletSystem& Bsystem, Spaceship* target)
{
	changeTarget(target);
	turret.update(dt, shipPosition, Bsystem, (rand.RandomFloat() > 0.8));
	outofBoundsCheck(Psystem, warp);
	changeVelocity(dt, Psystem);
	shipPosition = shipPosition + velocity;
	return (life > 0);
}
void EnemyAIBase::tergetMotion(int _add_count)
{
	terget_change_count++;
	if (terget_change_count > _add_count
		&& aiterget.distanceSquared(enemy->transform.position.xy()) < 1) {
		terget_change_count = 0;
		changeTarget();

	}
}
Exemplo n.º 5
0
void ComponentSteering::onMessage(const Message& message)
{
	switch (message.type)
	{
	case Message::NEW_TARGET:
		changeTarget(message.target);
		break;
	case Message::NEW_FORCE:
		addForce(message.target);
		break;
	}
}
Exemplo n.º 6
0
AITutorial::AITutorial(CharaBase* _enemy, CharaBase* _player):
	EnemyAIBase(_enemy, _player)
{

	changeTarget();
	/*enemy->transform.position.x = -3;
	enemy->transform.position.y = -3;
	*/
	enemy->setPosition(aiterget);


}
Exemplo n.º 7
0
void ComponentAIBomber::update()
{
	GameObject::removeDeadOnesFromList(onVisionList);
	GameObject::removeDeadOnesFromList(defenders);

	if(!parent->isDead())
	{

		if( state == EnemyState::ATTACK && distanceFromThePath() > 60 )
		{

			watching = false;
			shooting = false;		
			target=NULL;
			selectedTarget = false;
			messageStopAIM();
			state = EnemyState::RETURN;
		}


		//Comprueba que pases cerca del punto final del camino y si cambia el camino
		if(parent->position.getDistanceFrom(path->getEnd()) < 30 && state != EnemyState::ATTACK)
		{
			messageStopAIM();
			changeTarget(true);
		}

		switch (state)
		{
		case ATTACK:
			updateAttack();
			break;
		case MOVE:
			updateMove();
			break;
		case RETURN:
			updateReturn();
			break;
		default:
			break;
		}
	} 
	else
	{
		std::list<GameObject*>::iterator it;
		for (it=defenders.begin(); it!=defenders.end(); ++it)
		{
			(*it)->kill();
		}
	}
}
Exemplo n.º 8
0
AILevel2::AILevel2(CharaBase* _enemy, CharaBase* _player) :
	EnemyAIBase(_enemy, _player)
{
	enemy->transform.position.x = -3;
	enemy->transform.position.y = 3;
	enemy->setPosition(enemy->transform.position.xy());
	c_Easing::apply(enemy->transform.position.z,
		100, EasingFunction::CircOut, 50);
	c_Easing::apply(enemy->transform.position.z,
		200, EasingFunction::ExpoIn, 50);
	c_Easing::stop(enemy->transform.position.z);
	changeTarget();

	roll_count = 2;
}
Exemplo n.º 9
0
AILevel1::AILevel1(CharaBase* _enemy, CharaBase* _player) :
	EnemyAIBase(_enemy, _player)
{


	enemy->transform.position.x = 3;
	enemy->transform.position.y = 3;
	enemy->setPosition(enemy->transform.position.xy());

	c_Easing::apply(enemy->transform.position.z,
		100, EasingFunction::CircOut, 50);
	c_Easing::apply(enemy->transform.position.z,
		150, EasingFunction::CubicIn, 50);
	c_Easing::stop(enemy->transform.position.z);
	terget_change_count = 0;
	changeTarget();

}
Exemplo n.º 10
0
bool EnemyShip::Update(const float& dt, bool& warp, ParticleSystem& Psystem, BulletSystem& Bsystem, Spaceship* target, Walls& walls)
{
	changeTarget(target);
	turret.update(dt, shipPosition, Bsystem, (rand.RandomFloat() < 0.1));
	outofBoundsCheck(Psystem, warp);
	changeVelocity(dt, Psystem);

	Vector2 collision = walls.getCollisionVelocity(shipPosition, velocity);

	if (Engine::LengthSquared(collision) != 0)
	{
		Psystem.AddParticle(new COLLISIONPARTICLE);
	}

	velocity = velocity + collision;
	shipPosition = shipPosition + velocity;
	return (life > 0);
}
Exemplo n.º 11
0
void updateProjectile(Projectile* p)
{
	
	
	if ( (p->target== NULL) || (getCoordsDistance(p->position, p->target->position) < 0.2) || p->target->hp <=0 )
	{	

		
		
		changeTarget(p,NULL,&(p->origin));
	}
	else{
		Coord move;
		directionTotarget(p);
		move = multipliedCoord(&(p->direction), 0.3);
		addCoords(&(p->position), &move);
	}

}
Exemplo n.º 12
0
void setTargetPosition(motorGroup *group, int position, bool resetIntegral=true) {
	changeTarget(group->posPID, position, resetIntegral);
	group->moving = TARGET;
}