Exemple #1
0
func FxMoveToTimer(object target, proplist fx, int time)
{
	if(!master)
	{
		KillBall();
		return;
	}
		
	if(GetEffect("Blocked", this))
	{
		ox=GetX();
		oy=GetY();
		return;
	}
	
	DrawParticleLine("Flash", 0, 0, ox-GetX(), oy-GetY(), 1, 0, 0, 15, movetrailparticles);

	if(time%7 == 0)
	{
		for(var i = 0; i < 360; i+=5)
		{
			CreateParticle("Flash", Sin(i, 3), -Cos(i, 5), 0, 0, 10, moveparticle2, 2);
		}
	}

	MoveToPos(fx.x, fx.y);
	
	ox=GetX();
	oy=GetY();
	
	var dst = Distance(GetX(), GetY(), fx.x, fx.y);
	if(dst < 5)
	{
		SetXDir(0);
		SetYDir(0);
		CheckForEnemies(AttackSize);
		Idle();
		
		CreateParticle("StarSpark", 0, 0, 0, 0, 10, moveparticle, 5);
		
		return -1;
	}
}
Exemple #2
0
func FxHomeCallTimer(object target, proplist fx, int time)
{
	if(!master)
	{
		KillBall();
		return -1;
	}	
	
	if(GetEffect("Blocked", this))
	{
		ox=GetX();
		oy=GetY();
		return;
	}
	
	DrawParticleLine("Flash", 0, 0, ox-GetX(), oy-GetY(), 1, 0, 0, 15, hometrailparticles);
	
	if(time%7 == 0)
	{
		for(var i = 0; i < 360; i+=5)
		{
			CreateParticle("Flash", Sin(i, 3), -Cos(i, 5), 0, 0, 10, hometrailparticles2, 2);
		}
	}

	fx.x = master->GetX();
	fx.y = master->GetY();
	var angle = Angle(GetX(), GetY(), fx.x, fx.y, 10);
	var txdir = Sin(angle, Speed + 12, 10);
	var tydir = -Cos(angle, Speed + 12, 10);
	SetXDir((GetXDir() + (txdir - GetXDir())/2));
	SetYDir((GetYDir() + (tydir - GetYDir())/2));
	
	CheckForEnemies(HomeCallSize);
	
	ox=GetX();
	oy=GetY();
	
	var dst = Distance(GetX(), GetY(), fx.x, fx.y);
	if(dst < 8)
	{
		AddShield(master);
		Sound("Ball::ball_shield", false, 20);
		
		var particles =
		{
			Prototype = Particles_Glimmer(),
			R = pR,
			G = pG,
			B = pB,
			Alpha = 255,
			Size = PV_Linear(10, 0),
			OnCollision = PC_Bounce(),
		};
		CreateParticle("StarSpark", 0, 0, PV_Random(-60,60), PV_Random(-60, 60), 25, particles, 5);
		
		var particle =
		{
			Alpha = PV_Linear(255, 0),
			Size = 50,
			R = pR,
			G = pG,
			B = pB,
			BlitMode = GFX_BLIT_Additive,
		};
		master->CreateParticle("StarSpark", 0, 0, 0, 0, 7, particle, 4);
		
		FollowMaster();
		return -1;
	}
}
Exemple #3
0
bool Bot::FixedUpdate()
{
	bool ret = true;
	switch (state)
	{
 	case BotState::idle:
		LOG("IDLE STATE");

		// Check if the Unit is a player Unit
		if (unit->team == App->AI->playerTeam)
		{
			if (unit->ArrivedToDestination())
				CheckForEnemies();
		}

		else
		{
			CheckForEnemies();
		}
		break;

	case BotState::attack:
		LOG("ATTACK STATE");
		if (App->AI->botList.find(target) != -1)
		{
			//If this Unit Evades when low life, Set the state to flee
			if (flees)
			{
				if (unit->GetHP() < unit->GetMaxHP() / 4) //flee when less than 10% health
				{
						SetState(flee);
						break;
				}
			}
			//Check if target is on the Attack Range
			if (EnemyOnRange(target->unit, unit, attackRange))
			{
				//TODO: 3 - Attack target
				if (!unit->ArrivedToDestination())
					unit->Stop();
				//Attack Unit 
				//Attack according to attackspeed
				if (attackTimer.ReadSec() >= attackSpeed)
				{
					attackTimer.Start();
					target->OnAttack(damage, this);
				}
			}
			//If is not on the attack range, chase him
			else if (unit->team == App->AI->playerTeam || father != NULL || EnemyOnRange(target->unit, unit, sightRange))
			{
				//TODO: 2 - Chase target

				// Compare target position with unit position 
				if (targetPos != target->GetPos() || unit->isTargetReached())
				{
					C_DynArray<iPoint> newPath;
					fPoint unitPos = unit->GetPosition();
					fPoint targetPos = target->unit->GetPosition();
					iPoint unitTile = App->map->WorldToMap(round(unitPos.x), round(unitPos.y));
					iPoint enemyTile = App->map->WorldToMap(round(targetPos.x), round(targetPos.y));
					App->pathFinding->GetNewPath(unitTile, enemyTile, newPath);
					unit->SetNewPath(newPath);
				}
			}
			else
			{
				SetState(idle);
			}
		}
		else
		{
			SetState(idle);
		}

		break;

	case BotState::flee:
		LOG("FLEE STATE");
		if (unit->ArrivedToDestination())
		{
			if (DistanceBetweenUnits(target->unit, unit) < sightRange * 1.5f)
			{ 
				// flees in random direction
				int x = (rand() % 60) + unit->GetPosition().x;
				int y = (rand() % 60) + unit->GetPosition().y;

				C_DynArray<iPoint> newPath;
				fPoint unitPos = unit->GetPosition();
				iPoint unitTile = App->map->WorldToMap(round(unitPos.x), round(unitPos.y));
				App->pathFinding->GetNewPath(unitTile, { x, y }, newPath);
				unit->SetNewPath(newPath);
			}
			else
			{
				SetState(idle);
			}
		}
		
		break;
	}
	return ret;
}