void PropateExplotion(int x, int y, int limit, int xStep, int yStep) { Debug.Log("X: " + x + " Y: " + y); if (limit >= ExplotionRange) { return; } BaseTile tileToCheck = tile.GetNeigbourInDirection(x, y); if (tileToCheck.GetType() == typeof(Wall)) { return; } ExplosionEffect SFX = Instantiate(effect, tileToCheck.transform.position, Quaternion.identity); tileToCheck.AddObjectToTile(SFX); tileToCheck.GetComponent <IDamage>().TakeDamage(Damage); if (xStep == 0 && yStep == 0) { return; } limit++; PropateExplotion(x + xStep, y + yStep, limit, xStep, yStep); }
public void FillRandom(BaseTile prefab) { for (uint i = 0; i < x; i++) { for (uint j = 0; j < y; j++) { BaseTile tile = Instantiate(prefab); int dirStart = (int)Random.Range(0.0f, 3.0f); int dirEnd = (int)Random.Range(0.0f, 3.0f); if (dirEnd == 1) { dirEnd = 3; } if (dirStart == dirEnd) { if (dirStart == 3) { dirStart = 1; } dirEnd = 3; } tile.SetDirections((BaseTile.eDirection)dirStart, (BaseTile.eDirection)dirEnd); //tile.SetDirections(BaseTile.eDirection.left, BaseTile.eDirection.right); tile.name = "Tile" + i + "_" + j; AddTile(tile, i, j); Destroy(tile.GetComponent <DraggableObject>()); } } }
/// <summary> /// Saves Details and DOES CHECK for ITileHit interfaces /// </summary> /// <param name="tile"></param> /// <param name="WorldOffset"></param> public LightHitInfo(BaseTile tile, Vector2Int WorldOffset) { this.hitTile = tile.GetComponent <ITileHit>(); this.lightPosition = tile.arrayPosition + WorldOffset; }
public LightHitInfo[] LightBouncePositions(Vector2Int startPosition, Vector2Int aimingDirection, TileColor lightColor) { if (aimingDirection == Vector2Int.zero) { //If there is no direction then it can go no where, so lets just stop it here otherwise it will be stuck in a infinite loop LightHitInfo[] tempArray = { new LightHitInfo(startPosition, Vector2Int.zero) }; return(tempArray); } BaseTile NextPosition = GridArray[startPosition.x][startPosition.y]; List <LightHitInfo> ReflectPositions = new List <LightHitInfo>(); //A Temporary List for checking the satelite Positions hit, so it doesn't get stuck in a loop List <Vector2Int> TilesHit = new List <Vector2Int>(); Vector2Int LastKnownHeading = aimingDirection; Vector2Int nullPosition = new Vector2Int(-1, -1); //Set First Position ReflectPositions.Add(new LightHitInfo(NextPosition, WorldOffset)); TilesHit.Add(startPosition); //Try to get to the next position, so we aren't just checking the position we started from already Vector2Int tempPosition = NextPosition.arrayPosition + LastKnownHeading; if (tempPosition.x < Width && tempPosition.x >= 0 && tempPosition.y < Height && tempPosition.y >= 0) { NextPosition = GridArray[tempPosition.x][tempPosition.y]; } else { //Position is out of the array break here NextPosition = null; } while (NextPosition != null) { //Look into the next Position tempPosition = nullPosition; //Check if this Position is a Satalite switch (NextPosition.tileType) { case BaseTile.TileTypes.Satalite: //This is a satalite, this will update our heading LastKnownHeading = NextPosition.GetComponent <Satellite>().ReflectDirection; if (TilesHit.Contains(NextPosition.arrayPosition)) { //Stop this here, since we are going to end up going in a loop ReflectPositions.Add(new LightHitInfo(NextPosition, WorldOffset)); TilesHit.Add(NextPosition.arrayPosition); //Is this needed? NextPosition = null; break; } else { ReflectPositions.Add(new LightHitInfo(NextPosition, WorldOffset)); TilesHit.Add(NextPosition.arrayPosition); } break; case BaseTile.TileTypes.LightTarget: TargetTile tempTarget = NextPosition.GetComponent <TargetTile>(); if (lightColor == tempTarget.TargetColour) { ReflectPositions.Add(new LightHitInfo(NextPosition, WorldOffset)); TilesHit.Add(NextPosition.arrayPosition); //Is this needed? NextPosition = null; break; } else { //Not Reached our Target } break; case BaseTile.TileTypes.CombineSatellite: //Check if we are searching for our selves if (NextPosition.arrayPosition == startPosition) { break; } //End the Light position for this colour ReflectPositions.Add(new LightHitInfo(NextPosition, WorldOffset)); TilesHit.Add(NextPosition.arrayPosition); NextPosition = null; break; case BaseTile.TileTypes.LightGate: //Check if the light can pass through the gate LightGate tempGate = NextPosition.GetComponent <LightGate>(); if (tempGate.CanPass(LastKnownHeading, lightColor)) { ReflectPositions.Add(new LightHitInfo(NextPosition.arrayPosition, WorldOffset)); } else { ReflectPositions.Add(new LightHitInfo(NextPosition, WorldOffset)); NextPosition = null; } break; //If the Tile hit ends here and DOES contain ITileHit interface case BaseTile.TileTypes.SatelliteSplitter: case BaseTile.TileTypes.LightTrigger: case BaseTile.TileTypes.LightFilter: //Not matter what happens, the light beam should end here ReflectPositions.Add(new LightHitInfo(NextPosition, WorldOffset)); TilesHit.Add(NextPosition.arrayPosition); NextPosition = null; break; //If the tile hits an end point but DOES NOT contain the ITileHit interface case BaseTile.TileTypes.Asteroid: //End Here, Hit an Asteroid ReflectPositions.Add(new LightHitInfo(NextPosition, WorldOffset)); TilesHit.Add(NextPosition.arrayPosition); //Is this needed? NextPosition = null; break; } if (NextPosition == null) { break; } //Basic Tile, Keep Heading in Direction and Till we reach the end tempPosition = NextPosition.arrayPosition + LastKnownHeading; //Checking this is within the size of the array, and has been assigned if (tempPosition.x < Width && tempPosition.x >= 0 && tempPosition.y < Height && tempPosition.y >= 0) { NextPosition = GridArray[tempPosition.x][tempPosition.y]; } else { ReflectPositions.Add(new LightHitInfo(NextPosition, WorldOffset)); //Reached End NextPosition = null; break; } } return(ReflectPositions.ToArray()); }