//Note that AISTATES are never directly part of lists, //and exist as fields of an AI. Thus, this will only // ever be called by its AI parent. public override void Update(GameTime gt) { if (Moving) { Body.Go(); if (MoveTarget != null) { if (!MoveTarget.IsDestroyed()) Body.SetHeading(PointAt(MoveTarget)); else MoveTarget = null; } } else Body.Stop(); if (Shooting) { Body.Shoot(); if (ShootTarget != null) { if (!ShootTarget.IsDestroyed()) Body.SetWeaponHeadings(PointAt(ShootTarget)); else ShootTarget = null; } } else Body.HoldFire(); }
public void SetMoveTarget(Target t) { if (MoveTarget == null) MoveTarget = t; }
public void SetShootTarget(Target t) { if (ShootTarget == null) ShootTarget = t; }
/* This method returns the apropriate heading for the * actor to "point" at the given target. */ private double PointAt(Target t) { var tp = t.GetPosition(); var bp = Body.GetPosition(); double dir = Math.Atan2(tp.Y - bp.Y, tp.X - bp.X); return dir; }