コード例 #1
0
        public void DrawLine(Vector2 point1, Vector2 point2, Color color, double depth)
        {
            Vector2 scale    = new Vector2((float)Math.Sqrt((point2 - point1).LengthSquared()), 1);
            float   rotation = (float)Vector2Utils.Vector2Angle(point2 - point1);

            spriteBatch.Draw(point, point1, null, color, rotation, new Vector2(0), scale, SpriteEffects.None, (float)depth);
        }
コード例 #2
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);
        }
コード例 #3
0
        public float GetClosestPointAtAngleInRange(Vector2 target)
        {
            PhysicalObject parent = ((PhysicalObject)(this.Parent));

            if (parent != null)
            {
                float worldDirection = Vector2Utils.Vector2Angle(target - this.WorldPosition());
                float targetAngleRelativeToParent = worldDirection - parent.WorldDirection() - this.DirectionRelativeToParent;
                return(MathUtils.ClosestInRange(Vector2Utils.MinimizeMagnitude(targetAngleRelativeToParent), this.Range, -this.Range));
            }
            else
            {
                return(0);
            }
        }
コード例 #4
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);
                }
            }