private static void FindCorrespondingInteropCells(Word.Table table, CellInfo[,] cellInfos) { var interopRow = 1; for (int r = 0; r < cellInfos.GetLength(0); r++) { var interopCol = 0; for (int c = 0; c < cellInfos.GetLength(1); c++) { var cellInfo = cellInfos[r, c]; if (cellInfo.MergedVerticallyWith != null) { interopCol++; } else { interopCol++; cellInfo.Row = interopRow; cellInfo.Column = interopCol; cellInfo.Cell = GetCell(cellInfo, table); } } interopRow++; } }
public LogicGrid(CellInfo[,] infoGrid) { int width = infoGrid.GetLength(0); int height = infoGrid.GetLength(1); Grid = new LogicCell[width, height]; Dictionary <int, LogicCell> cells = new Dictionary <int, LogicCell>(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Grid[x, y] = infoGrid[x, y].CellFromBytes(); if (Grid[x, y] != null) { cells[Grid[x, y].GetCellID()] = Grid[x, y]; } } } for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (Grid[x, y] is DoorButtonCell doorButton) { if (cells[doorButton.GetLinkedDoorID()] is DoorCell door) { doorButton.SetLinkedDoor(door); } } } } }
public List <Square> SpawnLevel(CellInfo[,] level) { var height = level.GetLength(0); var width = level.GetLength(1); var spawned = new Square[height, width]; var output = new List <Square>(); //spawnsquares for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if (level[i, j].Color != SquareType.Blank) { var rotation = new Quaternion { eulerAngles = new Vector3(0, 0, level[i, j].Rotation) }; var square = this.SpawnSquare(level[i, j].Color, new Vector3(j, -i, 0) * Game.SquareSize, Vector3.zero, rotation); if (level[i, j].Fixed) { square.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; } square.Identifier = level[i, j].Identifier; spawned[i, j] = square; output.Add(square); } } } //join them for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if (level[i, j].Color != SquareType.Blank) { foreach (var c in level[i, j].JoinDirections) { var dir = Tools.CharToDirection(c); if (i + dir[0] >= 0 && i + dir[0] < height && j + dir[1] >= 0 && j + dir[1] < width && spawned[i + dir[0], j + dir[1]] != null) { FixSquares(spawned[i, j], spawned[i + dir[0], j + dir[1]]); } } } } } return(output); }
private IEnumerable <CellInfo> FlatGrid() { for (int x = 0; x < _grid.GetLength(0); x++) { for (int y = 0; y < _grid.GetLength(1); y++) { yield return(_grid[x, y]); } } }
public void SetGridState(CreateCubeInCell Create) { for (int x = 0; x < cells.GetLength(0); x++) { for (int y = 0; y < cells.GetLength(1); y++) { CellInfo cellInfo = cells[x, y]; if (!cellInfo.isFree) { Create(new Vector2(x, y), cellInfo.cubeIndex); } } } }
public override void _Ready() { _map = (TileMap)FindNode("TileMap"); var cellPositions = _map.GetUsedCells().OfType <Vector2>() .Select(t => new Point((int)t.x, (int)t.y)) .ToArray(); var minX = cellPositions.Min(t => t.X); var maxX = cellPositions.Max(t => t.X); var minY = cellPositions.Min(t => t.Y); var maxY = cellPositions.Max(t => t.Y); _grid = new CellInfo[maxX - minX + 1, maxY - minY + 1]; for (int x = 0; x < _grid.GetLength(0); x++) { for (int y = 0; y < _grid.GetLength(1); y++) { _grid[x, y] = new CellInfo { CellType = CellTypes.Empty, HasFire = false, Heat = 0 }; } } foreach (var cellPos in cellPositions) { var p = new Point(cellPos.X - minX, cellPos.Y - minY); _grid[p.X, p.Y].LocalCoords = cellPos; _grid[p.X, p.Y].CellType = (CellTypes)_map.GetCell(cellPos.X, cellPos.Y); _grid[p.X, p.Y].WorldCoords = _map.MapToWorld(cellPos.ToVector()) + new Vector2(0, _map.CellSize.y / 2); _grid[p.X, p.Y].GridCoords = p; if (_grid[p.X, p.Y].CellType == CellTypes.Heater) { _grid[p.X, p.Y].Heat = 100; } } _player = (AudioStreamPlayer)FindNode("FireSound"); _player.Play(); }
private static void ApplyVerticalMerges(CellInfo[,] cellInfos) { for (int r = 0; r < cellInfos.GetLength(0); r++) { for (int c = 0; c < cellInfos.GetLength(1); c++) { var cellInfo = cellInfos[r, c]; var vmerge = cellInfo.XmlCell?.Descendants().FirstOrDefault(d => d.Name.LocalName == "vmerge"); if (vmerge != null) { var isParent = (vmerge.Attributes().FirstOrDefault(a => a.Name.LocalName == "val")?.Value ?? string.Empty) == "restart"; if (isParent) { MarkCellsBelow(cellInfos, r, c); } } } } }
private static void MarkCellsBelow(CellInfo[,] cells, int parentR, int parentC) { var parentCell = cells[parentR, parentC]; for (int r = parentR + 1; r < cells.GetLength(1); r++) { var cell = cells[r, parentC]; var vmerge = cell.XmlCell?.Descendants().FirstOrDefault(d => d.Name.LocalName == "vmerge"); if (vmerge == null) { break; } var isParent = (vmerge?.Attributes().FirstOrDefault(a => a.Name.LocalName == "val")?.Value ?? string.Empty) == "restart"; if (isParent) { break; } cell.MergedVerticallyWith = parentCell.XmlCell; } }
private IEnumerator BuildWorldFromCellInfoCoroutine(CellInfo[,] cellInfos) { // voir https://docs.unity3d.com/ScriptReference/Tilemaps.Tilemap.SetTiles.html // créer arrays de tile ensuite call setTiles ? Vector3Int pos = new Vector3Int(0, 0, 0); m_totalTiles = cellInfos.GetLength(0) * cellInfos.GetLength(1); List <Tile> wallCells = new List <Tile>(); List <Tile> floorCells = new List <Tile>(); List <Tile> doorCells = new List <Tile>(); List <Tile> doorButtonCells = new List <Tile>(); List <Tile> playerSpawnCells = new List <Tile>(); List <Vector3Int> wallPos = new List <Vector3Int>(); List <Vector3Int> floorPos = new List <Vector3Int>(); List <Vector3Int> doorPos = new List <Vector3Int>(); List <Vector3Int> doorButtonPos = new List <Vector3Int>(); List <Vector3Int> playerSpawnPos = new List <Vector3Int>(); for (int x = 0; x < cellInfos.GetLength(0); x++) { for (int y = 0; y < cellInfos.GetLength(1); y++) { LogicCell cell = cellInfos[x, y].CellFromBytes(); pos.x = x; pos.y = y; if (cell is WallCell) { wallCells.Add(m_defaultWallTile); wallPos.Add(pos); } else if (cell is FloorCell) { floorCells.Add(m_defaultFloorTile); floorPos.Add(pos); } else if (cell is DoorCell) { doorCells.Add(m_defaultDoorTile); doorPos.Add(pos); } else if (cell is DoorButtonCell) { doorButtonCells.Add(m_defaultInteractableTile); doorButtonPos.Add(pos); } else if (cell is PlayerSpawnCell) { playerSpawnCells.Add(m_defaultPlayerSpawnTile); playerSpawnPos.Add(pos); } m_loadedTiles++; } yield return(null); } m_walls.SetTiles(wallPos.ToArray(), wallCells.ToArray()); m_floor.SetTiles(floorPos.ToArray(), floorCells.ToArray()); m_doors.SetTiles(doorPos.ToArray(), doorCells.ToArray()); m_interactable.SetTiles(doorButtonPos.ToArray(), doorButtonCells.ToArray()); m_playerSpawn.SetTiles(playerSpawnPos.ToArray(), playerSpawnCells.ToArray()); IsRebuilt = true; m_onWorldBuilt.Invoke(); }