147 lines
5.8 KiB
C#
147 lines
5.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Boss1Controller : MonoBehaviour {
|
|
[SerializeField] Rigidbody2D body;
|
|
[SerializeField] float waitTime = 5f;
|
|
[SerializeField] float smoothness = 1f;
|
|
|
|
[SerializeField] int border = 64;
|
|
[SerializeField] GameObject bullet;
|
|
[SerializeField] GameObject laserBullet;
|
|
[SerializeField] GameObject bulletEffect;
|
|
|
|
[SerializeField] AudioClip shoot;
|
|
[SerializeField] AudioClip shoot2;
|
|
[SerializeField] AudioClip laserSound;
|
|
|
|
int intentX = 0;
|
|
int intentY = 0;
|
|
bool meandering = false;
|
|
AudioSource audioSource;
|
|
PLIGameController game;
|
|
|
|
// Start is called before the first frame update
|
|
void Start() {
|
|
body = GetComponent<Rigidbody2D>();
|
|
game = GameObject.FindGameObjectWithTag("PegLegIoGame").GetComponent<PLIGameController>();
|
|
audioSource = game.GetComponent<AudioSource>();
|
|
StartCoroutine(PickSomewhere());
|
|
StartCoroutine(GoCraCy());
|
|
}
|
|
|
|
IEnumerator PickSomewhere() {
|
|
while (true) {
|
|
yield return new WaitForSeconds(waitTime);
|
|
if (meandering) {
|
|
intentX = Random.Range(-256 / 2 + border, 256 / 2 - border);
|
|
intentY = Random.Range(64, 96);
|
|
}
|
|
}
|
|
}
|
|
|
|
IEnumerator GoCraCy() {
|
|
// TODO: charge laser
|
|
yield return new WaitForSeconds(5.0f);
|
|
audioSource.PlayOneShot(laserSound);
|
|
// Get blown back
|
|
intentY = 100;
|
|
for (int i = 0; i < 40; i++) {
|
|
float xDelta = 40f;
|
|
float yDelta = -40f;
|
|
float bulletSpeed = -500f;
|
|
for (int _ = 0; _ < 2; _++) {
|
|
GameObject b1 = Instantiate(laserBullet);
|
|
b1.transform.position = new Vector2(
|
|
transform.position.x + xDelta - 6,
|
|
transform.position.y + yDelta);
|
|
b1.GetComponent<Rigidbody2D>().velocity = new Vector2(0f, bulletSpeed);
|
|
|
|
GameObject b2 = Instantiate(laserBullet);
|
|
b2.transform.position = new Vector2(
|
|
transform.position.x + xDelta,
|
|
transform.position.y + yDelta + 2);
|
|
b2.GetComponent<Rigidbody2D>().velocity = new Vector2(0f, bulletSpeed);
|
|
|
|
|
|
GameObject b3 = Instantiate(laserBullet);
|
|
b3.transform.position = new Vector2(
|
|
transform.position.x + xDelta + 6,
|
|
transform.position.y + yDelta);
|
|
b3.GetComponent<Rigidbody2D>().velocity = new Vector2(0f, bulletSpeed);
|
|
|
|
xDelta *= -1f;
|
|
}
|
|
yield return new WaitForSeconds(0.06f);
|
|
}
|
|
yield return new WaitForSeconds(3.0f);
|
|
meandering = true;
|
|
while (true) {
|
|
float bulletsPerRevolution = 15f;
|
|
float bulletSpeed = 100f;
|
|
int c = 0, d = 0;
|
|
float a = 0f;
|
|
for (d = 0; d < 8; d++) {
|
|
a = -1f * Mathf.PI;
|
|
audioSource.PlayOneShot(shoot, 0.3f);
|
|
GameObject e1 = Instantiate(bulletEffect);
|
|
e1.transform.position = transform.position;
|
|
for (c = 0; c < bulletsPerRevolution; c++) {
|
|
GameObject b1 = Instantiate(bullet);
|
|
b1.transform.position = transform.position;
|
|
b1.GetComponent<Rigidbody2D>().velocity = new Vector2(bulletSpeed * Mathf.Cos(a), bulletSpeed * Mathf.Sin(a));
|
|
GameObject b2 = Instantiate(bullet);
|
|
b2.transform.position = transform.position;
|
|
b2.GetComponent<Rigidbody2D>().velocity = new Vector2(
|
|
0.5f * bulletSpeed * Mathf.Cos(a + Mathf.PI),
|
|
0.5f * bulletSpeed * Mathf.Sin(a + Mathf.PI));
|
|
a += Mathf.PI / bulletsPerRevolution;
|
|
}
|
|
yield return new WaitForSeconds(0.08f);
|
|
}
|
|
yield return new WaitForSeconds(2f);
|
|
c = 0;
|
|
a = -1f*Mathf.PI;
|
|
bulletsPerRevolution = 10f;
|
|
bulletSpeed = 60f;
|
|
while (c < 10) {
|
|
c++;
|
|
audioSource.PlayOneShot(shoot2, 0.3f);
|
|
GameObject e1 = Instantiate(bulletEffect);
|
|
e1.transform.position = transform.position;
|
|
for (int s = 1; s <= 3; s++) {
|
|
GameObject b1 = Instantiate(bullet);
|
|
b1.transform.position = transform.position;
|
|
b1.GetComponent<Rigidbody2D>().velocity = new Vector2(
|
|
s * bulletSpeed * Mathf.Cos(a),
|
|
s * bulletSpeed * Mathf.Sin(a));
|
|
GameObject b2 = Instantiate(bullet);
|
|
b2.transform.position = transform.position;
|
|
b2.GetComponent<Rigidbody2D>().velocity = new Vector2(
|
|
s * bulletSpeed * Mathf.Cos(a + Mathf.PI / 12),
|
|
s * bulletSpeed * Mathf.Sin(a + Mathf.PI / 12));
|
|
GameObject b3 = Instantiate(bullet);
|
|
b3.transform.position = transform.position;
|
|
b3.GetComponent<Rigidbody2D>().velocity = new Vector2(
|
|
s * bulletSpeed * Mathf.Cos(a - Mathf.PI / 12),
|
|
s * bulletSpeed * Mathf.Sin(a - Mathf.PI / 12));
|
|
}
|
|
a += Mathf.PI / bulletsPerRevolution;
|
|
yield return new WaitForSeconds(0.2f);
|
|
}
|
|
yield return new WaitForSeconds(1.5f);
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void FixedUpdate() {
|
|
Vector2 vel = body.velocity;
|
|
Vector2.SmoothDamp(transform.position,
|
|
new Vector2(intentX, intentY),
|
|
ref vel,
|
|
smoothness);
|
|
body.velocity = vel;
|
|
}
|
|
}
|