public void DestroyBridge(bool instantaneous = false, bool rememberState = false) { if (bridgeDirection >= 0 && (state == TileBridgeState.Created || state == TileBridgeState.Creating)) { if (state == TileBridgeState.Creating) { pieceLocation -= Directions.ToPoint(bridgeDirection); if (pieceLocation == Location) { return; } } else { // Find the second to last tile in the bridge. pieceLocation = new Point2I(-1, -1); TileBridge pieceTile = GetConnectedTile(bridgeDirection); while (pieceTile != null) { TileBridge nextTile = pieceTile.GetConnectedTile(bridgeDirection); if (nextTile == null) { break; } pieceLocation = pieceTile.Location; pieceTile = nextTile; } } if (pieceLocation.X > 0 && pieceLocation.Y > 0) { state = TileBridgeState.Destroying; timer = 0; } } if (instantaneous) { while (state == TileBridgeState.Destroying) { TileBridge pieceTile = GetConnectedTile(pieceLocation); if (pieceTile != null) { RoomControl.RemoveTile(pieceTile); } pieceLocation -= Directions.ToPoint(bridgeDirection); if (pieceLocation == Location) { state = TileBridgeState.Destroyed; break; } } } if (state == TileBridgeState.Destroyed || state == TileBridgeState.Destroying) { Properties.Set("built", false); } }
public override void Update() { base.Update(); if (state == TileBridgeState.Creating) { timer++; if (timer >= 10) { timer = 0; if (RoomControl.IsTileInBounds(pieceLocation) && GetConnectedTile(pieceLocation) == null) { AudioSystem.PlaySound(GameData.SOUND_BARRIER); TileData pieceTileData = Resources.GetResource <TileData>( isVertical ? "bridge_vertical" : "bridge_horizontal"); Tile pieceTile = Tile.CreateTile(pieceTileData); RoomControl.PlaceTileOnHighestLayer(pieceTile, pieceLocation); pieceLocation += Directions.ToPoint(bridgeDirection); } else { state = TileBridgeState.Created; } } } else if (state == TileBridgeState.Destroying) { timer++; if (timer >= 10) { timer = 0; TileBridge pieceTile = GetConnectedTile(pieceLocation); if (pieceTile != null) { RoomControl.RemoveTile(pieceTile); AudioSystem.PlaySound(GameData.SOUND_BARRIER); } pieceLocation -= Directions.ToPoint(bridgeDirection); if (pieceLocation == Location) { state = TileBridgeState.Destroyed; } } } }