Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using Random = UnityEngine.Random;
- public class PieceBasedLevelGeneration : MonoBehaviour {
- //Other scripts
- public LevelManager LevelManagerScript = null;
- public EnemySpawn EnemySpawnScript = null;
- public Player PlayerScript = null;
- public SecondLane SecondLaneScript = null;
- //Source objects grounds
- public List<GameObject>RiverStarts=new List<GameObject>();
- public List<GameObject> BaseGrounds = null;
- public GameObject BasicWater = null;
- public GameObject StartWater = null;
- public GameObject EndWater = null;
- public GameObject PureBaseGround = null;
- //Source objects index+pools
- public MultiPool PieceMultipool = null;
- public int BasicWaterIndex = 0;
- public int StartWaterIndex = 0;
- public int EndWaterIndex = 0;
- public int PureBaseGroundIndex = 0;
- public List<int> SetPieceBaseGroundIndexes = new List<int>();
- public List<int> SetPieceRiverIndexes = new List<int>();
- public List<LevelPieceInformation> LevelPieceInfoPerPiece = new List<LevelPieceInformation>();
- //Source cliffs
- public List<GameObject> BottomCliffs = null;
- public GameObject BasicWaterCliffBottom = null;
- public List<GameObject>Cliffs =new List<GameObject>();
- public List<GameObject> WaterCliffs = new List<GameObject>();
- //Source cliffs index+pools
- public MultiPool CliffMultiPool = null;
- public List<int> BottomCliffsIndexes = new List<int>();
- public int BasicWaterCliffIndex = 0;
- public List<int> CliffsIndexes = new List<int>();
- public List<int> WaterCliffsIndexes = new List<int>();
- public List<CliffPieceInformation> CliffInfoPerPiece = new List<CliffPieceInformation>();
- //Bottom + Decoration
- public Pool BottomPiece = null;
- public Pool SideScene = null;
- //Cliff positions + bottom positions
- public Vector3 LeftCliffPos=new Vector3(7.5f,0,0);
- public Vector3 RightCliffPos = new Vector3(-7.25f, -8.0f, 0);
- public Vector3 BottomPartPos=new Vector3(-17.5f,-8,0);
- //Obstacles and bonus
- public Pool WaterSheep = null;
- public Pool Billboard = null;
- public Pool Ramp = null;
- public Pool Rail = null;
- public Pool Hole = null;
- public Pool Cannon = null;
- public Pool BossLaunchPad = null;
- //Internal objects
- private Queue<GameObject> _rows=new Queue<GameObject>();
- private Queue<GameObject> _bottomParts = new Queue<GameObject>();
- private Queue<GameObject> _sideScenery=new Queue<GameObject>();
- private GameObject _currentPiece = null;
- private GameObject _currentCliff = null;
- //Generation objects
- private GameObject _generationNeedle = null;
- private GameObject _generationNeedleSideScene = null;
- //Sizes and speed
- public float LevelStart = 20;
- public float LevelEnd = -100;
- public const float PieceLength = 10.0f;
- public const float PieceWidth = 10.0f;
- public const float SideLength = 60.0f;
- //Extra numbers
- public float BillboardDistanceFromRiver = 25.0f;
- //Wait rows
- private float _riverWaitRows = 0;
- private float _rampWaitRows = 0;
- private float _railWaitRows = 0;
- private float _cannonWaitRows = 0;
- private float _seaWaitRows = 0;
- private float _holeWaitRows = 0;
- //Special Pieces Of land
- private bool _firstSpecialRow = false;
- private bool _specialLand = false;
- private SpecialLands _specialLandKind;
- private float _sizeLeftSpecialLand = 50;
- private float _nextEnemyInSpecialLand = 0;
- private const float HowManySpaceForOneEnemy = 3;
- //Spawning grazing sheep
- private int _amountOfRowsToSpawnGrazingSheep = 0;
- private float _nextGrazingSheep = 0;
- private const float HowManySpaceForGrazingSheep = 4.5f;
- private const float GrazingSheepSpawnHeight = 20.0f;
- private const int AmountOfGrazeRowsAfterSea = 8;
- private bool _shouldWaitBlockBeforeSpawningGrazeSheep = false;
- //Clouds
- public GameObject CloudsLayer = null;
- public static float DistancePassed { get; private set; }
- void Start () {
- LevelManager.DeactivateSpecialPropsSpawning = GameManager.BossRunMode;
- _rows=new Queue<GameObject>();
- _generationNeedle = new GameObject("GenerationNeedle");
- _generationNeedleSideScene=new GameObject("GenerationSideNeedle");
- _generationNeedleSideScene.transform.position=_generationNeedle.transform.position = new Vector3(0, 0, LevelEnd);
- CheckAllInputFiles();
- GenerateThePoolIndexes();
- SyncAllWaitRows();
- _currentPiece = PlaceBasicPiece();
- _rows.Enqueue(_currentPiece);
- DestroyAndRegenerateLevel(true);
- StayInBounds.LeftWall = - PieceWidth * 0.5f;
- StayInBounds.RightWall = PieceWidth * 0.5f;
- DistancePassed = 0;
- }
- private void GenerateThePoolIndexes()
- {
- BasicWaterCliffIndex = CliffMultiPool.GetIndex(BasicWaterCliffBottom);
- BottomCliffsIndexes=new List<int>();
- foreach (var cliff in BottomCliffs)
- {
- BottomCliffsIndexes.Add(CliffMultiPool.GetIndex(cliff));
- }
- CliffsIndexes = new List<int>();
- foreach (var cliff in Cliffs)
- {
- CliffsIndexes.Add(CliffMultiPool.GetIndex(cliff));
- }
- WaterCliffsIndexes = new List<int>();
- foreach (var cliff in WaterCliffs)
- {
- WaterCliffsIndexes.Add(CliffMultiPool.GetIndex(cliff));
- }
- CliffInfoPerPiece = new List<CliffPieceInformation>();
- foreach (var cliff in CliffMultiPool.PoolItems)
- {
- var cliffScript = cliff.PoolObject.GetComponent<CliffPieces>();
- if (cliffScript != null)
- {
- CliffInfoPerPiece.Add(new CliffPieceInformation(cliffScript, CliffMultiPool));
- }
- }
- BasicWaterIndex = PieceMultipool.GetIndex(BasicWater);
- StartWaterIndex = PieceMultipool.GetIndex(StartWater);
- EndWaterIndex = PieceMultipool.GetIndex(EndWater);
- PureBaseGroundIndex = PieceMultipool.GetIndex(PureBaseGround);
- SetPieceBaseGroundIndexes = new List<int>();
- foreach (var ground in BaseGrounds)
- {
- SetPieceBaseGroundIndexes.Add(PieceMultipool.GetIndex(ground));
- }
- SetPieceRiverIndexes = new List<int>();
- foreach (var ground in RiverStarts)
- {
- SetPieceRiverIndexes.Add(PieceMultipool.GetIndex(ground));
- }
- LevelPieceInfoPerPiece=new List<LevelPieceInformation>();
- foreach (var ground in PieceMultipool.PoolItems)
- {
- var groundScript = ground.PoolObject.GetComponent<LevelPieces>();
- if (groundScript != null)
- {
- LevelPieceInfoPerPiece.Add(new LevelPieceInformation(groundScript, PieceMultipool));
- }
- }
- }
- //Check if all prefabs are valid
- void CheckAllInputFiles()
- {
- CheckAllGrounds();
- CheckAllRiverStarts();
- if (_generationNeedle == null)
- {
- Debug.LogError("GenerationNeedle is empty");
- Destroy(this);
- }
- if (BasicWater == null)
- {
- Debug.LogError("Basic water is empty");
- Destroy(this);
- }
- if (EndWater == null)
- {
- Debug.LogError("End water is empty");
- Destroy(this);
- }
- if (StartWater == null)
- {
- Debug.LogError("Start water is empty");
- Destroy(this);
- }
- if (PureBaseGround == null)
- {
- Debug.LogError("Purebase ground is empty");
- Destroy(this);
- }
- if (WaterSheep == null)
- {
- Debug.LogError("WaterSheep is empty");
- Destroy(this);
- }
- if (Billboard == null)
- {
- Debug.LogError("Billboard is empty");
- Destroy(this);
- }
- if (Ramp == null)
- {
- Debug.LogError("Ramp is empty");
- Destroy(this);
- }
- if (Rail == null)
- {
- Debug.LogError("Rail is empty");
- Destroy(this);
- }
- if (Cannon == null)
- {
- Debug.LogError("Cannon is empty");
- Destroy(this);
- }
- if (Hole == null)
- {
- Debug.LogError("Hole is empty");
- Destroy(this);
- }
- if (BossLaunchPad == null)
- {
- Debug.LogError("BossLaunchPad is empty");
- Destroy(this);
- }
- if (BottomCliffs.Count <= 0)
- {
- Debug.LogError("Cliff is empty");
- Destroy(this);
- }
- if (BasicWaterCliffBottom == null)
- {
- Debug.LogError("WaterCliff is empty");
- Destroy(this);
- }
- if (Cliffs.Count <= 0)
- {
- Debug.LogError("Cliffs is empty");
- Destroy(this);
- }
- if (WaterCliffs.Count <= 0)
- {
- Debug.LogError("WaterCliffs is empty");
- Destroy(this);
- }
- if (BottomPiece == null)
- {
- Debug.LogError("BottomPiece is missing");
- Destroy(this);
- }
- if (EnemySpawnScript == null)
- {
- Debug.LogError("EnemySpawnScript is missing");
- Destroy(this);
- }
- if (CliffMultiPool == null)
- {
- Debug.LogError("MultiPool is missing");
- Destroy(this);
- }
- }
- void CheckAllRiverStarts()
- {
- RiverStarts.RemoveAll(item => item == null);
- if (RiverStarts.Count <= 0)
- {
- Debug.LogError("RiverStarts are empty");
- Destroy(this);
- }
- }
- void CheckAllGrounds()
- {
- BaseGrounds.RemoveAll(item => item == null);
- if (BaseGrounds.Count <= 0)
- {
- Debug.LogError("BasicGrounds are empty");
- Destroy(this);
- }
- }
- //Set all the rows for spawning props
- void SyncAllWaitRows()
- {
- _riverWaitRows = LevelManagerScript.HowLongBeforeFirstRiver;
- _rampWaitRows = LevelManagerScript.RampDistance;
- _railWaitRows = LevelManagerScript.RailDistance;
- _cannonWaitRows = LevelManagerScript.CannonDistance;
- _seaWaitRows = LevelManagerScript.SeaDistance;
- _holeWaitRows = LevelManagerScript.HoleDistance;
- }
- private void Update()
- {
- MoveLevel();
- DestroyAndRegenerateLevel();
- }
- //Lower the waiting for props
- void LowerAllWaitRows(float amount)
- {
- if (_riverWaitRows > 0) _riverWaitRows-=amount;
- if (_rampWaitRows > 0) _rampWaitRows -= amount;
- if (_cannonWaitRows > 0) _cannonWaitRows -= amount;
- if (_holeWaitRows > 0) _holeWaitRows -= amount;
- if (_seaWaitRows > 0) _seaWaitRows -= amount;
- if (_railWaitRows > 0) _railWaitRows -= amount;
- CheckForSpecialLands();
- }
- //Check if a special kind of land needs to be placed
- void CheckForSpecialLands()
- {
- if (_seaWaitRows <= 0)
- {
- _specialLandKind = SpecialLands.Sea;
- _specialLand = true;
- _firstSpecialRow = true;
- _sizeLeftSpecialLand = LevelManagerScript.SeaLenght;
- _nextEnemyInSpecialLand = WaterSheepScript.Radius;
- _seaWaitRows = LevelManagerScript.SeaDistance;
- }
- }
- //Give a piece out of the basic list. Give default flat piece if needed
- GameObject PlaceBasicPiece(bool normalLands=false)
- {
- if (normalLands) return PlaceGivenPiece(PureBaseGroundIndex);
- var chance = SetPieceBaseGroundIndexes.Sum(ground => PieceMultipool.GetPrefab(ground).GetComponent<LevelPieces>().SpawnChance);
- int chosenPiece=0;
- var chosenNumber = Random.Range(0, chance);
- foreach (var ground in SetPieceBaseGroundIndexes)
- {
- chosenNumber -= PieceMultipool.GetPrefab(ground).GetComponent<LevelPieces>().SpawnChance;
- if (chosenNumber >= 0) continue;
- chosenPiece = ground;
- break;
- }
- return PlaceGivenPiece(chosenPiece);
- }
- //Place a river piece that connects
- GameObject PlaceRiverPiece()
- {
- var chance = SetPieceRiverIndexes.Sum(ground => PieceMultipool.GetPrefab(ground).GetComponent<LevelPieces>().SpawnChance);
- int chosenPiece=0;
- var chosenNumber = Random.Range(0, chance);
- foreach (var ground in SetPieceRiverIndexes)
- {
- chosenNumber -= PieceMultipool.GetPrefab(ground).GetComponent<LevelPieces>().SpawnChance;
- if (chosenNumber >= 0) continue;
- chosenPiece = ground;
- break;
- }
- var riverPiece=PlaceGivenPiece(chosenPiece);
- PlaceWaterBillBoard(riverPiece);
- return riverPiece;
- }
- //Place the chosen piece
- GameObject PlaceGivenPiece(int index)
- {
- var position = _generationNeedle.transform.position;
- position.z += PieceLength * 0.5f;
- var piece = PieceMultipool.MakePoolItem(position, Quaternion.identity, index);
- PlaceCliffs(position,piece);
- PlaceBottomPart(position);
- _generationNeedle.transform.Translate(0, 0, PieceLength);
- var script = piece.GetComponent<LevelPieces>();
- if (script != null)
- {
- script.IndexInPool = index;
- }
- return piece;
- }
- //Add a cliff to the side, based on previous cliffs and if there is a connection with a river
- void PlaceCliffs(Vector3 position,GameObject parent)
- {
- var requirements = parent.GetComponent<LevelPieces>().ExtraRequirements;
- var pos = LeftCliffPos;
- pos.z = position.z;
- GameObject piece = null;
- int indexCliff = -1;
- CliffPieces currentPieceCliffCode = null;
- if (_currentCliff != null)
- {
- currentPieceCliffCode = _currentCliff.GetComponent<CliffPieces>();
- }
- if (requirements.WaterFallUp)
- {
- if (currentPieceCliffCode != null)
- {
- indexCliff = CliffInfoPerPiece[currentPieceCliffCode.IndexInPool].GetNextPiece(true, CliffMultiPool);
- }
- if (indexCliff < 0)
- {
- indexCliff = CliffPieces.GiveCliffPiece(WaterCliffsIndexes,CliffMultiPool);
- }
- piece=CliffMultiPool.MakePoolItem(pos, Quaternion.identity, indexCliff);
- }
- else
- {
- if (currentPieceCliffCode != null)
- {
- indexCliff = CliffInfoPerPiece[currentPieceCliffCode.IndexInPool].GetNextPiece(false, CliffMultiPool);
- }
- if (indexCliff < 0)
- {
- indexCliff = CliffPieces.GiveCliffPiece(CliffsIndexes,CliffMultiPool);
- }
- piece = CliffMultiPool.MakePoolItem(pos, Quaternion.identity, indexCliff);
- }
- if (piece != null)
- {
- _currentCliff = piece;
- piece.transform.parent = parent.transform;
- var scale = piece.transform.localScale;
- scale.x = 1;
- piece.transform.localScale = scale;
- var script = piece.GetComponent<CliffPieces>();
- if (script != null)
- {
- script.IndexInPool = indexCliff;
- }
- }
- else
- {
- Debug.LogError("Faulty cliff");
- }
- pos = RightCliffPos;
- pos.z = position.z;
- if (requirements.WateFallDown)
- piece = CliffMultiPool.MakePoolItem(pos, Quaternion.identity, BasicWaterCliffIndex);
- else
- {
- indexCliff = CliffPieces.GiveCliffPiece(BottomCliffsIndexes, CliffMultiPool);
- piece = CliffMultiPool.MakePoolItem(pos, Quaternion.identity, indexCliff);
- }
- if (piece != null)
- {
- piece.transform.parent = parent.transform;
- var scale = piece.transform.localScale;
- scale.x = 1;
- piece.transform.localScale = scale;
- var script = piece.GetComponent<CliffPieces>();
- if (script != null)
- {
- script.IndexInPool = indexCliff;
- }
- }
- else
- {
- Debug.LogError("Faulty cliff");
- }
- }
- //Place land and river at the bottom of the cliffs
- void PlaceBottomPart(Vector3 position)
- {
- var pos = BottomPartPos;
- pos.z = position.z;
- var piece = BottomPiece.MakePoolItem(pos, Quaternion.identity);
- if (piece != null) _bottomParts.Enqueue(piece);
- }
- //Place the water tiles
- GameObject PlaceWaterLand()
- {
- if (_sizeLeftSpecialLand <= 0)
- {
- _specialLand = false;
- _amountOfRowsToSpawnGrazingSheep = AmountOfGrazeRowsAfterSea;
- _shouldWaitBlockBeforeSpawningGrazeSheep = true;
- }
- GameObject waterpiece = null;
- if (_firstSpecialRow)
- {
- waterpiece = PlaceGivenPiece(StartWaterIndex);
- _sizeLeftSpecialLand -= PieceLength*0.5f;
- }
- else if (!_specialLand)
- {
- waterpiece = PlaceGivenPiece(EndWaterIndex);
- }
- else
- {
- waterpiece = PlaceGivenPiece(BasicWaterIndex);
- PlaceWaterSheepInSea(waterpiece);
- _sizeLeftSpecialLand -= PieceLength;
- }
- if (!_firstSpecialRow) return waterpiece;
- PlaceWaterBillBoard(waterpiece);
- _firstSpecialRow = false;
- return waterpiece;
- }
- //Add swimming sheep to the water
- void PlaceWaterSheepInSea(GameObject row)
- {
- var radiusWaterSheep = WaterSheepScript.Radius;
- var posPiece = row.transform.position;
- var startposZ = posPiece.z- 0.5f * PieceLength;
- var nextSpawnZ = _nextEnemyInSpecialLand;
- const float borders = PieceWidth*0.35f;
- while (nextSpawnZ + radiusWaterSheep <= PieceLength)
- {
- var pos = new Vector3(0, posPiece.y+0.35f, startposZ+nextSpawnZ) { x = Random.Range(-borders, borders) };
- var waterSheep = WaterSheep.MakePoolItem(pos, WaterSheep.transform.rotation);
- if (waterSheep != null)
- {
- waterSheep.transform.parent = row.transform;
- var script = waterSheep.GetComponent<WaterSheepScript>();
- EnemySpawnScript.Enemies.Add(script);
- script.SpawnScript = EnemySpawnScript;
- }
- nextSpawnZ += HowManySpaceForOneEnemy;
- }
- _nextEnemyInSpecialLand = nextSpawnZ - PieceLength;
- }
- //Choose and spawn the next piece of land
- GameObject SpawnPiece(bool normalLands)
- {
- int index = -1;
- LevelPieces currentPieceCode = null;
- if (_currentPiece != null)
- {
- currentPieceCode=_currentPiece.GetComponent<LevelPieces>();
- }
- if (currentPieceCode != null)
- {
- index=LevelPieceInfoPerPiece[currentPieceCode.IndexInPool].GetNextPiece(PieceMultipool);
- }
- if (index < 0)
- {
- if (_specialLand && !normalLands)
- {
- switch (_specialLandKind)
- {
- case SpecialLands.Sea:
- return PlaceWaterLand();
- default:
- throw new ArgumentOutOfRangeException();
- }
- }
- LowerAllWaitRows(PieceLength);
- if ((_riverWaitRows > 0) || normalLands) return PlaceBasicPiece(normalLands);
- _riverWaitRows = LevelManagerScript.RiverDistance;
- return PlaceRiverPiece();
- }
- else
- {
- return PlaceGivenPiece(index);
- }
- }
- //Place the billboard to show that there will be water soon
- void PlaceWaterBillBoard(GameObject row)
- {
- var position = new Vector3(-6, 0, -BillboardDistanceFromRiver+row.transform.position.z);
- Billboard.MakePoolItem(position, Quaternion.identity);
- }
- //Movement of the level
- void MoveLevel()
- {
- DistancePassed += GameManager.LevelMoveSpeedStatic * Time.deltaTime;
- }
- //Destroy land that is out of reach and build new coming land
- void DestroyAndRegenerateLevel(bool normalGrounds=false)
- {
- while (_generationNeedle.transform.position.z < LevelStart + DistancePassed + PieceLength * 0.5)
- {
- _currentPiece = SpawnPiece(normalGrounds);
- if (!CheckIfShouldSpawnGrazingSheep(_currentPiece)&&!GameManager.BossRunMode&&!normalGrounds)
- {
- CheckIfCanAddAnyExtras(_currentPiece);
- }
- _rows.Enqueue(_currentPiece);
- }
- GameObject piece = null;
- if (_rows.Count > 0)
- {
- piece = _rows.Peek();
- if (piece != null)
- {
- while (piece.transform.position.z - 0.5f*PieceLength < LevelEnd + DistancePassed)
- {
- var row = _rows.Dequeue();
- var poolableItems = row.GetComponentsInChildren<PoolableItemMultiPool>().ToList();
- var piecePool = row.GetComponent<PoolableItemMultiPool>();
- poolableItems.Remove(piecePool);
- foreach (var poolItem in poolableItems)
- {
- if (!poolItem.PutInPool())
- Destroy(poolItem.gameObject);
- }
- if (piecePool != null)
- {
- if (!piecePool.PutInPool())
- {
- Destroy(piecePool.gameObject);
- }
- }
- else Destroy(row);
- if (_rows.Count <= 0) break;
- piece = _rows.Peek();
- if (piece == null) break;
- }
- }
- else _rows.Dequeue();
- }
- if (_bottomParts.Count > 0)
- {
- piece = _bottomParts.Peek();
- if (piece != null)
- {
- while (piece.transform.position.z - 0.5f*PieceLength < LevelEnd + DistancePassed)
- {
- var row = _bottomParts.Dequeue();
- var piecePool = row.GetComponent<PoolableItem>();
- if (piecePool != null)
- {
- if (!piecePool.PutInPool())
- {
- Destroy(piecePool.gameObject);
- }
- }
- else Destroy(row);
- if (_bottomParts.Count <= 0) return;
- piece = _bottomParts.Peek();
- if (piece == null) break;
- }
- }
- else _bottomParts.Dequeue();
- }
- while (_generationNeedleSideScene.transform.position.z < LevelStart + DistancePassed + SideLength * 0.5)
- {
- var pos = _generationNeedleSideScene.transform.position;
- pos.y = 0;
- pos.x = 30;
- var sidePiece = SideScene.MakePoolItem(pos, Quaternion.identity);
- _sideScenery.Enqueue(sidePiece);
- pos.x = -65;
- var sidePiece2 = SideScene.MakePoolItem(pos, Quaternion.identity);
- _sideScenery.Enqueue(sidePiece2);
- pos.x = 0;
- pos.z += SideLength;
- _generationNeedleSideScene.transform.position = pos;
- }
- if (_sideScenery.Count > 0)
- {
- piece = _sideScenery.Peek();
- if (piece != null)
- {
- while (piece.transform.position.z + 0.5f * SideLength < LevelEnd + DistancePassed)
- {
- var row = _sideScenery.Dequeue();
- var poolableItems = row.GetComponentsInChildren<PoolableItem>().ToList();
- var piecePool = row.GetComponent<PoolableItem>();
- poolableItems.Remove(piecePool);
- foreach (var poolItem in poolableItems)
- {
- if (!poolItem.PutInPool())
- Destroy(poolItem.gameObject);
- }
- if (piecePool != null)
- {
- if (!piecePool.PutInPool())
- {
- Destroy(piecePool.gameObject);
- }
- }
- else Destroy(row);
- if (_rows.Count <= 0) break;
- piece = _sideScenery.Peek();
- if (piece == null) break;
- }
- }
- else _sideScenery.Dequeue();
- }
- }
- //Check to add props
- void CheckIfCanAddAnyExtras(GameObject row)
- {
- if(LevelManager.DeactivateSpecialPropsSpawning)return;
- if (_rampWaitRows <= 0)
- {
- if (RampScript.CheckIfCanSpawnRampAndSpawnIt(row,Ramp))
- {
- _rampWaitRows = LevelManagerScript.RampDistance;
- return;
- }
- }
- if (_railWaitRows <= 0)
- {
- if (GrindPoleScript.CheckIfCanSpawnRailAndSpawnIt(row, PlayerScript, Rail))
- {
- _railWaitRows = LevelManagerScript.RailDistance;
- return;
- }
- }
- if (_holeWaitRows <= 0)
- {
- if (HoleScript.CheckIfCanSpawnAndSpawnIt(row,Hole))
- {
- _holeWaitRows = LevelManagerScript.HoleDistance;
- return;
- }
- }
- if (_cannonWaitRows <= 0)
- {
- if (HitLauncher.CheckIfCanSpawnAndSpawnIt(row,Cannon))
- {
- _cannonWaitRows = LevelManagerScript.CannonDistance;
- return;
- }
- }
- }
- //Add grazing sheep after water
- bool CheckIfShouldSpawnGrazingSheep(GameObject row)
- {
- if(_amountOfRowsToSpawnGrazingSheep<=0)return false;
- if (_shouldWaitBlockBeforeSpawningGrazeSheep)
- {
- _shouldWaitBlockBeforeSpawningGrazeSheep = false;
- return false;
- }
- _amountOfRowsToSpawnGrazingSheep--;
- var posPiece = row.transform.position;
- var startposZ = posPiece.z- 0.5f * PieceLength;
- var nextSpawnZ = _nextGrazingSheep;
- const float borders = PieceWidth*0.5f;
- while (nextSpawnZ + SheepMovementScript.SheepRadius <= PieceLength)
- {
- var pos = new Vector3(0, posPiece.y + GrazingSheepSpawnHeight, startposZ + nextSpawnZ) { x = Random.Range(-borders, borders) };
- var rotation = Random.Range(0.0f, 360.0f);
- EnemySpawnScript.SpawnGrazingSheep(pos,rotation);
- nextSpawnZ += HowManySpaceForGrazingSheep;
- }
- _nextGrazingSheep = nextSpawnZ - PieceLength;
- return true;
- }
- //Handle the clouds (for cannon)
- public void ShowCloudLayer(bool show)
- {
- var clouds = CloudsLayer.GetComponentsInChildren<Renderer>();
- if (show)
- {
- foreach (var cloud in clouds)
- {
- cloud.enabled = true;
- }
- }
- else
- {
- foreach (var cloud in clouds)
- {
- cloud.enabled = false;
- }
- }
- }
- void OnDestroy()
- {
- DistancePassed = 0;
- }
- public enum SpecialLands
- {
- Sea,
- }
- }
- public class CliffPieceInformation
- {
- private List<int> _nextPieces=new List<int>();
- private List<int> _nextRiverPieces = new List<int>();
- public CliffPieceInformation(CliffPieces script,MultiPool cliffPool)
- {
- _nextPieces=new List<int>();
- foreach (var nextPiece in script.ForcedNextPieces)
- {
- _nextPieces.Add(cliffPool.GetIndex(nextPiece));
- }
- _nextRiverPieces = new List<int>();
- foreach (var nextPiece in script.ForcedNextPiecesRiver)
- {
- _nextRiverPieces.Add(cliffPool.GetIndex(nextPiece));
- }
- }
- public int GetNextPiece(bool river, MultiPool cliffMultiPool)
- {
- if (river)
- {
- if (_nextRiverPieces.Count > 0)
- {
- return CliffPieces.GiveCliffPiece(_nextRiverPieces,cliffMultiPool);
- }
- else return -1;
- }
- else
- {
- if (_nextPieces.Count > 0)
- {
- return CliffPieces.GiveCliffPiece(_nextPieces,cliffMultiPool);
- }
- else return -1;
- }
- //If there is no next piece forced, because the manager is free to choose what piece they want, than it will return null
- }
- }
- public class LevelPieceInformation
- {
- private List<int> _nextPieces = new List<int>();
- public LevelPieceInformation(LevelPieces script, MultiPool piecePool)
- {
- _nextPieces = new List<int>();
- foreach (var nextPiece in script.ForcedNextSetPieces)
- {
- _nextPieces.Add(piecePool.GetIndex(nextPiece));
- }
- }
- public int GetNextPiece(MultiPool pieceMultiPool)
- {
- if (_nextPieces.Count > 0)
- {
- return LevelPieces.GiveLevelPiece(_nextPieces,pieceMultiPool);
- }
- return -1;
- //If there is no next piece forced, because the manager is free to choose what piece they want, than it will return null
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment