Example #1
0
        void UpdatePlayerMove()
        {
            if (ourPlayer == null) return;

            var isMoving = speed.X != 0 || speed.Y != 0;
            var angle = new Vector(speed.X, speed.Y).Angle;

            ourPlayer.SetMovement(isMoving, angle);
        }
Example #2
0
 public virtual void DeSerialize(BinaryReader r)
 {
     var x = r.ReadDouble();
     var y = r.ReadDouble();
     var d = r.ReadDouble();
     var m = r.ReadDouble();
     IsMoving = r.ReadBoolean();
     Position = new Vector(x,y);
     Direction = d;
     MoveSpeed = m;
 }
Example #3
0
 public RectangleF(double x, double y, double width, double height)
 {
     this.Position = new Vector(x, y);
     this.Size = new Vector(width, height);
 }
Example #4
0
 /// <summary>
 /// Returns whether the given point lies inside this rectangle. 
 /// </summary>
 public bool Contains(Vector p)
 {
     return Contains(p.X, p.Y);
 }
Example #5
0
 public void FireSpell(int id, Vector pos)
 {
     pendingSpellCasts.Enqueue(new Tuple<int, Vector>(id, pos));
 }
Example #6
0
 public RectangleF(Vector position, Vector size)
 {
     this.Position = position;
     this.Size = size;
 }
Example #7
0
 /// <summary>
 /// Clamps this vector's X and Y values between the X/Y values of the given vectors. 
 /// </summary>
 /// <param name="min">A vector with the minimum X and Y values the vector can take. </param>
 /// <param name="max">A vector with the maximum X and Y values the vector can take. </param>
 /// <returns></returns>
 public Vector Clamp(Vector min, Vector max)
 {
     return new Vector(
         Math.Min(max.x, Math.Max(min.x, x)),
         Math.Min(max.y, Math.Max(min.y, y)));
 }
Example #8
0
 /// <summary>
 /// Returns whether this point is inside the rectangle at the given position and size. 
 /// </summary>
 /// <param name="pos">The position of the bottom-left corner of the rectangle. </param>
 /// <param name="size">The size of the rectangle. </param>
 /// <returns>Whether this point is inside the rectangle. </returns>
 public bool Inside(Vector pos, Vector size)
 {
     return X >= pos.x && y >= pos.y && x <= pos.x + size.x && y <= pos.y + size.y;
 }
Example #9
0
 /// <summary>
 /// Returns the angle between this point and the given point. 
 /// </summary>
 public double AngleTo(Vector pos)
 {
     return Math.Atan2(pos.y - y, pos.x - x);
 }
Example #10
0
 /// <summary>
 /// Returns the distance between this point and the given point. 
 /// </summary>
 public double DistanceTo(Vector other)
 {
     return Math.Sqrt(DistanceToSquared(other));
 }
Example #11
0
        ///// <summary>
        ///// Uses raw conversion to <see cref="int"/> to convert this vector to a point. 
        ///// </summary>
        //public Point ToPoint()
        //{
        //    return new Point((int)x, (int)y);
        //}

        ///// <summary>
        ///// Uses <see cref="Math.Round(double)"/> to convert this vector to a point. 
        ///// </summary>
        //public Point Round()
        //{
        //    return new Point((int)Math.Round(x), (int)Math.Round(y));
        //}

        ///// <summary>
        ///// Uses <see cref="Math.Floor(double)"/> to convert this vector to a point. 
        ///// </summary>
        //public Point Floor()
        //{
        //    return new Point((int)Math.Floor(x), (int)Math.Floor(y));
        //}

        ///// <summary>
        ///// Uses <see cref="Math.Ceiling(double)"/> to convert this vector to a point. 
        ///// </summary>
        //public Point Ceiling()
        //{
        //    return new Point((int)Math.Ceiling(x), (int)Math.Ceiling(y));
        //}

        #endregion


        #region Binary ops

        /// <summary>
        /// Returns the squared distance between this point and the given point. 
        /// </summary>
        public double DistanceToSquared(Vector other)
        {
            var dx = X - other.X;
            var dy = Y - other.Y;
            return dx * dx + dy * dy;
        }