cShape GetRandomUsedShape(cEnemy vTempEnemy) { //intialise variable cShape vRandomShape = new cShape(); List <cShape> vShapeList = new List <cShape> (); if (vTempEnemy != null) { //reconstruct the shape we can use foreach (cShape vCurShape in vUsedForms) { if (vTempEnemy.vShape.vColor != vCurShape.vColor || vTempEnemy.vShape.vForm != vCurShape.vForm) { vShapeList.Add(vCurShape); } } } else { vShapeList = vUsedForms; } //get random shape in the list vRandomShape = vShapeList[Random.Range(0, vShapeList.Count)]; //return value return(vRandomShape); }
//try to get the matching enemy in the enemylist cEnemy GetMatchingEnemy(int vButtonIndex) { cEnemy vEnemyFound = null; //check if it match foreach (cEnemy vEnemy in vCurEnemy) { if (vEnemy.vShape.vColor == vUsedForms [vButtonIndex].vColor && vEnemy.vShape.vForm == vUsedForms [vButtonIndex].vForm) { vEnemyFound = vEnemy; } } return(vEnemyFound); }
//get the right shape to check if it match public void ButtonClick(int vButtonIndex) { //can only destroy enemy when in range if (vCurEnemy.Count > 0 && GameStarted) { //get current shape of the enemy to compare cEnemy vEnemyFound = GetMatchingEnemy(vButtonIndex); //make sure color + shape match if (vEnemyFound != null) { //make the beam the same color vBeamLight.GetComponent <SpriteRenderer> ().color = vEnemyFound.vShape.vColor; //show the animation! vBeamAnimator.SetTrigger("LaunchBeam"); //destroy current enemy in line vEnemyFound.GetComponent <Animator>().SetTrigger("Die"); //remove itself from the spawnlist foreach (GameManager2D.cSpawnList vList in vSpawnList) { if (vList.vSpawnList.Contains(vEnemyFound.gameObject)) { vList.vSpawnList.Remove(vEnemyFound.gameObject); } } //remove itself from the vCurEnemy vCurEnemy.Remove(vEnemyFound); //enemy die, so increase value EnemyDied(); } } }
public void GameOver(cEnemy vEnemy) { //need to wait for the gameover animation to finish before clicking WaitForGameOver = true; //remove other text vAlertText.SetActive(false); //stop the game GameStarted = false; //hide game over message vGameOverText.SetActive(true); //play sound PlaySound(vSndGameOver, 1f); //make sure dying enemy is above everything else vEnemy.vBorder.sortingOrder = 101; vEnemy.vInside.sortingOrder = 100; //make the target go VERY big vEnemy.GetComponent <Animator> ().SetTrigger("GameOver"); //hide vBlackBackground.SetActive(false); //go back to 2 buttons vButtonAnimator.SetBool("2Buttons", true); //hide button foreach (GameObject vButton in vButtonsList) { vButton.SetActive(false); } }
//check which mod we are and spawn a random enemy in the list on a random line cEnemy SpawnNewEnemy(int vIndex, cEnemy vTempEnemy = null) { //get a random enemy in the current game mod GameObject vNewEnemy = Instantiate(vEnemyPrefab); //modify the enemy (shape + color) cShape vNewShape = new cShape(); vNewShape = GetRandomUsedShape(vTempEnemy); //get it's componnet cEnemy vEnemy = vNewEnemy.GetComponent <cEnemy> (); //send it's shape to the enemy to be used when we try to destroy it vEnemy.vShape = vNewShape; //create enemy border vEnemy.vBorder.sprite = Resources.Load <Sprite> ("Enemies/" + vNewShape.vForm + "/Border"); //change the inside sprite on the button vEnemy.vInside.sprite = Resources.Load <Sprite> ("Enemies/" + vNewShape.vForm + "/Inside"); vEnemy.vInside.color = vNewShape.vColor; //we randomize all the enemy for all mobs but SIMPLE vEnemy.Initialise(this); //check if we spawn to a random spawn location if (vIndex == -1) { vIndex = Random.Range(0, vNbrSpawnLoc); } //spawn it on the correct location cSpawnList vRandomSpawn = vSpawnList [vIndex]; //get a random spawn position now vNewEnemy.transform.position = vRandomSpawn.vSpawnObject.transform.position; //make this enemy a child of the current line to be able to delete it when game is finish vNewEnemy.transform.parent = vRandomSpawn.vSpawnObject.transform; vRandomSpawn.vSpawnList.Add(vNewEnemy); //increase counter vEnemyCount++; //mean we are about to change round //add some more enemy to fight between each chang of colors so the rounds are longer each time //cannot have more than 50 enemy to kills if (vEnemyCount >= GetMaxNbr()) { vRound++; vRoundCounter++; //play alert sound! PlaySound(vChangingButtonSound, 1f); //show alert vAlertText.SetActive(true); //also check if we need to add new button. Cannot add more than 4x button if (vRound >= vRoundtimer && vNbrButton < 4) { vAction = "ChangeRound"; } else { vAction = "JustShuffle"; } //reset counter vEnemyCount = 0; } return(vEnemy); }