示例#1
0
        //-----------------------------------------------------------------------------
        // 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);
                        }
                    }
                }
            }
        }
示例#2
0
 //-----------------------------------------------------------------------------
 // Tile Methods
 //-----------------------------------------------------------------------------
 // Returns true if there is free space to place the given tile at a location.
 public bool CanPlaceTile(TileData tile, Room room, Point2I location, int layer)
 {
     Point2I size = tile.Size;
     for (int x = 0; x < size.X; x++) {
         for (int y = 0; y < size.Y; y++) {
             Point2I loc = location + new Point2I(x, y);
             if (room.GetTile(loc, layer) != null)
                 return false;
         }
     }
     return true;
 }
示例#3
0
        private void ActivateTile(MouseButtons mouseButton, Room room, Point2I tileLocation)
        {
            TileDataInstance tile = room.GetTile(tileLocation, EditorControl.CurrentLayer);

            if (mouseButton == MouseButtons.Left) {
                TileData selectedTilesetTileData = editorControl.SelectedTilesetTileData as TileData;

                if (selectedTilesetTileData != null) {
                    // Remove the existing tile.
                    if (tile != null) {
                        room.RemoveTile(tile);
                        editorControl.OnDeleteObject(tile);
                    }
                    // Place the new tile.
                    room.PlaceTile(
                        new TileDataInstance(selectedTilesetTileData),
                        tileLocation.X, tileLocation.Y, editorControl.CurrentLayer);
                }
            }
            else if (mouseButton == MouseButtons.Right) {
                // Erase the tile.
                if (tile != null) {
                    room.RemoveTile(tile);
                    editorControl.OnDeleteObject(tile);
                }
            }
            else if (mouseButton == MouseButtons.Middle) {
                // Sample the tile.
                if (tile != null) {
                    editorControl.SelectedTilesetTile		= -Point2I.One;
                    editorControl.SelectedTilesetTileData	= tile.TileData;
                }
            }
        }
        //-----------------------------------------------------------------------------
        // Static Methods
        //-----------------------------------------------------------------------------
        public static DungeonMapRoom Create(Room room, DungeonMapFloor floor)
        {
            // Don't show empty rooms.
            if (IsRoomEmpty(room))
                return null;

            // Create the map room object.
            DungeonMapRoom mapRoom = new DungeonMapRoom() {
                room			= room,
                hasTreasure		= room.HasUnopenedTreasure(),
                isDiscovered	= room.IsDiscovered,
                isBossRoom		= room.IsBossRoom,
                location		= room.Location,
                sprite			= null,
                floor			= floor,
            };

            // Determine the sprite to draw for this room based on its connections.
            Sprite[] connectedSprites = new Sprite[16] {
                GameData.SPR_UI_MAP_ROOM_NONE,
                GameData.SPR_UI_MAP_ROOM_RIGHT,
                GameData.SPR_UI_MAP_ROOM_UP,
                GameData.SPR_UI_MAP_ROOM_UP_RIGHT,
                GameData.SPR_UI_MAP_ROOM_LEFT,
                GameData.SPR_UI_MAP_ROOM_LEFT_RIGHT,
                GameData.SPR_UI_MAP_ROOM_LEFT_UP,
                GameData.SPR_UI_MAP_ROOM_LEFT_UP_RIGHT,
                GameData.SPR_UI_MAP_ROOM_DOWN,
                GameData.SPR_UI_MAP_ROOM_DOWN_RIGHT,
                GameData.SPR_UI_MAP_ROOM_DOWN_UP,
                GameData.SPR_UI_MAP_ROOM_DOWN_UP_RIGHT,
                GameData.SPR_UI_MAP_ROOM_DOWN_LEFT,
                GameData.SPR_UI_MAP_ROOM_DOWN_LEFT_RIGHT,
                GameData.SPR_UI_MAP_ROOM_DOWN_LEFT_UP,
                GameData.SPR_UI_MAP_ROOM_DOWN_LEFT_UP_RIGHT,
            };

            // Check for room connections.
            int[] connected = new int[] { 0, 0, 0, 0 };
            for (int y = 0; y < room.Height; y++) {
                bool freeOnRight = true;
                bool freeOnLeft = true;
                for (int i = 0; i < room.LayerCount; i++) {
                    TileDataInstance left = room.GetTile(0, y, i);
                    if (left != null && left.SolidType != TileSolidType.NotSolid && !typeof(TileDoor).IsAssignableFrom(left.Type))
                        freeOnLeft = false;
                    TileDataInstance right = room.GetTile(room.Width - 1, y, i);
                    if (right != null && right.SolidType != TileSolidType.NotSolid && !typeof(TileDoor).IsAssignableFrom(right.Type))
                        freeOnRight = false;;
                }
                if (freeOnRight)
                    connected[Directions.Right] = 1;
                if (freeOnLeft)
                    connected[Directions.Left] = 1;
            }
            for (int x = 0; x < room.Width; x++) {
                bool freeOnUp = true;
                bool freeOnDown = true;
                for (int i = 0; i < room.LayerCount; i++) {
                    TileDataInstance up = room.GetTile(x, 0, i);
                    TileDataInstance down = room.GetTile(x, room.Height - 1, i);
                    if (up != null && up.SolidType != TileSolidType.NotSolid && !typeof(TileDoor).IsAssignableFrom(up.Type))
                        freeOnUp = false;
                    if (down != null && down.SolidType != TileSolidType.NotSolid && !typeof(TileDoor).IsAssignableFrom(down.Type))
                        freeOnDown = false;
                }
                if (freeOnUp)
                    connected[Directions.Up] = 1;
                if (freeOnDown)
                    connected[Directions.Down] = 1;
            }

            int spiteIndex = (connected[0]) + (connected[1] << 1) + (connected[2] << 2) + (connected[3] << 3);
            mapRoom.sprite = connectedSprites[spiteIndex];

            return mapRoom;
        }
 public static bool IsRoomEmpty(Room room)
 {
     TileData sameTileType = null;
     for (int layer = 0; layer < room.LayerCount; layer++) {
         for (int x = 0; x < room.Width; x++) {
             for (int y = 0; y < room.Height; y++) {
                 TileDataInstance tile = room.GetTile(x, y, layer);
                 if (tile != null && layer > 0)
                     return false;
                 if (layer == 0) {
                     if (sameTileType != null && tile == null)
                         return false;
                     else if (sameTileType != null && tile != null && tile.TileData != sameTileType)
                         return false;
                     else if (sameTileType == null && tile != null)
                         sameTileType = tile.TileData;
                 }
             }
         }
     }
     return true;
 }
