int timer = 0; //needs to be outside of advance() to work as a timer
int timer2 = (int) (600*Math.random()); //random start point for strafing
public void advance(float amount)
{
timer++;
if (MathUtils.getDistance(
add(target.getLocation(), target.getVelocity(), null), //blow up the enemy ship
add(missile.getLocation(), multV2f(missile.getVelocity(),3), null))
< 600
&& MathUtils.getDistance(
missile.getLocation(), //don't blow up your own ship
missile.getSource().getLocation())
>missile.getSource().getCollisionRadius()+5
&& timer==1
)
{
timer++;
CombatEngine engine = CombatEngine.getInstance(); //engine
String MBRC_p = "MBRC2"; //dummy weapon
{
{
int counts = 1;
do {
float angRAND= (float) ((25*(.5-Math.random()))); //angle of spread
float velRAND= (float) (1+.5*(.5-Math.random())); //variance of projectile speeds
float splashVEL = 255f*velRAND; //speed of bullets launched
float misFFACE = missile.getFacing()-angRAND;
float x = (float) (splashVEL*Math.cos(Math.toRadians(misFFACE)));
float y = (float) (splashVEL*Math.sin(Math.toRadians(misFFACE)));
Vector2f vecFIRE = new Vector2f(x,y);
engine.spawnProjectile(null, null,MBRC_p,
missile.getLocation(), //Vector2f firing point
misFFACE, //float angle of spread
add(missile.getVelocity(), vecFIRE, null)
//multV2f(multV2f(missile.getVelocity(),1),velRAND) //Vector2f aditional velocity
//add(multV2f(missile.getVelocity(), 1), multRanV2f(missile.getVelocity(),1,.5f),null)
);
counts++;
}while (counts<2); //2x pew pew
//engine.removeEntity(missile); //make missile go poof
}
//lightning
// float emp = missile.getEmpAmount();
//float dam = missile.getDamageAmount();
//engine.spawnEmpArc(missile.getSource(), missile.getLocation(), target, target,
// DamageType.ENERGY,dam/4, emp/4,
//10000f, "tachyon_lance_emp_impact",20f, new Color(255,10,15,255),new Color(255,100,100,255));
}
//to stop missile shooting again
//engine.removeEntity(missile); //make missile go poof
//missile.flameOut(); //make missile flame out
return;
}
if (timer>40)
{timer=0;}
//missile pathing code
if (Math.abs(angularDistance) < 100 //get in close
&& MathUtils.getDistance(missile.getLocation(), target.getLocation())
>320+100/target.getCollisionRadius()*target.getCollisionRadius())
{
missile.giveCommand(ShipCommand.ACCELERATE);
}
if (Math.abs(angularDistance) < 100 //keep distance
&& MathUtils.getDistance(missile.getLocation(), target.getLocation())
<280+100/target.getCollisionRadius()*target.getCollisionRadius())
{
missile.giveCommand(ShipCommand.ACCELERATE_BACKWARDS);
}
if (Math.abs(angularDistance) < 100 //strafe
&& MathUtils.getDistance(missile.getLocation(), target.getLocation())<400+target.getCollisionRadius())
{
missile.giveCommand(timer2 > 300 ? ShipCommand.STRAFE_LEFT : ShipCommand.STRAFE_RIGHT);
}
timer2++;
if (timer2>600)
{
timer2=0;
}
}