Ejemplo n.º 1
0
        public Boolean IsPointedAt(Vector2 target, float errorDistance)
        {
            Vector2 worldPosition    = this.WorldPosition();
            float   angle            = Vector2Utils.ShortestAngleDistance(Vector2Utils.Vector2Angle(target - worldPosition), this.WorldDirection());
            float   distanceToTarget = Vector2.Distance(target, worldPosition);

            return(Math.Abs(angle) <= Math.PI / 2 && Math.Abs((float)(Math.Sin(angle) * distanceToTarget)) < errorDistance);
        }
Ejemplo n.º 2
0
            public override void Handle(Microsoft.Xna.Framework.GameTime elapsedTime)
            {
                base.Handle(elapsedTime);
                if (Vector2Utils.ShortestAngleDistance(obj.Direction, Vector2Utils.Vector2Angle(followObj.Position - obj.Position)) < (Math.PI / 20))
                {
                    if (!fire)
                    {
                        //((NPCShip)obj).FireCoaxialWeapon();
                        //fire = true;
                    }
                }

                // Switch states if we are too close for engagement.
                if ((followObj.Position - obj.Position).Length() < 500)
                {
                    // TODO: Dangerous convert...fix this
                    this.Context.AddState(new ClearTargetState((NPCBasicAttackStrategy)this.Context, (NPCShip)this.obj, this.followObj));
                    this.Context.RemoveState(this);
                }
            }