示例#6
0
        // Draw an entire room.
        private void DrawRoom(Graphics2D g, Room room)
        {
            Color belowFade = new Color(255, 255, 255, 150);
            Color aboveFade = new Color(255, 255, 255, 100);
            Color hide = Color.Transparent;
            Color normal = Color.White;

            // Draw white background.
            g.FillRectangle(new Rectangle2I(Point2I.Zero, room.Size * GameSettings.TILE_SIZE), Color.White);

            // Draw tile layers.
            for (int i = 0; i < room.LayerCount; i++) {
                // Determine color/transparency for layer based on layer visibility.
                Color color = normal;
                if (!editorControl.ShouldDrawEvents) {
                    if (editorControl.CurrentLayer > i) {
                        if (editorControl.BelowTileDrawMode == TileDrawModes.Hide)
                            color = hide;
                        else if (editorControl.BelowTileDrawMode == TileDrawModes.Fade)
                            color = belowFade;
                    }
                    else if (editorControl.CurrentLayer < i) {
                        if (editorControl.AboveTileDrawMode == TileDrawModes.Hide)
                            color = hide;
                        else if (editorControl.AboveTileDrawMode == TileDrawModes.Fade)
                            color = aboveFade;
                    }
                }

                // Draw the tile grid for this layer.
                for (int x = 0; x < room.Width; x++) {
                    for (int y = 0; y < room.Height; y++) {
                        Point2I position = new Point2I(x, y) * GameSettings.TILE_SIZE;
                        TileDataInstance tile = room.GetTile(x, y, i);

                        // Draw tile.
                        if (tile != null && tile.IsAtLocation(x, y))
                            DrawTile(g, tile, position, color);

                        // Draw grid square.
                        if (i == room.LayerCount - 1) {
                            if (editorControl.ShowGrid)
                                g.DrawRectangle(new Rectangle2I(position, new Point2I(GameSettings.TILE_SIZE + 1)), 1, new Color(0, 0, 0, 150));
                        }
                    }
                }
            }

            // Draw event tiles.
            if (editorControl.ShowEvents || editorControl.ShouldDrawEvents) {
                for (int i = 0; i < room.EventData.Count; i++)
                    DrawEventTile(g, room.EventData[i], room.EventData[i].Position, Color.White);
            }

            // Draw the spacing lines between rooms.
            if (editorControl.RoomSpacing > 0) {
                g.FillRectangle(new Rectangle2I(0, room.Height * GameSettings.TILE_SIZE, room.Width * GameSettings.TILE_SIZE, editorControl.RoomSpacing), Color.Black);
                g.FillRectangle(new Rectangle2I(room.Width * GameSettings.TILE_SIZE, 0, editorControl.RoomSpacing, room.Height * GameSettings.TILE_SIZE + editorControl.RoomSpacing), Color.Black);
            }
        }
示例#7
0
        private void WriteRoom(BinaryWriter writer, Room room)
        {
            writer.Write(room.Width);
            writer.Write(room.Height);
            writer.Write(room.LayerCount);
            WriteProperties(writer, room.Properties);

            // Write all tiles for the first tile layer.
            for (int y = 0; y < room.Height; y++)
            {
                for (int x = 0; x < room.Width; x++)
                {
                    TileDataInstance tile = room.GetTile(x, y, 0);
                    if (tile != null && tile.IsAtLocation(x, y))
                    {
                        WriteTileData(writer, tile);
                    }
                    else
                    {
                        writer.Write(-11);                         // -11 signifies a null tile.
                    }
                }
            }

            // Count non-null tile data for higher layers.
            int tileDataCount = 0;

            for (int i = 1; i < room.LayerCount; i++)
            {
                for (int y = 0; y < room.Height; y++)
                {
                    for (int x = 0; x < room.Width; x++)
                    {
                        TileDataInstance tile = room.GetTile(x, y, i);
                        if (tile != null && tile.IsAtLocation(x, y))
                        {
                            tileDataCount++;
                        }
                    }
                }
            }

            // Write non-null tile data for higher layers.
            writer.Write(tileDataCount);
            for (int i = 1; i < room.LayerCount; i++)
            {
                for (int y = 0; y < room.Height; y++)
                {
                    for (int x = 0; x < room.Width; x++)
                    {
                        TileDataInstance tile = room.GetTile(x, y, i);
                        if (tile != null && tile.IsAtLocation(x, y))
                        {
                            writer.Write(x);
                            writer.Write(y);
                            writer.Write(i);
                            WriteTileData(writer, tile);
                        }
                    }
                }
            }

            // Write event tile data.
            writer.Write(room.EventData.Count);
            for (int i = 0; i < room.EventData.Count; i++)
            {
                EventTileDataInstance eventTile = room.EventData[i];
                WriteEventTileData(writer, eventTile);
            }
        }
示例#8
0
        // Place a tile in a room, deleting any other tiles in the way.
        public void PlaceTile(TileDataInstance tile, Room room, Point2I location, int layer)
        {
            // Remove any tiles in the way.
            Point2I size = tile.Size;
            for (int x = 0; x < size.X; x++) {
                for (int y = 0; y < size.Y; y++) {
                    TileDataInstance t = room.GetTile(location, layer);
                    if (t != null)
                        DeleteTile(t);
                }
            }

            // Place the tile.
            room.PlaceTile(tile, location, layer);
        }
示例#9
0
 //-----------------------------------------------------------------------------
 // Internal methods
 //-----------------------------------------------------------------------------
 private void ActivateTile(MouseButtons mouseButton, Room room, Point2I tileLocation)
 {
     if (mouseButton == MouseButtons.Left) {
         // Sample the tile.
         TileDataInstance tile = room.GetTile(tileLocation, editorControl.CurrentLayer);
         if (tile != null) {
             editorControl.SelectedTilesetTile = -Point2I.One;
             editorControl.SelectedTilesetTileData = tile.TileData;
         }
     }
 }
示例#10
0
        //-----------------------------------------------------------------------------
        // Internal methods
        //-----------------------------------------------------------------------------
        private void ActivateTile(MouseButtons mouseButton, Room room, Point2I tileLocation)
        {
            if (mouseButton == MouseButtons.Left) {
                room.CreateTile(
                    editorControl.SelectedTilesetTileData,
                    tileLocation.X, tileLocation.Y, editorControl.CurrentLayer
                );

            }
            else if (mouseButton == MouseButtons.Right) {
                if (editorControl.CurrentLayer == 0) {
                    room.CreateTile(
                        editorControl.Tileset.DefaultTileData,
                        tileLocation.X, tileLocation.Y, editorControl.CurrentLayer
                    );
                }
                else {
                    room.RemoveTile(tileLocation.X, tileLocation.Y, editorControl.CurrentLayer);
                }
            }
            else if (mouseButton == MouseButtons.Middle) {
                // Sample the tile.
                TileDataInstance tile = room.GetTile(tileLocation, EditorControl.CurrentLayer);
                if (tile != null) {
                    editorControl.SelectedTilesetTile = -Point2I.One;
                    editorControl.SelectedTilesetTileData = tile.TileData;
                }
            }
        }