示例#1
0
 public override bool Control( GameEntity control, TimeSpan gameTime, Microsoft.Xna.Framework.Input.KeyboardState keyState )
 {
     if ( control is Projectile )
     {
         HashSet<Tank> tanks = new HashSet<Tank>();
         if ( control.Variables.ContainsKey( "Hypnotize" ) )
         {
             tanks = ( ( HashSet<Tank> )control.Variables[ "Hypnotize" ] );
         }
         if ( Vector2.Distance( control.Position, Owner.Position ) < rad )// && !Tools.IsGoingTowardsMe( Owner.Position, control.Angle, control.Position ) )
         {
             if ( !control.Variables.ContainsKey( "Hypnotize" ) || !tanks.Contains( Owner ) )
             {
                 DeflectorController d = new DeflectorController( Tools.Angle( Owner.Position, control.Position ) );
                 control.AppendController( d );
                 tanks.Add( Owner );
             }
         }
         else
         {
             tanks.Remove( Owner );
         }
         control.Variables[ "Hypnotize" ] = tanks;
     }
     return base.Control( control, gameTime, keyState );
 }
示例#2
0
 public override void InstantControl( GameEntity control, TimeSpan gameTime )
 {
     float closestDistance = -1; // The distance to the closest tank
     Tank closestTank = null; // The closest tank
     // Find the closest living tank
     foreach ( Tank t in Tanks )
     {
         float dist = Vector2.DistanceSquared( Owner.Position, t.Position );
         if ( t.IsAlive )
         {
             if ( ( closestTank == null || dist < closestDistance ) )
             {
                 closestDistance = dist;
                 closestTank = t;
             }
         }
     }
     if ( closestTank != null ) // If no tank is alive don't do anything
     {
         // Set owner's angle
         float ang = Tools.Angle( control.Position, closestTank.Position );
         DeflectorController c = new DeflectorController( ang );
         control.AppendController( c );
     }
 }