Example #1
0
        public bool CheckDownWards(GameObject gObj)
        {
            int x = (int)(gObj.Position.X / TileSize);

            int sx = (int)(gObj.Position.X / TileSize + (gObj.Size.X / TileSize));
            int sy = (int)(gObj.Position.Y / TileSize + (gObj.Size.Y + 3) / TileSize );

            try {
                return tiles[x, sy].Walkable && tiles[sx, sy].Walkable;
            }
            catch (IndexOutOfRangeException)
            {
                return false;
            }
        }
Example #2
0
        /// <summary>
        /// collision test for the given GameObject
        /// </summary>
        /// <param name="gObj"></param>
        /// <returns></returns>
        public bool IsWalkable(GameObject gObj)
        {
            int x = (int)(gObj.Position.X / TileSize + gObj.MovingDirection.X / TileSize);
            int y = (int)(gObj.Position.Y / TileSize + gObj.MovingDirection.Y / TileSize);

            int sx = (int)(gObj.Position.X / TileSize + gObj.Size.X / TileSize + gObj.MovingDirection.X / TileSize);
            int sy = (int)(gObj.Position.Y / TileSize + gObj.Size.Y / TileSize + gObj.MovingDirection.Y / TileSize);

            try
            {
                return tiles[x, y].Walkable && tiles[sx, y].Walkable && tiles[x, sy].Walkable && tiles[sx, sy].Walkable;
            }
            catch (IndexOutOfRangeException)
            {
                return false;
            }
        }