Commit 1c55fbcd authored by Andrew Van Buren's avatar Andrew Van Buren
Browse files

Added water boss damage/danger and boss music.

parent 0cb36019
...@@ -4,7 +4,9 @@ using System.Collections; ...@@ -4,7 +4,9 @@ using System.Collections;
public class Boss : MonoBehaviour { public class Boss : MonoBehaviour {
private Rigidbody2D rb; private Rigidbody2D rb;
public float speed = 1f; public float speed = 75f;
public float dangerSpeedMultiplier = 2f;
public int dangerTheshold = 10;
public GameObject[] waypoints; public GameObject[] waypoints;
private Transform currentWaypoint; private Transform currentWaypoint;
public float distanceThreshold = 0.5f; public float distanceThreshold = 0.5f;
...@@ -17,9 +19,13 @@ public class Boss : MonoBehaviour { ...@@ -17,9 +19,13 @@ public class Boss : MonoBehaviour {
public GameObject diety; public GameObject diety;
public Color damageColor; public Color damageColor;
public float damageColorSpeed = 8; public float damageColorSpeed = 8;
public Color dangerColor;
private SpriteRenderer sr; private SpriteRenderer sr;
private Animator animator; private Animator animator;
public AudioClip bossMusic;
private AudioSource bgm;
GameObject player; GameObject player;
private bool triggered = false; private bool triggered = false;
...@@ -34,6 +40,7 @@ public class Boss : MonoBehaviour { ...@@ -34,6 +40,7 @@ public class Boss : MonoBehaviour {
player = GameObject.FindGameObjectWithTag("Player"); player = GameObject.FindGameObjectWithTag("Player");
PickWaypoint(); PickWaypoint();
rb.isKinematic = true; rb.isKinematic = true;
bgm = Camera.main.GetComponentInChildren<AudioSource>();
} }
// Update is called once per frame // Update is called once per frame
...@@ -43,18 +50,24 @@ public class Boss : MonoBehaviour { ...@@ -43,18 +50,24 @@ public class Boss : MonoBehaviour {
PickWaypoint(); PickWaypoint();
} else { } else {
Vector2 dir = currentWaypoint.position - transform.position; Vector2 dir = currentWaypoint.position - transform.position;
Vector2 force = new Vector2(dir.x, dir.y) * speed; Vector2 force = new Vector2(dir.x, dir.y) * speed * (health < dangerTheshold ? dangerSpeedMultiplier : 1);
rb.AddForce(Vector2.ClampMagnitude(force, speed)); rb.AddForce(Vector2.ClampMagnitude(force, speed * (health < dangerTheshold ? dangerSpeedMultiplier : 1)));
} }
} }
if(Time.time > lastAttack) { if(Time.time > lastAttack) {
lastAttack = Time.time + attackCooldown + Random.Range(0, attackRandom); lastAttack = Time.time + (attackCooldown + Random.Range(0, attackRandom)) / (health < dangerTheshold ? dangerSpeedMultiplier : 1);
StartCoroutine(Attack()); StartCoroutine(Attack());
} }
sr.color = Color.Lerp(sr.color, Color.white, Time.deltaTime * damageColorSpeed); // Set color
sr.color = Color.Lerp(sr.color, (health < dangerTheshold ? dangerColor : Color.white), Time.deltaTime * damageColorSpeed);
if(Vector2.Distance(player.transform.position, transform.position) < triggerDist) { if(Vector2.Distance(player.transform.position, transform.position) < triggerDist) {
if (!triggered) {
bgm.clip = bossMusic;
bgm.Play();
}
triggered = true; triggered = true;
animator.SetBool("Moving", true); animator.SetBool("Moving", true);
rb.isKinematic = false; rb.isKinematic = false;
...@@ -76,7 +89,7 @@ public class Boss : MonoBehaviour { ...@@ -76,7 +89,7 @@ public class Boss : MonoBehaviour {
void GetHit(int amount) { void GetHit(int amount) {
if (triggered) { if (triggered) {
health -= health; health -= amount;
sr.color = damageColor; sr.color = damageColor;
if (health <= 0) { if (health <= 0) {
Die(); Die();
...@@ -85,6 +98,7 @@ public class Boss : MonoBehaviour { ...@@ -85,6 +98,7 @@ public class Boss : MonoBehaviour {
} }
void Die() { void Die() {
bgm.Stop();
Instantiate(diety, transform.position, Quaternion.identity); Instantiate(diety, transform.position, Quaternion.identity);
Destroy(gameObject); Destroy(gameObject);
} }
......
fileFormatVersion: 2
guid: 85eee806e25b00c42bd485a380e2d51d
timeCreated: 1479602249
licenseType: Free
AudioImporter:
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment