aboutsummaryrefslogtreecommitdiff
path: root/Assets/Scripts/Brain.cs
diff options
context:
space:
mode:
authorTom Harley2018-09-03 23:34:21 +0100
committerTom Harley2018-09-03 23:36:01 +0100
commit5440734d820606b29a795c46172ade5d7eba8efb (patch)
tree85867f40afb02cfa2a5028b515ed0a195866b7e9 /Assets/Scripts/Brain.cs
downloadpowerless-5440734d820606b29a795c46172ade5d7eba8efb.tar.gz
powerless-5440734d820606b29a795c46172ade5d7eba8efb.zip

Initial commit

Diffstat (limited to 'Assets/Scripts/Brain.cs')
-rw-r--r--Assets/Scripts/Brain.cs57
1 files changed, 57 insertions, 0 deletions
diff --git a/Assets/Scripts/Brain.cs b/Assets/Scripts/Brain.cs
new file mode 100644
index 0000000..36c2493
--- /dev/null
+++ b/Assets/Scripts/Brain.cs
@@ -0,0 +1,57 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class Brain : MonoBehaviour {
+ public float chargeInterval = 2f;
+ public float chargeDuration = 1f;
+
+ public GameObject wavePrefab;
+ public Vector2 waveSpawnOffset = new Vector2(0, 0);
+ public Vector2 waveVelocity = new Vector2(1, 0);
+
+ private bool charging = false;
+ private bool facingRight;
+
+ private Animator anim;
+
+ public bool Charging {
+ get {
+ return charging;
+ }
+
+ set {
+ charging = value;
+ if (anim) anim.SetBool("charging", value);
+ }
+ }
+
+ void Start() {
+ anim = GetComponent<Animator>();
+
+ facingRight = !GetComponent<SpriteRenderer>().flipX;
+ }
+
+ void Awake() {
+ Idle();
+ }
+
+ void Idle() {
+ Charging = false;
+ Invoke("Charge", chargeInterval);
+ }
+
+ void Charge() {
+ Charging = true;
+ Invoke("Fire", chargeDuration);
+ }
+
+ void Fire() {
+ Vector2 spawnPosition = this.transform.position + (Vector3)((facingRight ? 1 : -1) * waveSpawnOffset);
+ GameObject wave = Instantiate(wavePrefab, spawnPosition, Quaternion.identity);
+ Rigidbody2D wrb = wave.GetComponent<Rigidbody2D>();
+ wrb.velocity = waveVelocity * (facingRight ? 1 : -1);
+
+ Idle();
+ }
+}