예제 #1
0
파일: Level.cs 프로젝트: radtek/ZeldaOracle
        // Get the room tile location of the given level tile coordinate.
        public Point2I GetTileLocation(LevelTileCoord levelCoord)
        {
            Point2I roomLocation = GetRoomLocation(levelCoord);

            return(new Point2I(levelCoord.X - (roomLocation.X * roomSize.X),
                               levelCoord.Y - (roomLocation.Y * roomSize.Y)));
        }
예제 #2
0
파일: Level.cs 프로젝트: radtek/ZeldaOracle
        //-----------------------------------------------------------------------------
        // Internal Iteration
        //-----------------------------------------------------------------------------

        private IEnumerable <BaseTileDataInstance> GetTilesInArea(Rectangle2I area)
        {
            // Make sure the area is within the level bounds.
            area = Rectangle2I.Intersect(area,
                                         new Rectangle2I(Point2I.Zero, roomSize * dimensions));

            // Iterate the tile grid.
            for (int x = 0; x < area.Width; x++)
            {
                for (int y = 0; y < area.Height; y++)
                {
                    LevelTileCoord coord = (LevelTileCoord)(area.Point + new Point2I(x, y));
                    Room           room  = GetRoom(coord);
                    if (room != null)
                    {
                        Point2I tileLocation = GetTileLocation(coord);
                        for (int i = 0; i < roomLayerCount; i++)
                        {
                            TileDataInstance tile = room.GetTile(tileLocation, i);
                            if (tile != null && tile.Location == tileLocation)
                            {
                                yield return(tile);
                            }
                        }
                    }
                }
            }

            // Determine the collection of rooms that will contain the event tiles.
            Point2I     roomAreaMin = GetRoomLocation((LevelTileCoord)area.Min);
            Point2I     roomAreaMax = GetRoomLocation((LevelTileCoord)area.Max);
            Rectangle2I roomArea    = new Rectangle2I(roomAreaMin, roomAreaMax - roomAreaMin + Point2I.One);

            roomArea = Rectangle2I.Intersect(roomArea, new Rectangle2I(Point2I.Zero, dimensions));
            Rectangle2I pixelArea = new Rectangle2I(
                area.Point * GameSettings.TILE_SIZE,
                area.Size * GameSettings.TILE_SIZE);

            // Iterate event tiles.
            for (int x = roomArea.Left; x < roomArea.Right; x++)
            {
                for (int y = roomArea.Top; y < roomArea.Bottom; y++)
                {
                    Room room = rooms[x, y];
                    for (int i = 0; i < room.EventData.Count; i++)
                    {
                        EventTileDataInstance eventTile  = room.EventData[i];
                        Rectangle2I           tileBounds = eventTile.GetBounds();
                        tileBounds.Point += room.Location * roomSize * GameSettings.TILE_SIZE;
                        if (pixelArea.Contains(tileBounds.Point))
                        {
                            yield return(eventTile);
                        }
                    }
                }
            }
        }
예제 #3
0
파일: Level.cs 프로젝트: radtek/ZeldaOracle
        // Get the room containing the given level tile coordinate.
        public Room GetRoom(LevelTileCoord levelCoord)
        {
            Point2I loc = GetRoomLocation(levelCoord);

            if (ContainsRoom(loc))
            {
                return(rooms[loc.X, loc.Y]);
            }
            return(null);
        }
예제 #4
0
파일: Level.cs 프로젝트: radtek/ZeldaOracle
        // Get the room location containing the given level tile coordinate.
        public Point2I GetRoomLocation(LevelTileCoord levelCoord)
        {
            Point2I roomLocation = new Point2I(
                levelCoord.X / roomSize.X,
                levelCoord.Y / roomSize.Y);

            if (levelCoord.X < 0)
            {
                roomLocation.X--;
            }
            if (levelCoord.Y < 0)
            {
                roomLocation.Y--;
            }
            return(roomLocation);
        }
예제 #5
0
파일: Level.cs 프로젝트: radtek/ZeldaOracle
        // Place the tiles in a tile grid starting at the given location.
        public void PlaceTileGrid(TileGrid tileGrid, LevelTileCoord location)
        {
            // Remove tiles.
            Rectangle2I area = new Rectangle2I((Point2I)location, tileGrid.Size);

            RemoveArea(area);

            // Place tiles.
            foreach (BaseTileDataInstance baseTile in tileGrid.GetTiles())
            {
                if (baseTile is TileDataInstance)
                {
                    TileDataInstance tile  = (TileDataInstance)baseTile;
                    LevelTileCoord   coord = (LevelTileCoord)((Point2I)location + tile.Location);
                    Room             room  = GetRoom(coord);

                    if (room != null)
                    {
                        tile.Location = GetTileLocation(coord);
                        room.PlaceTile(tile, tile.Location, tile.Layer);
                    }
                }
                else if (baseTile is EventTileDataInstance)
                {
                    EventTileDataInstance eventTile = (EventTileDataInstance)baseTile;
                    eventTile.Position += (Point2I)location * GameSettings.TILE_SIZE;
                    Point2I roomLocation = eventTile.Position / (roomSize * GameSettings.TILE_SIZE);
                    Room    room         = GetRoomAt(roomLocation);
                    if (room != null)
                    {
                        eventTile.Position -= roomLocation * roomSize * GameSettings.TILE_SIZE;
                        room.AddEventTile(eventTile);
                    }
                }
            }
        }
