From 912ca06c77eff48dd624edc50a012158eb15a892 Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 29 Apr 2023 00:27:13 -0400 Subject: [PATCH] Continued to work on blue boss --- .../Assets/Boss Levels/Blue Boss.unity | 5 + .../Scripts/Bosses/BlueBossController.cs | 174 +++++++++++------- .../Assets/Scripts/Bosses/BossController.cs | 25 ++- 3 files changed, 131 insertions(+), 73 deletions(-) diff --git a/Dashing Game/Assets/Boss Levels/Blue Boss.unity b/Dashing Game/Assets/Boss Levels/Blue Boss.unity index 8b62efb..433c1fc 100644 --- a/Dashing Game/Assets/Boss Levels/Blue Boss.unity +++ b/Dashing Game/Assets/Boss Levels/Blue Boss.unity @@ -11303,6 +11303,11 @@ PrefabInstance: propertyPath: m_AnchorMax.y value: 0 objectReference: {fileID: 0} + - target: {fileID: 1253614027445701594, guid: 1179389a9652efc489c745ae80ae9854, + type: 3} + propertyPath: m_Alpha + value: 0 + objectReference: {fileID: 0} - target: {fileID: 1253614027651919904, guid: 1179389a9652efc489c745ae80ae9854, type: 3} propertyPath: m_AnchorMax.x diff --git a/Dashing Game/Assets/Scripts/Bosses/BlueBossController.cs b/Dashing Game/Assets/Scripts/Bosses/BlueBossController.cs index 22086b2..82d6672 100644 --- a/Dashing Game/Assets/Scripts/Bosses/BlueBossController.cs +++ b/Dashing Game/Assets/Scripts/Bosses/BlueBossController.cs @@ -46,6 +46,10 @@ public class BlueBossController : MonoBehaviour private float attackVel; private float curAttackSpeed; + //variables for pausing + private bool tempVelSet; + private Vector2 tempVel; + void Awake() { anims = GetComponent(); @@ -66,111 +70,139 @@ void Awake() attackTimeElapsed = 0; attackVel = 0; + + tempVelSet = false; } void Update() { - //handle animations - timeSinceLastBlink += Time.deltaTime; - - if(timeSinceLastBlink >= nextBlinkTime) + if (!PauseButton.IsPaused && BossController.Static_Reference.Health > 0) { - anims.SetTrigger("Blink"); - timeSinceLastBlink = 0; - nextBlinkTime = Random.Range(minBlinkTime, maxBlinkTime); - } + //unpause velocity if that's required + if(tempVelSet) + { + rb.velocity = tempVel; + tempVelSet = false; + } - //handle attacks - if(distanceToPlayer() < AttackRange + 1f) - attackBuildup += Time.deltaTime; - else - attackBuildup = 0; + //handle animations + timeSinceLastBlink += Time.deltaTime; - if (attackBuildup > maxAttackBuildup && !isAttacking) - { - //start attack - isAttacking = true; - attackTimeElapsed = 0f; + if (timeSinceLastBlink >= nextBlinkTime) + { + anims.SetTrigger("Blink"); + timeSinceLastBlink = 0; + nextBlinkTime = Random.Range(minBlinkTime, maxBlinkTime); + } - curAttackSpeed = 0; - attackVel = 0; + //handle attacks + if (distanceToPlayer() < AttackRange + 1f) + attackBuildup += Time.deltaTime; + else + attackBuildup = 0; - attackVector = (player.transform.position - transform.position); + if (attackBuildup > maxAttackBuildup && !isAttacking) + { + //start attack + isAttacking = true; + attackTimeElapsed = 0f; - attackParticles.Play(); - attackParticles.gameObject.transform.rotation.eulerAngles.Set(0, 0, 0); //reset particle rotation - } + curAttackSpeed = 0; + attackVel = 0; - if(isAttacking) - { - //spin the particles to make a ring effect - attackParticles.gameObject.transform.Rotate(Vector3.forward * 5f); + attackVector = (player.transform.position - transform.position); - if (distanceToPlayer() < DamageRange) - { - player.Health -= AttackStrength * Time.deltaTime; + attackParticles.Play(); + attackParticles.gameObject.transform.rotation.eulerAngles.Set(0, 0, 0); //reset particle rotation } - attackTimeElapsed += Time.deltaTime; - if(attackTimeElapsed >= AttackTime) + if (isAttacking) { - //stop attack - isAttacking = false; - attackBuildup = 0; - - attackParticles.Stop(); + //spin the particles to make a ring effect + attackParticles.gameObject.transform.Rotate(Vector3.forward * 5f); + + if (distanceToPlayer() < DamageRange) + { + player.Health -= AttackStrength * Time.deltaTime; + } + + attackTimeElapsed += Time.deltaTime; + if (attackTimeElapsed >= AttackTime) + { + //stop attack + isAttacking = false; + attackBuildup = 0; + + attackParticles.Stop(); + } } + + anims.SetBool("Attacking", isAttacking); } + else if(PauseButton.IsPaused) + { + if (!tempVelSet) + { + tempVel = rb.velocity; + tempVelSet = true; + } - anims.SetBool("Attacking", isAttacking); + rb.velocity = Vector2.zero; + } } void FixedUpdate() { - //handle movements - if (!isAttacking && distanceToPlayer() > AttackRange) - { - Vector2 movement = (player.transform.position - transform.position).normalized * (distanceToPlayer() > ConsiderRange ? MoveSpeed/2f : MoveSpeed); - rb.velocity = movement; - } - else if(isAttacking) + if (!PauseButton.IsPaused && BossController.Static_Reference.Health > 0) { - curAttackSpeed = Mathf.SmoothDamp(curAttackSpeed, AttackMoveSpeed, ref attackVel, 2f); - rb.velocity = attackVector * curAttackSpeed; - } - else - { - rb.velocity = Vector2.SmoothDamp(rb.velocity, Vector2.zero, ref smoothStopVel, 0.8f); + //handle movements + if (!isAttacking && distanceToPlayer() > AttackRange) + { + Vector2 movement = (player.transform.position - transform.position).normalized * (distanceToPlayer() > ConsiderRange ? MoveSpeed / 2f : MoveSpeed); + rb.velocity = movement; + } + else if (isAttacking) + { + curAttackSpeed = Mathf.SmoothDamp(curAttackSpeed, AttackMoveSpeed, ref attackVel, 1.2f); + rb.velocity = attackVector * curAttackSpeed; + } + else + { + rb.velocity = Vector2.SmoothDamp(rb.velocity, Vector2.zero, ref smoothStopVel, 0.8f); + } } } private void OnCollisionEnter2D(Collision2D other) { - if(other.collider.CompareTag("Player")) + if (!PauseButton.IsPaused && BossController.Static_Reference.Health > 0) { - if(player.isDashing) + if (other.collider.CompareTag("Player")) { - BossController.Static_Reference.Damage(); - - //calculate bounce-back vector - Vector2 bounce = (player.gameObject.transform.position - transform.position).normalized * bounciness; - - player.DashPower = 0; - player.gameObject.GetComponent().velocity = bounce; - player.KnockBackPlayer(bounce.x); + if (player.isDashing) + { + BossController.Static_Reference.Damage(); + + //calculate bounce-back vector + Vector2 bounce = (player.gameObject.transform.position - transform.position).normalized * bounciness; + + player.DashPower = 0; + player.gameObject.GetComponent().velocity = bounce; + player.KnockBackPlayer(bounce.x); + } + else + { + //damage player + player.Health -= AttackStrength * 1.5f; //do a little more damage to punish the player for thinking they can just touch the boss + } } - else + else if (other.collider.CompareTag("Ground") && isAttacking) { - //damage player - player.Health -= AttackStrength*1.5f; //do a little more damage to punish the player for thinking they can just touch the boss + //bounce off of wall + Vector2 direction = Vector2.Reflect(attackVector, other.contacts[0].normal); + attackVector = direction.normalized; } } - else if(other.collider.CompareTag("Ground") && isAttacking) - { - //bounce off of wall - Vector2 direction = Vector2.Reflect(attackVector, other.contacts[0].normal); - attackVector = direction.normalized; - } } private float distanceToPlayer() diff --git a/Dashing Game/Assets/Scripts/Bosses/BossController.cs b/Dashing Game/Assets/Scripts/Bosses/BossController.cs index 94796f7..41e850a 100644 --- a/Dashing Game/Assets/Scripts/Bosses/BossController.cs +++ b/Dashing Game/Assets/Scripts/Bosses/BossController.cs @@ -3,11 +3,17 @@ using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; +using TMPro; public class BossController : MonoBehaviour { public static BossController Static_Reference; + [Header("Things that need to be assigned by developer:")] + [SerializeField] private TextMeshProUGUI DisplayText; + + [Space] + [Header("The actual boss in the level")] [SerializeField] private GameObject boss; [SerializeField] private GameObject health_bar; @@ -28,6 +34,9 @@ public class BossController : MonoBehaviour [Tooltip("Maximum amount of damage the player can do to the boss")] [SerializeField] private float playerDamage; //how much the player can damage the enemy + [Tooltip("How much money the player can earn (based off of remaining health)")] + [SerializeField] private float maxMoneyPossible; + private Player player; private Animator bossAnims; private Slider health_bar_slider; @@ -102,6 +111,15 @@ void Update() timeSinceLastAttack = 0; } } + else if(_health <= 0) + { + //give the player money + + + //kill the player + + Destroy(gameObject); + } //handle boss animations bossAnims.SetBool("IsAngry", Vector2.Distance(boss.transform.position, player.gameObject.transform.position) < angryRange); @@ -115,8 +133,11 @@ void LateUpdate() public void Damage() { - _health -= player_power * playerDamage; + if (_health > 0) + { + _health -= player_power * playerDamage; - bossAnims.SetTrigger("Damage"); + bossAnims.SetTrigger("Damage"); + } } }