// Move the car in the current direction, if that cell isn't blocked private void MoveForward() { bool reachedEnd = false; Vector2 nextCoords = car.CurrentCoord + new Vector2(car.XDir, car.YDir); if (nextCoords.x >= 0 && nextCoords.y >= 0 && nextCoords.x <= 4 && nextCoords.y <= 9) { foreach (GridCell cell in cells) { if (cell.blocked && cell.Coords == nextCoords) { return; // prevent from going into blocked cells/out of bounds } else if (!cell.blocked && cell.Coords == nextCoords && cell.name == "End") { reachedEnd = true; endCell = cell; } } car.Move(); if (reachedEnd) { endCell.GetComponent <BooleanSwitchTest>().isEnabled = false; endCell.GetComponent <BooleanSwitchTest>().ToggleBoolean(); doorToUnlock.SetLock(false); } else if (endCell != null) { endCell.GetComponent <BooleanSwitchTest>().isEnabled = true; endCell.GetComponent <BooleanSwitchTest>().ToggleBoolean(); doorToUnlock.SetLock(true); } } }
private void ResetPressedCellType() { ResetGrid(); GridCell cell = GetCellOnMouse(); PathCell pathCell = cell.GetComponent <PathCell>(); pathfindController.SetCellType(pathCell, PathCell.CellType.Empty); gridSavingController.SaveCell(pathCell); }
private void PlaceCell(Vector2 startPos, float isoX, float isoY, int x, int y) { Vector2 pos = new Vector2(startPos.x + isoX, startPos.y + isoY); GridCell c = Instantiate(gridCell).GetComponent <GridCell> (); c.GetComponent <Transform> ().SetParent(gridHolder); c.PlaceTile(new GridPos(x, y), pos); c.name = string.Format("{0}, {1}", Mathf.Abs(x), Mathf.Abs(y)); }
public void DrawDecObjectBordersOnGrid(int _i, int _j, int cellsCount) { if (!gridIsActive) { return; } //Отрисовка участка сетки на который занимает декоративный объект bool objectCanBeSet = HaveAnEmptyCells(_i, _j, cellsCount); int iFrom = _i; int jFrom = _j; //Проверка на выход за границы массива if (_i + cellsCount > iCount) { iFrom = iFrom - (_i + cellsCount - iCount); } if (_j + cellsCount > jCount) { jFrom = jFrom - (_j + cellsCount - jCount); } for (int i = iFrom; i < iFrom + cellsCount; i++) { for (int j = jFrom; j < jFrom + cellsCount; j++) { GridCell cell = transform.GetChild(i * jCount + j).GetComponent <GridCell>(); if (cell != null) { if (objectCanBeSet) { cell.GetComponent <SpriteRenderer>().sprite = canBeSetCellSprite; } else { cell.GetComponent <SpriteRenderer>().sprite = fullCellSprite; } } } } }
public void ReDrawGridRect(int _i, int _j, int cellsCount) { if (!gridIsActive) { return; } int iFrom = _i; int jFrom = _j; //Проверка на выход за границы массива if (_i + cellsCount > iCount) { iFrom = iFrom - (_i + cellsCount - iCount); } if (_j + cellsCount > jCount) { jFrom = jFrom - (_j + cellsCount - jCount); } for (int i = iFrom; i < iFrom + cellsCount; i++) { for (int j = jFrom; j < jFrom + cellsCount; j++) { GridCell cell = transform.GetChild(i * jCount + j).GetComponent <GridCell>(); if (cell != null) { if (cell.isEmpty) { cell.GetComponent <SpriteRenderer>().sprite = emptyCellSprite; } else { cell.GetComponent <SpriteRenderer>().sprite = fullCellSprite; } } } } }
public void HighlightCell(GridCell cell, Color32 highlightColor) { if (cell.height <= lavaMaxHeight) { return; } SpriteRenderer spriteRenderer = cell.GetComponent <SpriteRenderer>(); if (spriteRenderer.color != VisualInfo.defaultCellColor) { return; } spriteRenderer.color = highlightColor; highlightedCells.Add(spriteRenderer); }
private void UpdatePressedCellType() { ResetGrid(); GridCell cell = GetCellOnMouse(); if (!cell) { return; } Toggle activeToggle = cellTypeToggleGroup.ActiveToggles().First(); ToggleTypeHolder toggleTypeHolder = activeToggle.GetComponent <ToggleTypeHolder>(); PathCell pathCell = cell.GetComponent <PathCell>(); pathfindController.SetCellType(pathCell, toggleTypeHolder.cellType); gridSavingController.SaveCell(pathCell); }
public void Load() { for (int i = 0; i < gridExtension.gridSize.x; i++) { for (int j = 0; j < gridExtension.gridSize.y; j++) { string cellPrefKey = i + " " + j; PathCell.CellType type = PathCell.CellType.Empty; if (PlayerPrefs.HasKey(cellPrefKey)) { type = (PathCell.CellType)PlayerPrefs.GetInt(cellPrefKey); } GridCell gridCell = gridExtension.GetCell(i, j); if (gridCell) { PathCell pathCell = gridCell.GetComponent <PathCell>(); pathfindController.SetCellType(pathCell, type); } } } }
private void HighlightCell(int index, GridCell cell) { RectTransform mask = _masks[index]; Highlight(ref mask, cell.GetComponent <RectTransform>()); }