예제 #6
0
        // Place the tiles in a tile grid starting at the given location.
        public void PlaceTileGrid(TileGrid tileGrid, LevelTileCoord location)
        {
            // Remove tiles.
            Rectangle2I area = new Rectangle2I((Point2I) location, tileGrid.Size);
            RemoveArea(area);

            // Place tiles.
            foreach (BaseTileDataInstance baseTile in tileGrid.GetTiles()) {
                if (baseTile is TileDataInstance) {
                    TileDataInstance tile = (TileDataInstance) baseTile;
                    LevelTileCoord coord = (LevelTileCoord) ((Point2I) location + tile.Location);
                    Room room = GetRoom(coord);

                    if (room != null) {
                        tile.Location = GetTileLocation(coord);
                        room.PlaceTile(tile, tile.Location, tile.Layer);
                    }
                }
                else if (baseTile is EventTileDataInstance) {
                    EventTileDataInstance eventTile = (EventTileDataInstance) baseTile;
                    eventTile.Position += (Point2I) location * GameSettings.TILE_SIZE;
                    Point2I roomLocation = eventTile.Position / (roomSize * GameSettings.TILE_SIZE);
                    Room room = GetRoomAt(roomLocation);
                    if (room != null) {
                        eventTile.Position -= roomLocation * roomSize * GameSettings.TILE_SIZE;
                        room.AddEventTile(eventTile);
                    }
                }
            }
        }
예제 #7
0
 //-----------------------------------------------------------------------------
 // Level Coordinates
 //-----------------------------------------------------------------------------
 // Return true if the level tile coordinate is within the level's bounds.
 public bool IsInBounds(LevelTileCoord levelCoord)
 {
     return ContainsRoom(GetRoomLocation(levelCoord));
 }
예제 #8
0
 // Get the room tile location of the given level tile coordinate.
 public Point2I GetTileLocation(LevelTileCoord levelCoord)
 {
     Point2I roomLocation = GetRoomLocation(levelCoord);
     return new Point2I(levelCoord.X - (roomLocation.X * roomSize.X),
                        levelCoord.Y - (roomLocation.Y * roomSize.Y));
 }
예제 #9
0
 // Get the room location containing the given level tile coordinate, clamped to the level's bounds.
 public Point2I GetRoomLocationClamped(LevelTileCoord levelCoord)
 {
     return new Point2I(
         GMath.Clamp(levelCoord.X / roomSize.X, 0, dimensions.X - 1),
         GMath.Clamp(levelCoord.Y / roomSize.Y, 0, dimensions.Y - 1));
 }
예제 #10
0
 // Get the room location containing the given level tile coordinate.
 public Point2I GetRoomLocation(LevelTileCoord levelCoord)
 {
     Point2I roomLocation = new Point2I(
             levelCoord.X / roomSize.X,
             levelCoord.Y / roomSize.Y);
     if (levelCoord.X < 0)
         roomLocation.X--;
     if (levelCoord.Y < 0)
         roomLocation.Y--;
     return roomLocation;
 }
예제 #11
0
 // Get the room containing the given level tile coordinate.
 public Room GetRoom(LevelTileCoord levelCoord)
 {
     Point2I loc = GetRoomLocation(levelCoord);
     if (ContainsRoom(loc))
         return rooms[loc.X, loc.Y];
     return null;
 }
예제 #12
0
파일: Level.cs 프로젝트: radtek/ZeldaOracle
 // Get the room location containing the given level tile coordinate, clamped to the level's bounds.
 public Point2I GetRoomLocationClamped(LevelTileCoord levelCoord)
 {
     return(new Point2I(
                GMath.Clamp(levelCoord.X / roomSize.X, 0, dimensions.X - 1),
                GMath.Clamp(levelCoord.Y / roomSize.Y, 0, dimensions.Y - 1)));
 }
예제 #13
0
파일: Level.cs 프로젝트: radtek/ZeldaOracle
        //-----------------------------------------------------------------------------
        // Level Coordinates
        //-----------------------------------------------------------------------------

        // Return true if the level tile coordinate is within the level's bounds.
        public bool IsInBounds(LevelTileCoord levelCoord)
        {
            return(ContainsRoom(GetRoomLocation(levelCoord)));
        }