예제 #1
0
파일: Map.cs 프로젝트: endert/Intro2D
        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;
            }
        }
예제 #2
0
파일: Map.cs 프로젝트: endert/Intro2D
        /// <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;
            }
        }