public void BuyZombie(int index) { if (!showingTutorial || tutorialPhase == TutorialPhase.BUY_ZOMBIE) { int map = GetMapFromZombieIndex(index); if (numberUnits[map] < SCR_Config.MAX_NUMBER_ZOMBIES && SCR_Profile.brain >= SCR_Config.ZOMBIE_INFO[index].price) { GameObject zombie = SpawnZombie(index); SCR_Profile.numberZombies[index]++; SCR_Profile.SaveNumberZombies(); UpdateTotalProductionRate(); DecreaseBrain(SCR_Config.ZOMBIE_INFO[index].price); if (showingTutorial) { if (tutorialPhase == TutorialPhase.BUY_ZOMBIE) { if (index == 0) { tutorialZombie2 = zombie.transform; ShowTutorial(TutorialPhase.CLOSE_ZOMBIE_SHOP); } } } source.PlayOneShot(sndBuyZombie); } else { grpAreaIsFull.GetComponent <SCR_AutoFade>().txtTitle.text = "AREA IS FULL!"; grpAreaIsFull.SetActive(true); source.PlayOneShot(sndButton); } } }
public void FuseZombie(GameObject zombie1, GameObject zombie2) { int originalIndex = (int)zombie1.GetComponent <SCR_Zombie>().type; int zombieIndex = originalIndex + 1; int originalMap = GetMapFromZombieIndex(originalIndex); int map = GetMapFromZombieIndex(zombieIndex); if (map == originalMap || numberUnits[map] < SCR_Config.MAX_NUMBER_ZOMBIES) { Vector3 position = (zombie1.transform.position + zombie2.transform.position) * 0.5f; if (map != originalMap) { GameObject movedZombie = Instantiate(PFB_ZOMBIES[zombieIndex], backgrounds[originalMap].transform); movedZombie.transform.position = new Vector3(0, -movedZombie.GetComponent <BoxCollider2D>().offset.y, 0); movedZombie.GetComponent <SCR_Zombie>().SwitchMapEffect(); if (zombieIndex > SCR_Profile.zombieUnlocked) { pendingDiscover = true; pendingIndex = zombieIndex; } } GameObject zombie = Instantiate(PFB_ZOMBIES[zombieIndex], backgrounds[map].transform); zombie.transform.position = position; Instantiate(PFB_FUSE_EFFECT, position, PFB_FUSE_EFFECT.transform.rotation); Destroy(zombie1); Destroy(zombie2); numberUnits[map]++; numberUnits[originalMap] -= 2; SCR_Profile.numberZombies[zombieIndex]++; SCR_Profile.numberZombies[originalIndex] -= 2; SCR_Profile.SaveNumberZombies(); UpdateTotalProductionRate(); if (showingTutorial) { if (tutorialPhase == TutorialPhase.EVOLVE_ZOMBIE) { hand.SetActive(false); showingTutorial = false; SCR_Profile.finishedTutorial = true; SCR_Profile.SaveTutorial(); } } if (zombieIndex > SCR_Profile.zombieUnlocked) { if (!pendingDiscover) { cvsDiscover.GetComponent <SCR_DiscoverZombie>().ShowNewZombie(zombieIndex); cvsDiscover.SetActive(true); source.PlayOneShot(sndDiscover); } SCR_Profile.zombieUnlocked = zombieIndex; SCR_Profile.SaveZombieUnlocked(); scrZombieShop.RefreshUnlocked(); scrUpgradeShop.RefreshUnlocked(); } source.PlayOneShot(sndEvolve); } else { grpAreaIsFull.GetComponent <SCR_AutoFade>().txtTitle.text = "NEXT AREA IS FULL!"; grpAreaIsFull.SetActive(true); } }
public void Update() { if (!cvsDiscover.activeSelf && !cvsUpgrade.activeSelf && !cvsCollection.activeSelf && !scrZombieShop.gameObject.activeSelf) { if (Input.GetMouseButtonDown(0)) { Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition); RaycastHit2D bestHit = FindBestHit(pos); if (bestHit.transform != null) { if (bestHit.transform.parent != null) { SCR_Tomb scrTomb = bestHit.transform.parent.GetComponent <SCR_Tomb>(); if (scrTomb != null) { GameObject zombie = SpawnZombie(0); // numberUnits[0]++ in SpawnZombie(0) numberUnits[0]--; SCR_Profile.numberZombies[0]++; SCR_Profile.SaveNumberZombies(); SCR_Profile.numberTombs--; SCR_Profile.SaveNumberTombs(); UpdateTotalProductionRate(); zombie.transform.position = bestHit.transform.parent.position; Destroy(bestHit.transform.parent.gameObject); if (showingTutorial) { if (tutorialPhase == TutorialPhase.OPEN_TOMB) { tutorialZombie1 = zombie.transform; ShowTutorial(TutorialPhase.OPEN_ZOMBIE_SHOP); } } source.PlayOneShot(sndTapTomb); } } if (!showingTutorial || tutorialPhase == TutorialPhase.EVOLVE_ZOMBIE) { SCR_Zombie scrZombie = bestHit.transform.GetComponent <SCR_Zombie>(); if (scrZombie != null) { selectedZombie = bestHit.transform; offsetX = selectedZombie.position.x - pos.x; offsetY = selectedZombie.position.y - pos.y; selectedZombie.GetComponent <Collider2D>().enabled = false; scrZombie.StopMoving(); scrZombie.state = ZombieState.USER_MOVE; } } } } if (Input.GetMouseButton(0)) { if (selectedZombie != null) { Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition); float x = Mathf.Clamp(pos.x + offsetX, GARDEN_LEFT, GARDEN_RIGHT); float y = Mathf.Clamp(pos.y + offsetY, GARDEN_BOTTOM, GARDEN_TOP); float z = y; selectedZombie.position = new Vector3(x, y, z); } } if (Input.GetMouseButtonUp(0)) { if (selectedZombie != null) { Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition); RaycastHit2D bestHit = FindBestHit(pos); if (bestHit.transform != null) { SCR_Zombie scrZombie = bestHit.transform.GetComponent <SCR_Zombie>(); if (scrZombie != null) { if (selectedZombie.GetComponent <SCR_Zombie>().type == scrZombie.type) { if (scrZombie.type != SCR_Zombie.LAST_TYPE) { FuseZombie(selectedZombie.gameObject, scrZombie.gameObject); } else { grpPerfect.SetActive(true); } } } } selectedZombie.GetComponent <SCR_Zombie>().state = ZombieState.AUTO_MOVE; selectedZombie.GetComponent <Collider2D>().enabled = true; selectedZombie = null; } } } if (!showingTutorial) { tombSpawnTime += Time.deltaTime; if (tombSpawnTime >= SCR_Config.TOMB_SPAWN_INTERVAL && numberUnits[0] < SCR_Config.MAX_NUMBER_ZOMBIES) { SpawnTomb(); tombSpawnTime = 0; SCR_Profile.numberTombs++; SCR_Profile.SaveNumberTombs(); } productionTime += Time.deltaTime; if (productionTime >= 1) { IncreaseBrain(totalProductionRate); productionTime = 0; } } }