Пример #1
0
        /// <summary>Calculates the squared distance between two TilePos instances.</summary>
        /// <param name="value1">First TilePos.</param>
        /// <param name="value2">Second TilePos.</param>
        public static float DistanceSquared(TilePos value1, TilePos value2)
        {
            int num1 = value1.X - value2.X;
            int num2 = value1.Y - value2.Y;

            return(num1 * num1 + num2 * num2);
        }
Пример #2
0
        /// <summary>
        /// Returns a TilePos object corresponding to the specified co-ordinate
        /// </summary>
        /// <param name="position">The position within the world. For a GameObject, pass in the co-ordinates of the object's origin.</param>
        /// <returns>A TilePos that contains the specified co-ordinate</returns>
        public static TilePos TilePosFromPosition(Vector2 position)
        {
            var intX = (int)position.X / Constants.TileLength;
            var intY = (int)position.Y / Constants.TileLength;

            var result = new TilePos(intX, intY);

            return(result);
        }
Пример #3
0
        public bool Contains(TilePos tp)
        {
            var result =
                this.TopLeft.X <= tp.X &&
                tp.X < this.TopLeft.X + this.Width &&
                this.TopLeft.Y <= tp.Y &&
                tp.Y < this.TopLeft.Y + this.Height;

            return(result);
        }
Пример #4
0
        /// <summary>
        /// Returns a rectangle around this instance
        /// </summary>
        /// <param name="radius">The radius of tiles around this instance</param>
        /// <returns>A new TileRect structure with this TilePos instance at its centre</returns>
        public TileRect GetRectAroundPosition(int radius)
        {
            if (radius < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(radius));
            }
            var topLeft  = new TilePos(this.X - radius, this.Y - radius);
            var diameter = radius * 2 + 1;
            var result   = new TileRect(topLeft, diameter, diameter);

            return(result);
        }
Пример #5
0
        public void Add([NotNull] IGameObject gameObject)
        {
            if (gameObject == null)
            {
                throw new ArgumentNullException(nameof(gameObject));
            }
            if (!gameObject.IsExtant)
            {
                throw new ArgumentException("Cannot Add a non-extant object to the GameObjectCollection.");
            }

            TilePos tp = gameObject.TilePosition;
            ref List <IGameObject> listOfStaticItem = ref this._gameObjects[tp.X, tp.Y];
Пример #6
0
 public Grid(TilePos worldSize)
 {
     this._gameObjects = new List <IGameObject> [worldSize.X, worldSize.Y];
     this._worldSize   = worldSize;
 }
Пример #7
0
 public TileRect(TilePos topLeft, int width, int height)
 {
     this.TopLeft = topLeft;
     this.Width   = width;
     this.Height  = height;
 }