Exemplo n.º 1
0
 public void FillRoomWithDefaultTiles(Room room)
 {
     for (int x = 0; x < room.Width; x++)
     {
         for (int y = 0; y < room.Height; y++)
         {
             room.PlaceTile(new TileDataInstance(Zone.DefaultTileData), x, y, 0);
         }
     }
 }
Exemplo n.º 2
0
        private void ReadRoom(BinaryReader reader, Room room)
        {
            // Read the dimensions.
            int width      = reader.ReadInt32();
            int height     = reader.ReadInt32();
            int layerCount = reader.ReadInt32();

            // Read the room's properties.
            ReadProperties(reader, room.Properties);

            // Read tile data for first layer (stored as a grid of tiles).
            for (int y = 0; y < room.Height; y++)
            {
                for (int x = 0; x < room.Width; x++)
                {
                    TileDataInstance tile = ReadTileData(reader);
                    if (tile != null)
                    {
                        room.PlaceTile(tile, new Point2I(x, y), 0);
                    }
                }
            }

            // Read tile data for higher layers (stored as a list of non-null tiles).
            int tileDataCount = reader.ReadInt32();

            for (int i = 0; i < tileDataCount; i++)
            {
                int x     = reader.ReadInt32();
                int y     = reader.ReadInt32();
                int layer = reader.ReadInt32();
                room.PlaceTile(ReadTileData(reader), new Point2I(x, y), layer);
            }

            // Read event tile data.
            int eventTileDataCount = reader.ReadInt32();

            for (int i = 0; i < eventTileDataCount; i++)
            {
                room.AddEventTile(ReadEventTileData(reader));
            }
        }
Exemplo n.º 3
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);
                    }
                }
            }
        }
Exemplo n.º 4
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;
                }
            }
        }
Exemplo n.º 5
0
 public void FillRoomWithDefaultTiles(Room room)
 {
     for (int x = 0; x < room.Width; x++) {
         for (int y = 0; y < room.Height; y++) {
             room.PlaceTile(new TileDataInstance(Zone.DefaultTileData), x, y, 0);
         }
     }
 }
Exemplo n.º 6
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);
        }