public override void Spread() { Queue <Vector2Int> openSet = new Queue <Vector2Int>(); List <Vector2Int> closedSet = new List <Vector2Int>(); openSet.Enqueue(gridPos); Direction wireDirection; Vector2Int currPos; while (openSet.Count > 0) { currPos = openSet.Dequeue(); wireDirection = SlotGrid.GetWireDirection(currPos.x, currPos.y); closedSet.Add(currPos); foreach (Vector2Int position in GetConnectedSlotPositions(currPos, wireDirection)) { if (!closedSet.Contains(position)) { openSet.Enqueue(position); } } } foreach (Vector2Int position in closedSet) { EnergyTrail newTrail = new EnergyTrail(position, energyType, Direction.None, this); trails.Add(newTrail); } SlotGrid.AddEnergyTrails(trails); }
public override void Spread() { int moveX = 0; int moveY = 0; if (spreadDirection == Direction.Right) { moveX = 1; } else if (spreadDirection == Direction.Left) { moveX = -1; } else if (spreadDirection == Direction.Down) { moveY = 1; } else if (spreadDirection == Direction.Up) { moveY = -1; } Vector2Int trailPos = new Vector2Int(gridPos.x, gridPos.y); do { trailPos.x += moveX; trailPos.y += moveY; EnergyTrail trail = new EnergyTrail(trailPos, EnType.Laser, spreadDirection, this); trails.Add(trail); } while (!SlotGrid.IsSlotOccupied(trailPos.x, trailPos.y)); SlotGrid.AddEnergyTrails(trails); }
public void MoveStartPos() { Vector2Int newGridPosStart = gridPosStart + movement; if (!SlotGrid.IsSlotOccupied(newGridPosStart.x, newGridPosStart.y)) { EnergyTrail trail = new EnergyTrail(newGridPosStart, creator.energyType, CalculateDirection(gridPosStart, newGridPosStart), creator); path.Enqueue(trail); SlotGrid.AddEnergyTrail(trail); gridPosStart.Set(newGridPosStart.x, newGridPosStart.y); } }
public void MoveEndPos(ref bool vanished) { Vector2Int newGridPosEnd = gridPosEnd + movement; EnergyTrail s = path.Dequeue(); SlotGrid.RemoveEnergyTrail(s); if (gridPosStart == newGridPosEnd) { vanished = true; return; } gridPosEnd = newGridPosEnd; }
public override void Spread() { List <EnergyTrail> trails = new List <EnergyTrail>(); int xPos, yPos; for (int i = -power; i <= power; i++) { for (int j = -power; j <= power; j++) { xPos = gridPos.x + i; yPos = gridPos.y + j; if (SlotGrid.PositionInsideGrid(xPos, yPos)) { EnergyTrail trail = new EnergyTrail(new Vector2Int(xPos, yPos), EnType.Heat, Direction.None, this); this.trails.Add(trail); trails.Add(trail); } } } SlotGrid.AddEnergyTrails(trails); }
public void RemoveEnergyTrail(EnergyTrail trail) { energyTrails.Remove(trail); }
public void AddEnergyTrail(EnergyTrail trail) { energyTrails.Add(trail); }
public static void RemoveEnergyTrail(EnergyTrail trail) { instance.slots[trail.gridPos.x, trail.gridPos.y].RemoveEnergyTrail(trail); instance.slots[trail.gridPos.x, trail.gridPos.y].UpdateItems(trail.energy); }