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); }
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; }
public RectangleF(double x, double y, double width, double height) { this.Position = new Vector(x, y); this.Size = new Vector(width, height); }
/// <summary> /// Returns whether the given point lies inside this rectangle. /// </summary> public bool Contains(Vector p) { return Contains(p.X, p.Y); }
public void FireSpell(int id, Vector pos) { pendingSpellCasts.Enqueue(new Tuple<int, Vector>(id, pos)); }
public RectangleF(Vector position, Vector size) { this.Position = position; this.Size = size; }
/// <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))); }
/// <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; }
/// <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); }
/// <summary> /// Returns the distance between this point and the given point. /// </summary> public double DistanceTo(Vector other) { return Math.Sqrt(DistanceToSquared(other)); }
///// <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; }