private bool CheckEnemyPosition(Vector3 position, int stepZ, int stepX) { Vector3 currentPosition = _currentTile.GetPosition(); bool check = position.z >= currentPosition.z + stepZ * _currentTile.GetSize().z&& position.x >= currentPosition.x - stepX * _currentTile.GetSize().x&& position.x <= currentPosition.x + stepX * _currentTile.GetSize().x; return(check); }
public void StartGenerate(LevelConstructor levelConstructor, TileGeneration startTile) { _levelConstructor = levelConstructor; _fogZPosition = startTile.GetPosition().z - startTile.GetSize().z *_startOfsetPosition; _fogStep = startTile.GetSize().z; _pool = FindObjectOfType <FogPool>(); GenerateFog(); StartCoroutine(NextGnerateFog()); }
public TileGeneration[] GetTilesToSpawn(TileGeneration[] tiles, TileGeneration currentTile) { CheckTilesOnScene(tiles); _currentTile = currentTile; Vector3 size = _currentTile.GetSize(); List <TileGeneration> tilesToSpawn = new List <TileGeneration>(); _currentTiles = tiles; Vector3 startTile = _currentTile.GetPosition() + new Vector3(0, 0, _stepZ * size.z); tilesToSpawn.Add(_currentTiles.Where(a => a.GetPosition() == startTile).First()); int counter = 1; bool isTileNotEnded = true; while (isTileNotEnded) { Vector3 nextPosition = new Vector3(startTile.x, startTile.y, startTile.z + _stepZ * counter * size.z); isTileNotEnded = AddTileByCoordinates(nextPosition, ref tilesToSpawn); counter++; if (counter > 100) { Debug.Log("counter > 100"); isTileNotEnded = false; } } Vector3[] centralTiles = new Vector3[tilesToSpawn.Count]; int tilesCounter = 0; foreach (var centralTile in tilesToSpawn) { centralTiles[tilesCounter] = centralTile.GetPosition(); tilesCounter++; } tilesToSpawn = new List <TileGeneration>(); for (int i = 0; i < centralTiles.Length; i++) { AddTileByCoordinates(centralTiles[i], ref tilesToSpawn); for (int j = -2; j <= 2; j++) { if (j != 0) { Vector3 nextPosition = new Vector3(centralTiles[i].x + (j * _stepX * size.x), centralTiles[i].y, centralTiles[i].z); AddTileByCoordinates(nextPosition, ref tilesToSpawn); } } } CheckSpawnsOnSceene(ref tilesToSpawn); if (tilesToSpawn.Count > 0) { foreach (var tileToSpawn in tilesToSpawn) { _tilesWithSpawner.Add(new SpawnerRange(tileToSpawn, _stepX, _stepZ)); } } return(tilesToSpawn.ToArray()); }