/// <summary> /// handles the sound of losing the game. Also clears out all inventory, /// and closes any other canvases in order to display the game over screen /// correctly. /// </summary> public void GameOver() { SceneManager.LoadScene("GameOver"); this.load = GameObject.Find("Loader").GetComponent <LoadingDontDestroy>(); this.load.GetGoing(); this.player = GameObject.Find("Player"); this.playerSprite = this.player.GetComponent <SpriteRenderer>(); this.inventoryScript = this.player.GetComponent <Inventory>(); this._goldReference = GameObject.Find("Gold Canvas").GetComponent <GoldDontDestroy>(); this.inventoryCanvas = GameObject.Find("Inventory").GetComponent <Canvas>(); this.upgradesCanvas = GameObject.Find("UpgradesManager").GetComponent <Canvas>(); this.playerScript = this.player.GetComponent <PlayerScript>(); this.playerScript.PlayLoseSound(); this.playerSprite.enabled = false; for (int i = 0; i < this.inventoryScript.slots.Length; i++) { if (this.inventoryScript.isfull[i] == true) { this.inventoryScript.isfull[i] = false; foreach (Transform child in this.inventoryScript.slots[i].transform) { Destroy(child.gameObject); } } } this.inventoryCanvas.enabled = false; this.upgradesCanvas.enabled = false; this._goldReference.AndroidControls.SetActive(false); }
/// <summary> /// check if the player hit the stairs. /// If so, call the loading canvas, and change scene. /// </summary> /// <param name="collision"></param> private void OnTriggerEnter2D(Collider2D collision) { if (collision.name == "Player") { this.scene = SceneManager.GetActiveScene(); this.load = GameObject.Find("Loader").GetComponent <LoadingDontDestroy>(); switch (this.scene.name) { case "Dungeon": this.load.GetGoing(); SoundManager.PlaySound(SoundManager.Sound.downstairs); SceneManager.LoadScene("2ndLevel"); break; case "2ndLevel": this.load.GetGoing(); SoundManager.PlaySound(SoundManager.Sound.downstairs); SceneManager.LoadScene("3rdLevel"); break; default: break; } } }
/// <summary> /// Loads the home screen, and turns off all other game objects. /// </summary> public void MainMenu() { SceneManager.LoadScene("HomeScreen"); this.load = GameObject.Find("Loader").GetComponent <LoadingDontDestroy>(); this.load.GetGoing(); this.player = GameObject.Find("Player"); this.playerSprite = this.player.GetComponent <SpriteRenderer>(); this.inventoryCanvas = GameObject.Find("Inventory").GetComponent <Canvas>(); this.upgradesCanvas = GameObject.Find("UpgradesManager").GetComponent <Canvas>(); this.playerSprite.enabled = false; this.inventoryCanvas.enabled = false; this.upgradesCanvas.enabled = false; }
/// <summary> /// check if the player hit the stairs. /// If so, call the loading canvas, and change scene. /// /// Additionally, if moving from first floor to main menu, /// checks if player has the staff, and if so, initalizes the win protocol. /// </summary> /// <param name="collision"></param> private void OnTriggerEnter2D(Collider2D collision) { if (collision.name == "Player") { this.scene = SceneManager.GetActiveScene(); this.assets = GameObject.Find("AssetManager").GetComponent <AssetManager>(); this.load = GameObject.Find("Loader").GetComponent <LoadingDontDestroy>(); switch (this.scene.name) { case "Dungeon": if (this.assets.hasStaff == false) { this.assets.MainMenu(); } else { SoundManager.PlaySound(SoundManager.Sound.win); this.assets.Win(); } break; case "2ndLevel": this.load.GetGoing(); SoundManager.PlaySound(SoundManager.Sound.upstairs); SceneManager.LoadScene("Dungeon"); break; case "3rdLevel": this.load.GetGoing(); SoundManager.PlaySound(SoundManager.Sound.upstairs); SceneManager.LoadScene("2ndLevel"); break; default: break; } if ((this.scene.name == "2ndLevel") || (this.scene.name == "3rdLevel")) { this.load.MoveToStairs(); } } }
private void Start() { this.player = GameObject.Find("Player"); this.inventoryScript = this.player.GetComponent <Inventory>(); this.playerSprite = this.player.GetComponent <SpriteRenderer>(); this.playerScript = this.player.GetComponent <PlayerScript>(); this.inventoryCanvas = GameObject.Find("Inventory").GetComponent <Canvas>(); this.upgradesCanvas = GameObject.Find("UpgradesManager").GetComponent <Canvas>(); this.goldCanvas = GameObject.Find("Gold Canvas").GetComponent <Canvas>(); this.exitScreen = GameObject.Find("MenuCanvas").GetComponent <Canvas>(); this._goldReference = GameObject.Find("Gold Canvas").GetComponent <GoldDontDestroy>(); this.load = GameObject.Find("Loader").GetComponent <LoadingDontDestroy>(); this.playerSprite.enabled = false; this.inventoryCanvas.enabled = false; this.upgradesCanvas.enabled = false; this.exitScreen.enabled = false; this.hasStaff = false; this.menuOpen = false; }
/// <summary> /// returns player to max health, and set player at the beginning /// of the dungeon. /// </summary> public void Restart() { this.load = GameObject.Find("Loader").GetComponent <LoadingDontDestroy>(); this.load.GetGoing(); this.player = GameObject.Find("Player"); this.playerSprite = this.player.GetComponent <SpriteRenderer>(); this.playerScript = this.player.GetComponent <PlayerScript>(); this.inventoryCanvas = GameObject.Find("Inventory").GetComponent <Canvas>(); this.upgradesCanvas = GameObject.Find("UpgradesManager").GetComponent <Canvas>(); this._goldReference = GameObject.Find("Gold Canvas").GetComponent <GoldDontDestroy>(); this.playerSprite.enabled = true; this.playerScript.ChangeHealth(this.playerScript.maxHealth); this.inventoryCanvas.enabled = true; this.upgradesCanvas.enabled = false; this._goldReference.healthBar.SetActive(true); this._goldReference.AndroidControls.SetActive(true); SceneManager.LoadScene("Dungeon"); }
/// <summary> /// loads the winning scene and plays the winning sound. /// closes all canvases and game objects. /// </summary> public void Win() { SceneManager.LoadScene("Win"); this.load = GameObject.Find("Loader").GetComponent <LoadingDontDestroy>(); this.load.GetGoing(); this.hasStaff = false; this.player = GameObject.Find("Player"); this.playerSprite = this.player.GetComponent <SpriteRenderer>(); this.playerScript = this.player.GetComponent <PlayerScript>(); this.playerScript.PlayWinSound(); this.inventoryCanvas = GameObject.Find("Inventory").GetComponent <Canvas>(); this.upgradesCanvas = GameObject.Find("UpgradesManager").GetComponent <Canvas>(); this.goldCanvas = GameObject.Find("Gold Canvas").GetComponent <Canvas>(); this.playerSprite.enabled = false; this.inventoryCanvas.enabled = false; this.upgradesCanvas.enabled = false; this.goldCanvas.enabled = false; }
/// <summary> /// resets all stats to original values. /// </summary> public void ResetAllStats() { this.load = GameObject.Find("Loader").GetComponent <LoadingDontDestroy>(); this.load.GetGoing(); this.upgrades = GameObject.Find("UpgradesManager").GetComponent <UpgradesManager>(); this._goldReference = GameObject.Find("Gold Canvas").GetComponent <GoldDontDestroy>(); this.playerScript.maxHealth = 30; this.playerScript.attackLow = 3; this.playerScript.attackHigh = 5; this.playerScript.defensePercent = .9f; this.playerScript.defenseRaw = 0; this.playerScript.defensePotion = 2; this.playerScript.attackPotion = 2; this.playerScript.breadHeal = 15; this.playerScript.appleHeal = 5; this.playerScript.potionDuration = 30; this.playerScript.appleDefense = 0; this.upgrades.ResetValues(); this._goldReference.ChangeGoldDisplay(GoldDontDestroy.gold * -1); this._goldReference.SetValue("HP", 1); SceneManager.LoadScene("HomeScreen"); this.player = GameObject.Find("Player"); this.playerSprite = this.player.GetComponent <SpriteRenderer>(); this.inventoryCanvas = GameObject.Find("Inventory").GetComponent <Canvas>(); this.upgradesCanvas = GameObject.Find("UpgradesManager").GetComponent <Canvas>(); this.goldCanvas = GameObject.Find("Gold Canvas").GetComponent <Canvas>(); this.playerSprite.enabled = false; this.inventoryCanvas.enabled = false; this.upgradesCanvas.enabled = false; this.goldCanvas.enabled = true; }