// Update is called once per frame void Update() { if (stateInt == State.ChoosingAttack) { if (princeHealth.getHealthPercent() >= .8) { attack = Random.Range(0, 3); Debug.Log(attack); stateInt = State.Attacking; } else if (princeHealth.getHealthPercent() >= .5) { attack = Random.Range(0, 4); stateInt = State.Attacking; } else if (princeHealth.getHealthPercent() > 0) { attack = Random.Range(0, 6); stateInt = State.Attacking; } else { //Play death animation here stateInt = State.Dead; princeAnimator.SetInteger("stateInt", 0); GameManager.instance.returnCamera().m_Lens.OrthographicSize = 10; GameManager.instance.returnCamera().m_Follow = player.GetComponentInChildren <CameraReturnPoint>().returnThisTransform(); Destroy(gameObject, 5f); } } }
/* * DONE: At some point (probably after animations come in for the rat boss) I need to hook up an animator to the boss and make the different placeholder warnings into animations? * or maybe I should keep the warnings in, ill see. Either way I need to implement the bite attack when the player gets/stays too close to the rat for too long. */ // Update is called once per frame void Update() { //debug method to check if the abilities when he is at half hp works correctly if (halfHealthTest) { atHalfHealth(); halfHealthTest = false; } if (bossFightStarted) { if (healthScript.getHealthPercent() <= .5) { Debug.Log(healthScript.getHealthPercent()); atHalfHealth(); } time += Time.deltaTime; staggerTime += Time.deltaTime; if (!belowHalfHealth) { if (time > attackTimer - 1.5 && moveSelected == -1) { moveSelected = Random.Range(1, moves); if (moveSelected == 2) { moveWarning.SetActive(true); spawnWarning.SetActive(false); } else { spawnWarning.SetActive(true); moveWarning.SetActive(false); } } if (time > attackTimer) { moveWarning.SetActive(false); spawnWarning.SetActive(false); time = 0f; ResetSpikes(); int numSpikes = Random.Range(1, spikes.Length); for (int i = 0; i < numSpikes; ++i) { int chosenSpike = spikeNumberList[Random.Range(0, spikeNumberList.Count)]; spikeNumberList.Remove(chosenSpike); spikes[chosenSpike].SetActive(true); spikes[chosenSpike].GetComponentInChildren <Spike_Rat>().Appear(); } switch (moveSelected) { case 1: //Spawn attack //spawnOffset = new Vector3(0, 0, 0); int randRats = Random.Range(1, numRatz + 1); for (int i = 0; i < randRats; ++i) { //spawnOffset = new Vector3(0, 2*i, 0); GameObject spawnedRat = Instantiate(rat, transform.position, transform.rotation); ratz.Add(spawnedRat); if (transform.position.x <= leftLocation.transform.position.x) { spawnedRat.GetComponent <Rigidbody2D>().velocity = (new Vector3(Random.Range(velMin, velMax), Random.Range(velMin, velMax) / 2, 0f)); } else if (transform.position.x >= originalLocation.transform.position.x) { spawnedRat.GetComponent <Rigidbody2D>().velocity = (new Vector3((Random.Range(-velMin, -velMax)), Random.Range(velMin, velMax) / 2, 0f)); } } break; case 2: //Move attack //Debug.Log("attack2"); if (!movingLeft && !movingBack) { if (transform.position.x <= leftLocation.transform.position.x) { bossAnimation.SetInteger("StateInt", 1); movingBack = true; } else if (transform.position.x >= originalLocation.transform.position.x) { bossAnimation.SetInteger("StateInt", 1); movingLeft = true; } } break; case 3: //Staggered Spawn Attack spawnOffset = new Vector3(0, 0, 0); randStaggeredRatz = Random.Range(1, numRatz + 1); spawning = true; break; default: Debug.Log("Selected move #" + moveSelected); break; } moveSelected = -1; for (int i = 0; i < ratz.Count; ++i) { if (ratz[i] != null) { ratz[i].GetComponent <Health_Script>().dealDamage(damagePerTickToSpawnedRats); } else { ratz.RemoveAt(i); } } } if (spawning && staggerTime > attackTimer / 2 && randStaggeredRatz != 0) { staggerTime = 0f; GameObject spawnedRat = Instantiate(rat, transform.position, transform.rotation); ratz.Add(spawnedRat); if (transform.position.x <= leftLocation.transform.position.x) { spawnedRat.GetComponent <Rigidbody2D>().velocity = (new Vector3(Random.Range(velMin, velMax), Random.Range(velMin, velMax), 0f)); } else if (transform.position.x >= originalLocation.transform.position.x) { spawnedRat.GetComponent <Rigidbody2D>().velocity = (new Vector3((Random.Range(-velMin, -velMax)), Random.Range(velMin, velMax), 0f)); } randStaggeredRatz -= 1; } else if (randStaggeredRatz == 0) { spawning = false; } } /* * I need to implement a case in the attack switch so that it can choose to activate its dive attack */ else if (!isDoingDivingAttack) { //placeholder warning if (time > attackTimer / attackTimeDecreaseInPhase2 - 1) { moveWarning.SetActive(true); } if (time > attackTimer / attackTimeDecreaseInPhase2 - .5) { bossAnimation.SetInteger("StateInt", 2); ratRigidBody.AddForce(transform.up * forceJumpValue); } //half health attack timer is shorter if (time > attackTimer / attackTimeDecreaseInPhase2) { moveWarning.SetActive(false); spawnWarning.SetActive(false); diveWarning.SetActive(false); time = 0f; moveSelected = Random.Range(1, moves); ResetSpikes(); int numSpikes = Random.Range(1, spikes.Length / 2); //spike attack for (int i = 0; i < numSpikes; ++i) { int chosenSpike = spikeNumberList[Random.Range(0, spikeNumberList.Count)]; spikeNumberList.Remove(chosenSpike); spikes[chosenSpike].SetActive(true); spikes[chosenSpike].GetComponentInChildren <Spike_Rat>().Appear(); } switch (moveSelected) { case 1: //Spawn attack //spawnOffset = new Vector3(0, 0, 0); int randRats = Random.Range(1, numRatz + 1); for (int i = 0; i < randRats; ++i) { //spawnOffset = new Vector3(0, 2*i, 0); GameObject spawnedRat = Instantiate(rat, transform.position, transform.rotation); ratz.Add(spawnedRat); if (transform.position.x <= leftLocation.transform.position.x) { spawnedRat.GetComponent <Rigidbody2D>().velocity = (new Vector3(Random.Range(velMin, velMax), Random.Range(velMin, velMax), 0f)); } else if (transform.position.x >= originalLocation.transform.position.x) { spawnedRat.GetComponent <Rigidbody2D>().velocity = (new Vector3((Random.Range(-velMin, -velMax)), Random.Range(velMin, velMax), 0f)); } } break; case 2: //Staggered Spawn Attack spawnOffset = new Vector3(0, 0, 0); randStaggeredRatz = Random.Range(1, numRatz + 1); spawning = true; break; case 3: //implement dive attack here isDoingDivingAttack = true; break; default: Debug.Log("Selected move #" + moveSelected); break; } //Every time the boss makes a move it should jump up in the air and move to the opposite side of the arena, unless it is doing the dive attack if (!movingLeft && !movingBack) { if (transform.position.x <= leftLocation.transform.position.x + 1) { movingBack = true; } else if (transform.position.x >= originalLocation.transform.position.x - 1) { movingLeft = true; } } for (int i = 0; i < ratz.Count; ++i) { if (ratz[i] != null) { ratz[i].GetComponent <Health_Script>().dealDamage(damagePerTickToSpawnedRats); //gotta change this into something that doesnt cause bleeding } else { ratz.RemoveAt(i); } } } if (spawning && staggerTime > attackTimer / 3 && randStaggeredRatz != 0) { staggerTime = 0f; GameObject spawnedRat = Instantiate(rat, transform.position, transform.rotation); ratz.Add(spawnedRat); if (transform.position.x <= leftLocation.transform.position.x) { spawnedRat.GetComponent <Rigidbody2D>().velocity = (new Vector3(Random.Range(velMin, velMax), Random.Range(velMin, velMax), 0f)); } else if (transform.position.x >= originalLocation.transform.position.x) { spawnedRat.GetComponent <Rigidbody2D>().velocity = (new Vector3((Random.Range(-velMin, -velMax)), Random.Range(velMin, velMax), 0f)); } randStaggeredRatz -= 1; } else if (randStaggeredRatz == 0) { spawning = false; } } //Do the dive attack logic here. //the attack sCaution1hould first make the rat dive under the water. //It should then save the current x location of the player and move under neath it. //once it reaches there, it should give a warning to let the player know that it is there. //then it should jump straight out of the water. After that, it should stay above the water and move to the other side of the arena after a moment of delay. else { if (!hasDove && !readyToJump && !isFalling) { platform.SetActive(false); transform.position = Vector3.MoveTowards ( new Vector3(transform.position.x, transform.position.y, 0), new Vector3(transform.position.x, diveLocation.position.y, 0), 16 * Time.deltaTime ); if (time > attackTimer / (2 * attackTimeDecreaseInPhase2)) { time = 0f; hasDove = true; } } else if (hasDove && !readyToJump && !isFalling) { bossAnimation.SetInteger("StateInt", 0); transform.position = Vector3.MoveTowards ( new Vector3(transform.position.x, transform.position.y, 0), new Vector3(player.transform.position.x, diveLocation.position.y, 0), 16 * Time.deltaTime ); if (time > attackTimer / (2 * attackTimeDecreaseInPhase2) - 1) { diveWarning.SetActive(true); } if (time > attackTimer / (2 * attackTimeDecreaseInPhase2)) { diveWarning.SetActive(false); time = 0f; readyToJump = true; } } else if (hasDove && readyToJump && !isFalling) { bossAnimation.SetInteger("StateInt", 2); ratRigidBody.AddForce(transform.up * forceJumpValue); if (time > .5f) { time = 0f; isFalling = true; } } else { platform.SetActive(true); if (time >= 2f) { moveWarning.SetActive(true); } if (time >= 3f) { hasDove = false; readyToJump = false; isFalling = false; isDoingDivingAttack = false; } } } if (!isDoingDivingAttack && movingLeft) { bossAnimation.SetInteger("StateInt", 1); transform.position = Vector3.MoveTowards ( new Vector3(transform.position.x, transform.position.y, 0), new Vector3(leftLocation.transform.position.x, transform.position.y, 0), 16 * Time.deltaTime ); if (transform.position.x <= leftLocation.transform.position.x) { transform.rotation = Quaternion.Euler(0, -180, 0); bossAnimation.SetInteger("StateInt", 0); movingLeft = false; //movingBack = true; } } else if (!isDoingDivingAttack && movingBack) { bossAnimation.SetInteger("StateInt", 1); transform.position = Vector3.MoveTowards ( new Vector3(transform.position.x, transform.position.y, 0), new Vector3(originalLocation.transform.position.x, transform.position.y, 0), 16 * Time.deltaTime ); if (transform.position.x >= originalLocation.transform.position.x) { transform.rotation = Quaternion.Euler(0, 0, 0); bossAnimation.SetInteger("StateInt", 0); movingLeft = false; movingBack = false; } } } }