init
This commit is contained in:
commit
16da8e4dde
333 changed files with 109229 additions and 0 deletions
50
Assets/Scripts/AudioManager.cs
Normal file
50
Assets/Scripts/AudioManager.cs
Normal file
|
@ -0,0 +1,50 @@
|
|||
using UnityEngine.Audio;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class AudioManager : MonoBehaviour{
|
||||
|
||||
public Sound[] sounds;
|
||||
|
||||
public static AudioManager instance;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
if (instance == null)
|
||||
instance = this;
|
||||
else{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
foreach(Sound s in sounds){
|
||||
s.source = gameObject.AddComponent<AudioSource>();
|
||||
s.source.clip = s.clip;
|
||||
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
s.source.loop = s.loop;
|
||||
|
||||
s.source.outputAudioMixerGroup = s.mixerGroup;
|
||||
}
|
||||
}
|
||||
|
||||
public void Play(string name){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogError("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
s.source.Play();
|
||||
}
|
||||
public void Stop(string name){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogError("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
s.source.Stop();
|
||||
}
|
||||
}
|
11
Assets/Scripts/AudioManager.cs.meta
Normal file
11
Assets/Scripts/AudioManager.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0172a948598e1f445b0b71140795ca3a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
27
Assets/Scripts/CameraController.cs
Normal file
27
Assets/Scripts/CameraController.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraController : MonoBehaviour{
|
||||
|
||||
[HideInInspector]
|
||||
public Transform follow;
|
||||
public Vector2 minCamPos, maxCamPos;
|
||||
public float smoothTime;
|
||||
|
||||
private Vector2 velocity;
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate(){
|
||||
|
||||
float posX = Mathf.SmoothDamp(transform.position.x,
|
||||
follow.transform.position.x, ref velocity.x, smoothTime);
|
||||
float posY = Mathf.SmoothDamp(transform.position.y,
|
||||
follow.transform.position.y, ref velocity.y, smoothTime);
|
||||
|
||||
transform.position = new Vector3(
|
||||
Mathf.Clamp(posX, minCamPos.x, maxCamPos.x),
|
||||
Mathf.Clamp(posY, minCamPos.y, maxCamPos.y),
|
||||
transform.position.z);
|
||||
}
|
||||
}
|
11
Assets/Scripts/CameraController.cs.meta
Normal file
11
Assets/Scripts/CameraController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c789538f25fb0cf4c9679f036d03abe1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
32
Assets/Scripts/CameraShake.cs
Normal file
32
Assets/Scripts/CameraShake.cs
Normal file
|
@ -0,0 +1,32 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraShake : MonoBehaviour{
|
||||
|
||||
float shakeAmount = 0;
|
||||
|
||||
public void Shake(float amt, float length){
|
||||
shakeAmount = amt;
|
||||
InvokeRepeating("DoShake", 0, 0.01f);
|
||||
Invoke("StopShake", length);
|
||||
}
|
||||
|
||||
void DoShake(){
|
||||
if (shakeAmount > 0){
|
||||
Vector3 camPos = transform.position;
|
||||
|
||||
float offsetX = Random.value * shakeAmount * 2 - shakeAmount;
|
||||
float offsetY = Random.value * shakeAmount * 2 - shakeAmount;
|
||||
camPos.x += offsetX;
|
||||
camPos.y += offsetY;
|
||||
|
||||
transform.position = camPos;
|
||||
}
|
||||
}
|
||||
|
||||
void StopShake(){
|
||||
CancelInvoke(nameof(DoShake));
|
||||
transform.localPosition = Vector3.zero;
|
||||
}
|
||||
}
|
11
Assets/Scripts/CameraShake.cs.meta
Normal file
11
Assets/Scripts/CameraShake.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8c484cba00461a54c9081bd839a58e40
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
70
Assets/Scripts/CarController.cs
Normal file
70
Assets/Scripts/CarController.cs
Normal file
|
@ -0,0 +1,70 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CarController : MonoBehaviour{
|
||||
|
||||
public GameController gameController;
|
||||
public float invulnerableTime = 2f;
|
||||
Animator anim;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
anim = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D col){
|
||||
if(col.CompareTag("Player")){
|
||||
gameController.playered = true;
|
||||
}
|
||||
}
|
||||
void OnTriggerExit2D(Collider2D col){
|
||||
if (col.CompareTag("Player")){
|
||||
gameController.playered = false;
|
||||
}
|
||||
}
|
||||
bool damaged;
|
||||
void OnCollisionEnter2D(Collision2D col){
|
||||
if (col.gameObject.CompareTag("Enemy") && !damaged || col.gameObject.CompareTag("BigEnemy") && !damaged){
|
||||
if(gameController.level == 2){
|
||||
gameController.health.TakeDamage(3.5f);
|
||||
}else if(gameController.level == 3){
|
||||
gameController.health.TakeDamage(5);
|
||||
}else{
|
||||
gameController.health.TakeDamage(2);
|
||||
}
|
||||
AudioManager.instance.Play("Hit");
|
||||
anim.SetBool("Damaged", true);
|
||||
damaged = true;
|
||||
Invoke(nameof(Damaged), invulnerableTime);
|
||||
}
|
||||
if (col.gameObject.CompareTag("RocketEnemy") && !damaged){
|
||||
if (gameController.level == 2){
|
||||
gameController.health.TakeDamage(7f);
|
||||
}else if (gameController.level == 3){
|
||||
gameController.health.TakeDamage(8.5f);
|
||||
}else{
|
||||
gameController.health.TakeDamage(4);
|
||||
}
|
||||
AudioManager.instance.Play("Hit");
|
||||
anim.SetBool("Damaged", true);
|
||||
damaged = true;
|
||||
Invoke(nameof(Damaged), invulnerableTime);
|
||||
}
|
||||
}
|
||||
|
||||
void Damaged(){
|
||||
damaged = false;
|
||||
anim.SetBool("Damaged", false);
|
||||
}
|
||||
|
||||
void OnCollisionStay2D(Collision2D col){
|
||||
if (col.gameObject.CompareTag("CircleEnemy") && !damaged){
|
||||
if (col.gameObject.GetComponent<CircleEnemyController>().hp == 2){
|
||||
gameController.health.TakeDamage(0.025f);
|
||||
}else if (col.gameObject.GetComponent<CircleEnemyController>().hp == 1){
|
||||
gameController.health.TakeDamage(0.01f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/CarController.cs.meta
Normal file
11
Assets/Scripts/CarController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 17f8d09ed45bcce4b97d65d392616a09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
37
Assets/Scripts/DeathParticle.cs
Normal file
37
Assets/Scripts/DeathParticle.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DeathParticle : MonoBehaviour, IPooledObject{
|
||||
|
||||
public Color level1Color;
|
||||
public Color level2Color;
|
||||
public Color level3Color;
|
||||
|
||||
GameController gameController;
|
||||
|
||||
// Start is called before the first frame update
|
||||
public void OnObjectSpawn(){
|
||||
gameController = FindObjectOfType<GameController>();
|
||||
if (gameController.level == 1 || gameController.level == 0){
|
||||
ParticleSystem ps = GetComponent<ParticleSystem>();
|
||||
var main = ps.main;
|
||||
main.startColor = level1Color;
|
||||
}
|
||||
if (gameController.level == 2){
|
||||
ParticleSystem ps = GetComponent<ParticleSystem>();
|
||||
var main = ps.main;
|
||||
main.startColor = level2Color;
|
||||
}
|
||||
if (gameController.level == 3){
|
||||
ParticleSystem ps = GetComponent<ParticleSystem>();
|
||||
var main = ps.main;
|
||||
main.startColor = level3Color;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/DeathParticle.cs.meta
Normal file
11
Assets/Scripts/DeathParticle.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c1bdd9ed634fb994e98a257b9b5fb160
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Enemies.meta
Normal file
8
Assets/Scripts/Enemies.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b11184eda0db7eb4284b3853df884884
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
144
Assets/Scripts/Enemies/BigEnemyController.cs
Normal file
144
Assets/Scripts/Enemies/BigEnemyController.cs
Normal file
|
@ -0,0 +1,144 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BigEnemyController : MonoBehaviour, IPooledObject{
|
||||
|
||||
public float speed;
|
||||
public GameObject healthBar;
|
||||
public GameObject enemy;
|
||||
public float bulletDamage;
|
||||
public float bigBulletDamage;
|
||||
public GameObject spawnParticles;
|
||||
public Color level1Color;
|
||||
public Color level2Color;
|
||||
public Color level3Color;
|
||||
public SpriteRenderer spriteRenderer;
|
||||
|
||||
Animator anim;
|
||||
bool ready;
|
||||
bool spawned;
|
||||
BoxCollider2D boxCol;
|
||||
public int maxHp;
|
||||
float hp;
|
||||
|
||||
GameController gameController;
|
||||
Rigidbody2D rb2d;
|
||||
Transform target;
|
||||
Vector2 targetPos;
|
||||
|
||||
public void OnObjectSpawn(){
|
||||
gameController = FindObjectOfType<GameController>();
|
||||
if (gameController.level == 1 || gameController.level == 0){
|
||||
spriteRenderer.color = level1Color;
|
||||
ParticleSystem ps = spawnParticles.GetComponent<ParticleSystem>();
|
||||
var main = ps.main;
|
||||
main.startColor = level1Color;
|
||||
}
|
||||
if (gameController.level == 2){
|
||||
spriteRenderer.color = level2Color;
|
||||
ParticleSystem ps = spawnParticles.GetComponent<ParticleSystem>();
|
||||
var main = ps.main;
|
||||
main.startColor = level2Color;
|
||||
}
|
||||
if (gameController.level == 3){
|
||||
spriteRenderer.color = level3Color;
|
||||
ParticleSystem ps = spawnParticles.GetComponent<ParticleSystem>();
|
||||
var main = ps.main;
|
||||
main.startColor = level3Color;
|
||||
}
|
||||
anim = GetComponent<Animator>();
|
||||
Invoke(nameof(StopAnimation), 1f);
|
||||
anim.SetBool("Spawned", false);
|
||||
Invoke(nameof(Ready), 2f);
|
||||
ready = false;
|
||||
spawned = false;
|
||||
enemy.transform.rotation = Quaternion.Euler(Vector3.zero);
|
||||
boxCol = GetComponent<BoxCollider2D>();
|
||||
boxCol.enabled = false;
|
||||
spawnParticles.SetActive(true);
|
||||
spawnParticles.GetComponent<ParticleSystem>().Play();
|
||||
hp = maxHp;
|
||||
healthBar.transform.localScale = new Vector2(hp / maxHp, healthBar.transform.localScale.y);
|
||||
target = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
|
||||
rb2d = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if (ready){
|
||||
targetPos = target.position - transform.position;
|
||||
float rotZ = Mathf.Atan2(targetPos.y, targetPos.x) * Mathf.Rad2Deg;
|
||||
enemy.transform.rotation = Quaternion.Euler(0f, 0f, rotZ);
|
||||
}else if (spawned){
|
||||
Vector2 targetPos = target.transform.position - transform.position;
|
||||
float rotZ = Mathf.Atan2(targetPos.y, targetPos.x) * Mathf.Rad2Deg;
|
||||
enemy.transform.rotation = Quaternion.Euler(0f, 0f, rotZ - 90);
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate(){
|
||||
if (ready){
|
||||
rb2d.MovePosition(rb2d.position + (targetPos.normalized * speed * Time.fixedDeltaTime));
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D col){
|
||||
if(col.CompareTag("Bullet")){
|
||||
if(hp > 0 && hp > bulletDamage){
|
||||
hp -= bulletDamage;
|
||||
healthBar.transform.localScale = new Vector2(hp / maxHp, healthBar.transform.localScale.y);
|
||||
}else if(hp > 0 && hp <= bulletDamage){
|
||||
hp = 0;
|
||||
ScreenShake.Shake(1f, .15f);
|
||||
AudioManager.instance.Play("EnemyDeath");
|
||||
ObjectPooler.Instance.SpawnFromPool("EnemyDeath", transform.position, Quaternion.identity);
|
||||
healthBar.transform.localScale = new Vector2(hp / maxHp, healthBar.transform.localScale.y);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
else if(hp <= 0){
|
||||
ScreenShake.Shake(1f, .15f);
|
||||
AudioManager.instance.Play("EnemyDeath");
|
||||
ObjectPooler.Instance.SpawnFromPool("EnemyDeath", transform.position, Quaternion.identity);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
if (col.CompareTag("BigBullet")){
|
||||
if (hp > 0 && hp > bulletDamage){
|
||||
hp -= bigBulletDamage;
|
||||
healthBar.transform.localScale = new Vector2(hp / maxHp, healthBar.transform.localScale.y);
|
||||
}else if (hp > 0 && hp <= bulletDamage){
|
||||
hp = 0;
|
||||
ScreenShake.Shake(1f, .15f);
|
||||
AudioManager.instance.Play("EnemyDeath");
|
||||
ObjectPooler.Instance.SpawnFromPool("EnemyDeath", transform.position, Quaternion.identity);
|
||||
healthBar.transform.localScale = new Vector2(hp / maxHp, healthBar.transform.localScale.y);
|
||||
gameObject.SetActive(false);
|
||||
}else if (hp == 0){
|
||||
ScreenShake.Shake(1f, .15f);
|
||||
AudioManager.instance.Play("EnemyDeath");
|
||||
ObjectPooler.Instance.SpawnFromPool("EnemyDeath", transform.position, Quaternion.identity);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
#region OnSpawn
|
||||
void StopAnimation(){
|
||||
anim.SetBool("Spawned", true);
|
||||
}
|
||||
|
||||
void Ready(){
|
||||
spawned = true;
|
||||
Invoke(nameof(StartRunning), 0.5f);
|
||||
Invoke(nameof(EnableCollider), 0.25f);
|
||||
}
|
||||
|
||||
void EnableCollider(){
|
||||
boxCol.enabled = true;
|
||||
}
|
||||
|
||||
void StartRunning(){
|
||||
ready = true;
|
||||
}
|
||||
#endregion
|
||||
}
|
11
Assets/Scripts/Enemies/BigEnemyController.cs.meta
Normal file
11
Assets/Scripts/Enemies/BigEnemyController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 02c265ccaecb24e4bb6817b3fcbc4467
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
119
Assets/Scripts/Enemies/CircleEnemyController.cs
Normal file
119
Assets/Scripts/Enemies/CircleEnemyController.cs
Normal file
|
@ -0,0 +1,119 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CircleEnemyController : MonoBehaviour, IPooledObject{
|
||||
|
||||
public float speed;
|
||||
public GameObject spikes2;
|
||||
[HideInInspector]
|
||||
public int hp, maxHp = 2;
|
||||
public GameObject spawnParticles;
|
||||
public Color level1Color;
|
||||
public Color level2Color;
|
||||
public Color level3Color;
|
||||
public SpriteRenderer[] spriteRenderers;
|
||||
|
||||
GameController gameController;
|
||||
Animator anim;
|
||||
CircleCollider2D cirCol;
|
||||
bool ready;
|
||||
Rigidbody2D rb2d;
|
||||
Transform target;
|
||||
Vector2 targetPos;
|
||||
|
||||
public void OnObjectSpawn(){
|
||||
gameController = FindObjectOfType<GameController>();
|
||||
if (gameController.level == 1 || gameController.level == 0){
|
||||
foreach(SpriteRenderer r in spriteRenderers){
|
||||
r.color = level1Color;
|
||||
}
|
||||
ParticleSystem ps = spawnParticles.GetComponent<ParticleSystem>();
|
||||
var main = ps.main;
|
||||
main.startColor = level1Color;
|
||||
}
|
||||
if (gameController.level == 2){
|
||||
foreach (SpriteRenderer r in spriteRenderers){
|
||||
r.color = level2Color;
|
||||
}
|
||||
ParticleSystem ps = spawnParticles.GetComponent<ParticleSystem>();
|
||||
var main = ps.main;
|
||||
main.startColor = level2Color;
|
||||
}
|
||||
if (gameController.level == 3){
|
||||
foreach (SpriteRenderer r in spriteRenderers){
|
||||
r.color = level3Color;
|
||||
}
|
||||
ParticleSystem ps = spawnParticles.GetComponent<ParticleSystem>();
|
||||
var main = ps.main;
|
||||
main.startColor = level3Color;
|
||||
}
|
||||
anim = GetComponent<Animator>();
|
||||
anim.SetBool("Spawned", false);
|
||||
cirCol = GetComponent<CircleCollider2D>();
|
||||
cirCol.enabled = false;
|
||||
hp = maxHp;
|
||||
spikes2.SetActive(true);
|
||||
target = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
|
||||
rb2d = GetComponent<Rigidbody2D>();
|
||||
ready = false;
|
||||
Invoke(nameof(StopAnimation), 1f);
|
||||
Invoke(nameof(Ready), 2f);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
targetPos = target.position - transform.position;
|
||||
}
|
||||
|
||||
void FixedUpdate(){
|
||||
if (ready){
|
||||
rb2d.MovePosition(rb2d.position + (targetPos.normalized * speed * Time.fixedDeltaTime));
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D col){
|
||||
if (col.CompareTag("Bullet") && hp == 2){
|
||||
spikes2.SetActive(false);
|
||||
hp = 1;
|
||||
}else if(col.CompareTag("Bullet") && hp == 1){
|
||||
gameObject.SetActive(false);
|
||||
AudioManager.instance.Play("EnemyDeath");
|
||||
hp = 0;
|
||||
ScreenShake.Shake(1f, .15f);
|
||||
ObjectPooler.Instance.SpawnFromPool("CircleEnemyDeath", transform.position, Quaternion.identity);
|
||||
}
|
||||
if (col.CompareTag("BigBullet") && hp == 2){
|
||||
gameObject.SetActive(false);
|
||||
AudioManager.instance.Play("EnemyDeath");
|
||||
hp = 0;
|
||||
ScreenShake.Shake(1f, .15f);
|
||||
ObjectPooler.Instance.SpawnFromPool("CircleEnemyDeath", transform.position, Quaternion.identity);
|
||||
}else if (col.CompareTag("BigBullet") && hp == 1){
|
||||
gameObject.SetActive(false);
|
||||
AudioManager.instance.Play("EnemyDeath");
|
||||
hp = 0;
|
||||
ScreenShake.Shake(1f, .15f);
|
||||
ObjectPooler.Instance.SpawnFromPool("CircleEnemyDeath", transform.position, Quaternion.identity);
|
||||
}
|
||||
}
|
||||
|
||||
#region OnSpawn
|
||||
void StopAnimation(){
|
||||
anim.SetBool("Spawned", true);
|
||||
}
|
||||
|
||||
void Ready(){
|
||||
Invoke(nameof(StartRunning), 0.5f);
|
||||
Invoke(nameof(EnableCollider), 0.25f);
|
||||
}
|
||||
|
||||
void EnableCollider(){
|
||||
cirCol.enabled = true;
|
||||
}
|
||||
|
||||
void StartRunning(){
|
||||
ready = true;
|
||||
}
|
||||
#endregion
|
||||
}
|
11
Assets/Scripts/Enemies/CircleEnemyController.cs.meta
Normal file
11
Assets/Scripts/Enemies/CircleEnemyController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e63ace73998409c449c98a0737a00844
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
104
Assets/Scripts/Enemies/EnemyController.cs
Normal file
104
Assets/Scripts/Enemies/EnemyController.cs
Normal file
|
@ -0,0 +1,104 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class EnemyController : MonoBehaviour, IPooledObject{
|
||||
|
||||
public float speed;
|
||||
public GameObject enemy;
|
||||
public GameObject spawnParticles;
|
||||
public Color level1Color;
|
||||
public Color level2Color;
|
||||
public Color level3Color;
|
||||
|
||||
GameController gameController;
|
||||
Animator anim;
|
||||
bool ready;
|
||||
bool spawned;
|
||||
BoxCollider2D boxCol;
|
||||
Rigidbody2D rb2d;
|
||||
Transform target;
|
||||
Vector2 targetPos;
|
||||
|
||||
public void OnObjectSpawn(){
|
||||
gameController = FindObjectOfType<GameController>();
|
||||
if(gameController.level == 1 || gameController.level == 0){
|
||||
GetComponentInChildren<SpriteRenderer>().color = level1Color;
|
||||
ParticleSystem ps = spawnParticles.GetComponent<ParticleSystem>();
|
||||
var main = ps.main;
|
||||
main.startColor = level1Color;
|
||||
}
|
||||
if (gameController.level == 2){
|
||||
GetComponentInChildren<SpriteRenderer>().color = level2Color;
|
||||
ParticleSystem ps = spawnParticles.GetComponent<ParticleSystem>();
|
||||
var main = ps.main;
|
||||
main.startColor = level2Color;
|
||||
}
|
||||
if (gameController.level == 3){
|
||||
GetComponentInChildren<SpriteRenderer>().color = level3Color;
|
||||
ParticleSystem ps = spawnParticles.GetComponent<ParticleSystem>();
|
||||
var main = ps.main;
|
||||
main.startColor = level3Color;
|
||||
}
|
||||
anim = GetComponent<Animator>();
|
||||
anim.SetBool("Spawned", false);
|
||||
target = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
|
||||
rb2d = GetComponent<Rigidbody2D>();
|
||||
boxCol = GetComponentInChildren<BoxCollider2D>();
|
||||
boxCol.enabled = false;
|
||||
spawnParticles.SetActive(true);
|
||||
spawnParticles.GetComponent<ParticleSystem>().Play();
|
||||
ready = false;
|
||||
spawned = false;
|
||||
Invoke(nameof(StopAnimation), 1f);
|
||||
Invoke(nameof(Ready), 2f);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if (ready){
|
||||
targetPos = target.position - transform.position;
|
||||
float rotZ = Mathf.Atan2(targetPos.y, targetPos.x) * Mathf.Rad2Deg;
|
||||
enemy.transform.rotation = Quaternion.Euler(0f, 0f, rotZ);
|
||||
}else if (spawned){
|
||||
Vector2 targetPos = target.transform.position - transform.position;
|
||||
float rotZ = Mathf.Atan2(targetPos.y, targetPos.x) * Mathf.Rad2Deg;
|
||||
enemy.transform.rotation = Quaternion.Euler(0f, 0f, rotZ);
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate(){
|
||||
if (ready){
|
||||
rb2d.MovePosition(rb2d.position + (targetPos.normalized * speed * Time.fixedDeltaTime));
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D col){
|
||||
if (col.CompareTag("Bullet") || col.CompareTag("BigBullet")){
|
||||
ScreenShake.Shake(1f, .15f);
|
||||
AudioManager.instance.Play("EnemyDeath");
|
||||
ObjectPooler.Instance.SpawnFromPool("EnemyDeath", col.transform.position, Quaternion.identity);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
#region OnSpawn
|
||||
void StopAnimation(){
|
||||
anim.SetBool("Spawned", true);
|
||||
}
|
||||
|
||||
void Ready(){
|
||||
spawned = true;
|
||||
Invoke(nameof(StartRunning), 0.5f);
|
||||
Invoke(nameof(EnableCollider), 0.25f);
|
||||
}
|
||||
|
||||
void EnableCollider(){
|
||||
boxCol.enabled = true;
|
||||
}
|
||||
|
||||
void StartRunning(){
|
||||
ready = true;
|
||||
}
|
||||
#endregion
|
||||
}
|
11
Assets/Scripts/Enemies/EnemyController.cs.meta
Normal file
11
Assets/Scripts/Enemies/EnemyController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 238ef62119f1ac144b9517dd0dfa510d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
121
Assets/Scripts/Enemies/RocketEnemy.cs
Normal file
121
Assets/Scripts/Enemies/RocketEnemy.cs
Normal file
|
@ -0,0 +1,121 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class RocketEnemy : MonoBehaviour, IPooledObject{
|
||||
|
||||
public float speed;
|
||||
public GameObject particles;
|
||||
public PolygonCollider2D polCol;
|
||||
public GameObject spawnParticles;
|
||||
public GameObject rocket;
|
||||
public Color level1Color;
|
||||
public Color level2Color;
|
||||
public Color level3Color;
|
||||
public SpriteRenderer[] spriteRenderers;
|
||||
|
||||
GameController gameController;
|
||||
Animator anim;
|
||||
bool spawned;
|
||||
bool ready;
|
||||
GameObject target;
|
||||
|
||||
public void OnObjectSpawn(){
|
||||
gameController = FindObjectOfType<GameController>();
|
||||
if (gameController.level == 1 || gameController.level == 0){
|
||||
foreach (SpriteRenderer r in spriteRenderers){
|
||||
r.color = level1Color;
|
||||
}
|
||||
ParticleSystem ps = spawnParticles.GetComponent<ParticleSystem>();
|
||||
var main = ps.main;
|
||||
main.startColor = level1Color;
|
||||
}
|
||||
if (gameController.level == 2){
|
||||
foreach (SpriteRenderer r in spriteRenderers){
|
||||
r.color = level2Color;
|
||||
}
|
||||
ParticleSystem ps = spawnParticles.GetComponent<ParticleSystem>();
|
||||
var main = ps.main;
|
||||
main.startColor = level2Color;
|
||||
}
|
||||
if (gameController.level == 3){
|
||||
foreach (SpriteRenderer r in spriteRenderers){
|
||||
r.color = level3Color;
|
||||
}
|
||||
ParticleSystem ps = spawnParticles.GetComponent<ParticleSystem>();
|
||||
var main = ps.main;
|
||||
main.startColor = level3Color;
|
||||
}
|
||||
anim = GetComponent<Animator>();
|
||||
Invoke(nameof(StopAnimation), 1f);
|
||||
anim.SetBool("Spawned", false);
|
||||
particles.SetActive(false);
|
||||
ready = false;
|
||||
spawned = false;
|
||||
target = GameObject.FindGameObjectWithTag("Player");
|
||||
Invoke(nameof(Ready), 2f);
|
||||
polCol.enabled = false;
|
||||
spawnParticles.SetActive(true);
|
||||
spawnParticles.GetComponent<ParticleSystem>().Play();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if (ready){
|
||||
transform.Translate(Vector3.up * speed * Time.deltaTime);
|
||||
}else if(spawned){
|
||||
Vector2 targetPos = target.transform.position - transform.position;
|
||||
float rotZ = Mathf.Atan2(targetPos.y, targetPos.x) * Mathf.Rad2Deg;
|
||||
transform.rotation = Quaternion.Euler(0f, 0f, rotZ - 90);
|
||||
}else if (!spawned){
|
||||
Vector2 targetPos = target.transform.position - transform.position;
|
||||
float rotZ = Mathf.Atan2(targetPos.y, targetPos.x) * Mathf.Rad2Deg;
|
||||
rocket.transform.rotation = Quaternion.Euler(0f, 0f, rotZ - 90);
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D col){
|
||||
if(col.gameObject.CompareTag("Wall")){
|
||||
Vector2 targetPos = target.transform.position - transform.position;
|
||||
float rotZ = Mathf.Atan2(targetPos.y, targetPos.x) * Mathf.Rad2Deg;
|
||||
transform.rotation = Quaternion.Euler(0f, 0f, rotZ - 90);
|
||||
}
|
||||
if(col.gameObject.CompareTag("Player")){
|
||||
ObjectPooler.Instance.SpawnFromPool("RocketEnemyDeath", transform.position, Quaternion.identity);
|
||||
AudioManager.instance.Play("EnemyDeath");
|
||||
gameObject.SetActive(false);
|
||||
ScreenShake.Shake(1f, .15f);
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D col){
|
||||
if (col.CompareTag("Bullet") || col.CompareTag("BigBullet")){
|
||||
AudioManager.instance.Play("EnemyDeath");
|
||||
ObjectPooler.Instance.SpawnFromPool("RocketEnemyDeath", transform.position, Quaternion.identity);
|
||||
ScreenShake.Shake(1f, .15f);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
#region OnSpawn
|
||||
void StopAnimation(){
|
||||
anim.SetBool("Spawned", true);
|
||||
}
|
||||
|
||||
void Ready(){
|
||||
Invoke(nameof(StartRunning), 1f);
|
||||
spawned = true;
|
||||
Invoke(nameof(EnableCollider), 0.5f);
|
||||
rocket.transform.rotation = Quaternion.Euler(Vector3.zero);
|
||||
}
|
||||
|
||||
void EnableCollider(){
|
||||
polCol.enabled = true;
|
||||
}
|
||||
|
||||
void StartRunning(){
|
||||
ready = true;
|
||||
particles.SetActive(true);
|
||||
}
|
||||
#endregion
|
||||
}
|
11
Assets/Scripts/Enemies/RocketEnemy.cs.meta
Normal file
11
Assets/Scripts/Enemies/RocketEnemy.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 347d5ccf364673941894f24f09c1f7af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
274
Assets/Scripts/GameController.cs
Normal file
274
Assets/Scripts/GameController.cs
Normal file
|
@ -0,0 +1,274 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cinemachine;
|
||||
|
||||
public class GameController : MonoBehaviour{
|
||||
|
||||
public int level;
|
||||
|
||||
[Header("SpawnRates")]
|
||||
public Vector2 minSpawnPos;
|
||||
public Vector2 maxSpawnPos;
|
||||
public float standardEnemySpawnRate = 2f;
|
||||
public float circleEnemySpawnRate = 3f;
|
||||
public float bigEnemySpawnRate = 4f;
|
||||
public float rocketEnemySpawnRate = 10f;
|
||||
public float gunSpawnRate = 15f;
|
||||
[HideInInspector]
|
||||
public float actualStandardEnemySpawnRate, actualCircleEnemySpawnRate, actualBigEnemySpawnRate, actualRocketEnemySpawnRate, actualGunSpawnRate;
|
||||
public float spawnRateDivider = .6f;
|
||||
|
||||
[Header("Car")]
|
||||
public CinemachineVirtualCamera room1Cam;
|
||||
public CinemachineVirtualCamera room2Cam;
|
||||
public CinemachineVirtualCamera room3Cam;
|
||||
public CinemachineVirtualCamera room4Cam;
|
||||
public CameraController cameraController;
|
||||
public float speed;
|
||||
public GameObject car;
|
||||
public GameObject[] checkPoints;
|
||||
Transform target;
|
||||
public Transform player;
|
||||
public HealthBar health;
|
||||
[HideInInspector]
|
||||
public bool ready, playered;
|
||||
bool dead;
|
||||
|
||||
[Header("Level")]
|
||||
public GameObject[] doors;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
PreFirst();
|
||||
GetComponent<BigEnemySpawner>().enabled = false;
|
||||
GetComponent<CircleEnemySpawner>().enabled = false;
|
||||
GetComponent<EnemySpawner>().enabled = false;
|
||||
GetComponent<GunSpawner>().enabled = false;
|
||||
GetComponent<RocketEnemySpawner>().enabled = false;
|
||||
AudioManager.instance.Stop("MenuTheme");
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if(health.hp <= 0 && dead == false){
|
||||
car.SetActive(false);
|
||||
ObjectPooler.Instance.SpawnFromPool("CarExplosion", car.transform.position, Quaternion.identity);
|
||||
Camera.main.GetComponent<Animator>().SetBool("GameOver", true);
|
||||
FindObjectOfType<InGameUI>().GameOver(false);
|
||||
AudioManager.instance.Stop("MainTheme");
|
||||
Time.timeScale = 0f;
|
||||
dead = true;
|
||||
}
|
||||
if(level != 0 && level != 1){
|
||||
actualBigEnemySpawnRate = bigEnemySpawnRate / (spawnRateDivider * level);
|
||||
actualStandardEnemySpawnRate = standardEnemySpawnRate / (spawnRateDivider * level);
|
||||
actualRocketEnemySpawnRate = rocketEnemySpawnRate / (spawnRateDivider * level);
|
||||
actualCircleEnemySpawnRate = circleEnemySpawnRate / (spawnRateDivider * level);
|
||||
actualGunSpawnRate = gunSpawnRate * (spawnRateDivider / level);
|
||||
}else{
|
||||
actualBigEnemySpawnRate = bigEnemySpawnRate;
|
||||
actualStandardEnemySpawnRate = standardEnemySpawnRate;
|
||||
actualRocketEnemySpawnRate = rocketEnemySpawnRate;
|
||||
actualCircleEnemySpawnRate = circleEnemySpawnRate;
|
||||
actualGunSpawnRate = gunSpawnRate;
|
||||
}
|
||||
|
||||
if (playered){
|
||||
if (second){
|
||||
minSpawnPos = new Vector2(17, -4);
|
||||
maxSpawnPos = new Vector2(33, 4);
|
||||
GetComponent<BigEnemySpawner>().enabled = true;
|
||||
GetComponent<CircleEnemySpawner>().enabled = true;
|
||||
GetComponent<EnemySpawner>().enabled = true;
|
||||
GetComponent<GunSpawner>().enabled = true;
|
||||
GetComponent<RocketEnemySpawner>().enabled = true;
|
||||
room2Cam.gameObject.SetActive(true);
|
||||
cameraController.follow = checkPoints[1].transform;
|
||||
health.time = 0f;
|
||||
Invoke(nameof(Third), 30f);
|
||||
foreach (GameObject d in doors){
|
||||
d.SetActive(true);
|
||||
}
|
||||
second = false;
|
||||
}
|
||||
if (third){
|
||||
minSpawnPos = new Vector2(42, -4);
|
||||
maxSpawnPos = new Vector2(58, 4);
|
||||
GetComponent<BigEnemySpawner>().enabled = true;
|
||||
GetComponent<CircleEnemySpawner>().enabled = true;
|
||||
GetComponent<EnemySpawner>().enabled = true;
|
||||
GetComponent<GunSpawner>().enabled = true;
|
||||
GetComponent<RocketEnemySpawner>().enabled = true;
|
||||
room3Cam.gameObject.SetActive(true);
|
||||
cameraController.follow = checkPoints[2].transform;
|
||||
health.time = 0f;
|
||||
Invoke(nameof(Fourth), 30f);
|
||||
foreach (GameObject d in doors){
|
||||
d.SetActive(true);
|
||||
}
|
||||
third = false;
|
||||
}
|
||||
if (fourth){
|
||||
minSpawnPos = new Vector2(67, -4);
|
||||
maxSpawnPos = new Vector2(83, 4);
|
||||
GetComponent<BigEnemySpawner>().enabled = true;
|
||||
GetComponent<CircleEnemySpawner>().enabled = true;
|
||||
GetComponent<EnemySpawner>().enabled = true;
|
||||
GetComponent<GunSpawner>().enabled = true;
|
||||
GetComponent<RocketEnemySpawner>().enabled = true;
|
||||
room4Cam.gameObject.SetActive(true);
|
||||
cameraController.follow = checkPoints[3].transform;
|
||||
health.time = 0f;
|
||||
foreach (GameObject d in doors){
|
||||
d.SetActive(true);
|
||||
}
|
||||
Invoke(nameof(Fifth), 30f);
|
||||
fourth = false;
|
||||
}
|
||||
if (ableToWin){
|
||||
Finish();
|
||||
Camera.main.GetComponent<Animator>().SetBool("Win", true);
|
||||
Invoke(nameof(WinWin), 0.5f);
|
||||
ableToWin = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate(){
|
||||
if (health.hp > 0){
|
||||
car.transform.position = Vector2.MoveTowards(car.transform.position, new Vector2(target.position.x + .675f, target.position.y), speed * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
void PreFirst(){
|
||||
Invoke(nameof(First), 4f);
|
||||
target = checkPoints[0].transform;
|
||||
room1Cam.gameObject.SetActive(true);
|
||||
cameraController.follow = checkPoints[0].transform;
|
||||
}
|
||||
|
||||
void First(){
|
||||
AudioManager.instance.Play("MainTheme");
|
||||
ready = true;
|
||||
GetComponent<BigEnemySpawner>().enabled = true;
|
||||
GetComponent<CircleEnemySpawner>().enabled = false;
|
||||
GetComponent<EnemySpawner>().enabled = true;
|
||||
GetComponent<GunSpawner>().enabled = true;
|
||||
GetComponent<RocketEnemySpawner>().enabled = false;
|
||||
Invoke(nameof(Second), 30f);
|
||||
}
|
||||
void Second(){
|
||||
Finish();
|
||||
level = 1;
|
||||
foreach(GameObject d in doors){
|
||||
d.SetActive(false);
|
||||
}
|
||||
room1Cam.gameObject.SetActive(false);
|
||||
room2Cam.gameObject.SetActive(false);
|
||||
room3Cam.gameObject.SetActive(false);
|
||||
room4Cam.gameObject.SetActive(false);
|
||||
cameraController.follow = player;
|
||||
target = checkPoints[1].transform;
|
||||
Invoke(nameof(SecondSecond), 25f);
|
||||
}
|
||||
bool second;
|
||||
void SecondSecond(){
|
||||
second = true;
|
||||
}
|
||||
void Third(){
|
||||
Finish();
|
||||
level = 2;
|
||||
foreach (GameObject d in doors){
|
||||
d.SetActive(false);
|
||||
}
|
||||
room1Cam.gameObject.SetActive(false);
|
||||
room2Cam.gameObject.SetActive(false);
|
||||
room3Cam.gameObject.SetActive(false);
|
||||
room4Cam.gameObject.SetActive(false);
|
||||
cameraController.follow = player;
|
||||
target = checkPoints[2].transform;
|
||||
Invoke(nameof(ThirdThird), 25f);
|
||||
}
|
||||
bool third;
|
||||
void ThirdThird(){
|
||||
third = true;
|
||||
}
|
||||
void Fourth(){
|
||||
Finish();
|
||||
level = 3;
|
||||
foreach (GameObject d in doors){
|
||||
d.SetActive(false);
|
||||
}
|
||||
room1Cam.gameObject.SetActive(false);
|
||||
room2Cam.gameObject.SetActive(false);
|
||||
room3Cam.gameObject.SetActive(false);
|
||||
room4Cam.gameObject.SetActive(false);
|
||||
cameraController.follow = player;
|
||||
target = checkPoints[3].transform;
|
||||
Invoke(nameof(FourthFourth), 25f);
|
||||
}
|
||||
bool fourth;
|
||||
void FourthFourth(){
|
||||
fourth = true;
|
||||
}
|
||||
|
||||
void Fifth(){
|
||||
foreach (GameObject d in doors){
|
||||
d.SetActive(false);
|
||||
}
|
||||
room1Cam.gameObject.SetActive(false);
|
||||
room2Cam.gameObject.SetActive(false);
|
||||
room3Cam.gameObject.SetActive(false);
|
||||
room4Cam.gameObject.SetActive(false);
|
||||
cameraController.follow = player;
|
||||
target = checkPoints[4].transform;
|
||||
Invoke(nameof(Win), 18f);
|
||||
}
|
||||
bool ableToWin;
|
||||
void Win(){
|
||||
ableToWin = true;
|
||||
}
|
||||
|
||||
void WinWin(){
|
||||
Time.timeScale = 0f;
|
||||
FindObjectOfType<InGameUI>().GameOver(true);
|
||||
AudioManager.instance.Stop("MainTheme");
|
||||
}
|
||||
|
||||
void Finish(){
|
||||
GetComponent<BigEnemySpawner>().enabled = false;
|
||||
GetComponent<CircleEnemySpawner>().enabled = false;
|
||||
GetComponent<EnemySpawner>().enabled = false;
|
||||
GetComponent<GunSpawner>().enabled = false;
|
||||
GetComponent<RocketEnemySpawner>().enabled = false;
|
||||
foreach (GameObject g in GameObject.FindGameObjectsWithTag("Enemy")){
|
||||
ObjectPooler.Instance.SpawnFromPool("EnemyDeath", g.transform.position, Quaternion.identity);
|
||||
if(g.transform.parent == null){
|
||||
g.SetActive(false);
|
||||
}else if(g.transform.parent.CompareTag("Enemy")){
|
||||
g.transform.parent.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
foreach (GameObject g in GameObject.FindGameObjectsWithTag("BigEnemy")){
|
||||
ObjectPooler.Instance.SpawnFromPool("EnemyDeath", g.transform.position, Quaternion.identity);
|
||||
g.SetActive(false);
|
||||
}
|
||||
foreach (GameObject g in GameObject.FindGameObjectsWithTag("RocketEnemy")){
|
||||
ObjectPooler.Instance.SpawnFromPool("RocketEnemyDeath", g.transform.position, Quaternion.identity);
|
||||
if (g.transform.parent == null){
|
||||
g.SetActive(false);
|
||||
}else if (g.transform.parent.CompareTag("RocketEnemy")){
|
||||
g.transform.parent.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
foreach (GameObject g in GameObject.FindGameObjectsWithTag("CircleEnemy")){
|
||||
ObjectPooler.Instance.SpawnFromPool("CircleEnemyDeath", g.transform.position, Quaternion.identity);
|
||||
if (g.transform.parent == null){
|
||||
g.SetActive(false);
|
||||
}else if (g.transform.parent.CompareTag("CircleEnemy")){
|
||||
g.transform.parent.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/GameController.cs.meta
Normal file
11
Assets/Scripts/GameController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3519b2196604bf64bba2de24a9e5980f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
39
Assets/Scripts/HealthBar.cs
Normal file
39
Assets/Scripts/HealthBar.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class HealthBar : MonoBehaviour{
|
||||
|
||||
public int maxHp;
|
||||
[HideInInspector] public float hp;
|
||||
public Image healthBar;
|
||||
public Image timer;
|
||||
[HideInInspector] public float time;
|
||||
GameController gameController;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
gameController = FindObjectOfType<GameController>();
|
||||
hp = maxHp;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if (gameController.ready){
|
||||
timer.transform.localScale = new Vector2(time, timer.transform.localScale.y);
|
||||
time = Mathf.Clamp(time + Time.deltaTime / 30, 0f, 1f);
|
||||
}else{
|
||||
timer.transform.localScale = new Vector2(0, timer.transform.localScale.y);
|
||||
}
|
||||
}
|
||||
|
||||
public void TakeDamage(float damage){
|
||||
hp -= damage;
|
||||
if(hp > 0 && hp > damage){
|
||||
healthBar.transform.localScale = new Vector2(hp / maxHp, healthBar.transform.localScale.y);
|
||||
}else if(hp < damage){
|
||||
healthBar.transform.localScale = new Vector2(0, healthBar.transform.localScale.y);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/HealthBar.cs.meta
Normal file
11
Assets/Scripts/HealthBar.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3cb8bccc28a695d46878601ccba92ccc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
5
Assets/Scripts/IPooledObject.cs
Normal file
5
Assets/Scripts/IPooledObject.cs
Normal file
|
@ -0,0 +1,5 @@
|
|||
using UnityEngine;
|
||||
|
||||
public interface IPooledObject{
|
||||
void OnObjectSpawn();
|
||||
}
|
11
Assets/Scripts/IPooledObject.cs.meta
Normal file
11
Assets/Scripts/IPooledObject.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bbd06145ddf00b644ab6354bf4ea03cd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
63
Assets/Scripts/InGameUI.cs
Normal file
63
Assets/Scripts/InGameUI.cs
Normal file
|
@ -0,0 +1,63 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class InGameUI : MonoBehaviour{
|
||||
|
||||
[SerializeField] Button winDefaultButton = default;
|
||||
[SerializeField] Button loseDefaultButton = default;
|
||||
|
||||
bool inWinScreen;
|
||||
|
||||
[SerializeField] PlayerInput playerInput = default;
|
||||
string currentControlScheme;
|
||||
|
||||
void Update(){
|
||||
if (playerInput.currentControlScheme != currentControlScheme){
|
||||
currentControlScheme = playerInput.currentControlScheme;
|
||||
if (currentControlScheme == "Keyboard"){
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
EventSystem.current.SetSelectedGameObject(null);
|
||||
}else{
|
||||
if (inWinScreen){
|
||||
winDefaultButton.Select();
|
||||
}else{
|
||||
loseDefaultButton.Select();
|
||||
}
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void GameOver(bool win){
|
||||
if (win){
|
||||
inWinScreen = true;
|
||||
winDefaultButton.Select();
|
||||
}else{
|
||||
inWinScreen = false;
|
||||
loseDefaultButton.Select();
|
||||
}
|
||||
}
|
||||
|
||||
public void Quit(){
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
public void Retry(){
|
||||
Time.timeScale = 1;
|
||||
SceneManager.LoadScene(1);
|
||||
}
|
||||
|
||||
public void Menu(){
|
||||
Time.timeScale = 1;
|
||||
SceneManager.LoadScene(0);
|
||||
}
|
||||
|
||||
public void PlaySound(string sound){
|
||||
AudioManager.instance.Play(sound);
|
||||
}
|
||||
}
|
11
Assets/Scripts/InGameUI.cs.meta
Normal file
11
Assets/Scripts/InGameUI.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e3e0df07d9351344aa8ddb22b213c76f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Level.meta
Normal file
8
Assets/Scripts/Level.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fef2e02a45e5eb14bab76b5348169f9a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Level/Guns.meta
Normal file
8
Assets/Scripts/Level/Guns.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8d050d610df321f49a1e2c741efe81b0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
21
Assets/Scripts/Level/Guns/GunController.cs
Normal file
21
Assets/Scripts/Level/Guns/GunController.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GunController : MonoBehaviour, IPooledObject{
|
||||
// Start is called before the first frame update
|
||||
public void OnObjectSpawn(){
|
||||
StartCoroutine(Remove());
|
||||
}
|
||||
|
||||
IEnumerator Remove(){
|
||||
yield return new WaitForSeconds(12f);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D col){
|
||||
if(col.gameObject.tag == "Player"){
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level/Guns/GunController.cs.meta
Normal file
11
Assets/Scripts/Level/Guns/GunController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f38af89adbebcb24f9727c2fae867700
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
88
Assets/Scripts/MenuAim.cs
Normal file
88
Assets/Scripts/MenuAim.cs
Normal file
|
@ -0,0 +1,88 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class MenuAim : MonoBehaviour{
|
||||
|
||||
public GameObject gun;
|
||||
|
||||
[SerializeField] Button defaultSelected = default;
|
||||
[SerializeField] Button creditsBack = default;
|
||||
[SerializeField] Button creditsButton = default;
|
||||
bool inCredits;
|
||||
float aimVelocity;
|
||||
|
||||
[SerializeField] PlayerInput playerInput = default;
|
||||
string currentControlScheme;
|
||||
Vector2 aim;
|
||||
|
||||
void Start(){
|
||||
AudioManager.instance.Play("MenuTheme");
|
||||
}
|
||||
|
||||
public void MousePos(InputAction.CallbackContext state){
|
||||
aim = state.ReadValue<Vector2>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if(currentControlScheme == "Keyboard"){
|
||||
Vector2 mousePos = Camera.main.ScreenToWorldPoint(aim) - transform.position;
|
||||
float rotZ = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg;
|
||||
gun.transform.rotation = Quaternion.Euler(0f, 0f, Mathf.SmoothDampAngle(gun.transform.eulerAngles.z, rotZ + 180, ref aimVelocity, .1f));
|
||||
}else{
|
||||
Vector2 mousePos = EventSystem.current.currentSelectedGameObject.transform.position - transform.position;
|
||||
float rotZ = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg;
|
||||
gun.transform.rotation = Quaternion.Euler(0f, 0f, Mathf.SmoothDampAngle(gun.transform.eulerAngles.z, rotZ + 180, ref aimVelocity, .1f));
|
||||
}
|
||||
|
||||
if (playerInput.currentControlScheme != currentControlScheme){
|
||||
currentControlScheme = playerInput.currentControlScheme;
|
||||
if(currentControlScheme == "Keyboard"){
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
EventSystem.current.SetSelectedGameObject(null);
|
||||
}else{
|
||||
if (inCredits)
|
||||
creditsBack.Select();
|
||||
else
|
||||
defaultSelected.Select();
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SelectCredits(){
|
||||
if(currentControlScheme == "Keyboard")
|
||||
EventSystem.current.SetSelectedGameObject(null);
|
||||
else
|
||||
creditsBack.Select();
|
||||
inCredits = true;
|
||||
}
|
||||
public void QuitCredits(){
|
||||
if (currentControlScheme == "Keyboard")
|
||||
EventSystem.current.SetSelectedGameObject(null);
|
||||
else
|
||||
creditsButton.Select();
|
||||
inCredits = false;
|
||||
}
|
||||
|
||||
public void Play(){
|
||||
SceneManager.LoadScene(1);
|
||||
}
|
||||
|
||||
public void Quit(){
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
public void OpenURL(){
|
||||
Application.OpenURL("https://geri8.itch.io/");
|
||||
}
|
||||
|
||||
public void PlaySound(string sound){
|
||||
AudioManager.instance.Play(sound);
|
||||
}
|
||||
}
|
11
Assets/Scripts/MenuAim.cs.meta
Normal file
11
Assets/Scripts/MenuAim.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: eb358420c7409204093529533416676b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
63
Assets/Scripts/ObjectPooler.cs
Normal file
63
Assets/Scripts/ObjectPooler.cs
Normal file
|
@ -0,0 +1,63 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ObjectPooler : MonoBehaviour{
|
||||
|
||||
[System.Serializable]
|
||||
public class Pool{
|
||||
public string tag;
|
||||
public GameObject prefab;
|
||||
public int size;
|
||||
}
|
||||
|
||||
#region Singleton
|
||||
public static ObjectPooler Instance;
|
||||
|
||||
private void Awake(){
|
||||
Instance = this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public List<Pool> pools;
|
||||
public Dictionary<string, Queue<GameObject>> poolDictionary;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
poolDictionary = new Dictionary<string, Queue<GameObject>>();
|
||||
|
||||
foreach (Pool pool in pools){
|
||||
Queue<GameObject> objectPool = new Queue<GameObject>();
|
||||
|
||||
for (int i = 0; i < pool.size; i++){
|
||||
GameObject obj = Instantiate(pool.prefab, gameObject.transform);
|
||||
obj.SetActive(false);
|
||||
objectPool.Enqueue(obj);
|
||||
}
|
||||
|
||||
poolDictionary.Add(pool.tag, objectPool);
|
||||
}
|
||||
}
|
||||
|
||||
public GameObject SpawnFromPool(string tag, Vector3 position, Quaternion rotation){
|
||||
if (!poolDictionary.ContainsKey(tag)){
|
||||
Debug.LogWarning("Pool with tag " + tag + " doesn't excist.");
|
||||
return null;
|
||||
}
|
||||
GameObject objectToSpawn = poolDictionary[tag].Dequeue();
|
||||
|
||||
objectToSpawn.SetActive(true);
|
||||
objectToSpawn.transform.position = position;
|
||||
objectToSpawn.transform.rotation = rotation;
|
||||
|
||||
IPooledObject pooledObj = objectToSpawn.GetComponent<IPooledObject>();
|
||||
|
||||
if (pooledObj != null){
|
||||
pooledObj.OnObjectSpawn();
|
||||
}
|
||||
|
||||
poolDictionary[tag].Enqueue(objectToSpawn);
|
||||
|
||||
return objectToSpawn;
|
||||
}
|
||||
}
|
11
Assets/Scripts/ObjectPooler.cs.meta
Normal file
11
Assets/Scripts/ObjectPooler.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3b21b57349261f0438fd907cf260297f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Player.meta
Normal file
8
Assets/Scripts/Player.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4d13c6f0c448c5749a9c9313dcb79076
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
34
Assets/Scripts/Player/BigBulletController.cs
Normal file
34
Assets/Scripts/Player/BigBulletController.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BigBulletController : MonoBehaviour{
|
||||
|
||||
public float speed;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
transform.Translate(Vector2.right * speed * Time.deltaTime);
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D col){
|
||||
if(col.gameObject.tag == "Enemy"){
|
||||
ObjectPooler.Instance.SpawnFromPool("EnemyDeath", col.transform.position, Quaternion.identity);
|
||||
ObjectPooler.Instance.SpawnFromPool("BulletImpact", transform.position, Quaternion.identity);
|
||||
}
|
||||
if (col.gameObject.tag == "BigEnemy"){
|
||||
ObjectPooler.Instance.SpawnFromPool("BulletImpact", transform.position, Quaternion.identity);
|
||||
}
|
||||
if (col.gameObject.tag == "CircleEnemy"){
|
||||
ObjectPooler.Instance.SpawnFromPool("BulletImpact", transform.position, Quaternion.identity);
|
||||
}
|
||||
if (col.gameObject.tag == "RocketEnemy"){
|
||||
ObjectPooler.Instance.SpawnFromPool("RocketEnemyDeath", col.transform.position, Quaternion.identity);
|
||||
ObjectPooler.Instance.SpawnFromPool("BulletImpact", transform.position, Quaternion.identity);
|
||||
}
|
||||
if(col.gameObject.tag == "Wall"){
|
||||
ObjectPooler.Instance.SpawnFromPool("BulletImpact", transform.position, Quaternion.identity);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/BigBulletController.cs.meta
Normal file
11
Assets/Scripts/Player/BigBulletController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d1feee7c3bd7bc445b8e27a2344314d0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
34
Assets/Scripts/Player/BulletController.cs
Normal file
34
Assets/Scripts/Player/BulletController.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BulletController : MonoBehaviour{
|
||||
|
||||
public float speed;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
transform.Translate(Vector2.right * speed * Time.deltaTime);
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D col){
|
||||
if(col.gameObject.tag == "Enemy"){
|
||||
ObjectPooler.Instance.SpawnFromPool("BulletImpact", transform.position, Quaternion.identity);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
if(col.gameObject.tag == "BigEnemy"){
|
||||
ObjectPooler.Instance.SpawnFromPool("BulletImpact", transform.position, Quaternion.identity);
|
||||
}
|
||||
if (col.gameObject.tag == "CircleEnemy"){
|
||||
ObjectPooler.Instance.SpawnFromPool("BulletImpact", transform.position, Quaternion.identity);
|
||||
}
|
||||
if (col.gameObject.tag == "RocketEnemy"){
|
||||
ObjectPooler.Instance.SpawnFromPool("BulletImpact", transform.position, Quaternion.identity);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
if (col.gameObject.tag == "Wall"){
|
||||
ObjectPooler.Instance.SpawnFromPool("BulletImpact", transform.position, Quaternion.identity);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/BulletController.cs.meta
Normal file
11
Assets/Scripts/Player/BulletController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f73c7d199b07b804da32fc3d5e36dd51
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
161
Assets/Scripts/Player/PlayerController.cs
Normal file
161
Assets/Scripts/Player/PlayerController.cs
Normal file
|
@ -0,0 +1,161 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class PlayerController : MonoBehaviour{
|
||||
|
||||
[Header("Statistics")]
|
||||
public float speed;
|
||||
public float shootingSpeed;
|
||||
public float invulnerableTime = 2f;
|
||||
[HideInInspector]
|
||||
public float defaultSpeed;
|
||||
[HideInInspector]
|
||||
public int gunSelected;
|
||||
[Header("Guns")]
|
||||
public GameObject[] gun;
|
||||
|
||||
GameController gameController;
|
||||
Animator anim;
|
||||
PlayerHealth health;
|
||||
bool dead;
|
||||
|
||||
Rigidbody2D rb2d;
|
||||
|
||||
PlayerInput playerInput;
|
||||
string currentControlScheme;
|
||||
Vector2 aim;
|
||||
Vector2 mov;
|
||||
|
||||
#region Input
|
||||
public void PlayerMove(InputAction.CallbackContext state){
|
||||
mov = state.ReadValue<Vector2>();
|
||||
}
|
||||
public void PlayerAim(InputAction.CallbackContext state){
|
||||
aim = state.ReadValue<Vector2>();
|
||||
}
|
||||
#endregion
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
playerInput = GetComponent<PlayerInput>();
|
||||
gameController = FindObjectOfType<GameController>();
|
||||
anim = GetComponent<Animator>();
|
||||
health = GetComponent<PlayerHealth>();
|
||||
defaultSpeed = speed;
|
||||
rb2d = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
RotateGun();
|
||||
|
||||
if(health.hp <= 0 && !dead){
|
||||
Time.timeScale = 0;
|
||||
ObjectPooler.Instance.SpawnFromPool("PlayerDeath", transform.position, Quaternion.identity);
|
||||
Camera.main.GetComponent<Animator>().SetBool("GameOver", true);
|
||||
dead = true;
|
||||
AudioManager.instance.Stop("MainTheme");
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if(playerInput.currentControlScheme != currentControlScheme){
|
||||
currentControlScheme = playerInput.currentControlScheme;
|
||||
}
|
||||
}
|
||||
|
||||
void RotateGun(){
|
||||
if(currentControlScheme == "Gamepad"){
|
||||
if(aim.magnitude > .1f){
|
||||
Quaternion newRot = Quaternion.Euler(0f, 0f, Mathf.Atan2(aim.y, aim.x) * Mathf.Rad2Deg);
|
||||
gun[gunSelected].transform.rotation = newRot;
|
||||
}
|
||||
}else{
|
||||
Vector2 mousePos = Camera.main.ScreenToWorldPoint(aim) - transform.position;
|
||||
float rotZ = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg;
|
||||
gun[gunSelected].transform.rotation = Quaternion.Euler(0f, 0f, rotZ);
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate(){
|
||||
rb2d.MovePosition(rb2d.position + (Vector2.ClampMagnitude(mov, 1f) * speed * Time.deltaTime));
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D col){
|
||||
if(col.CompareTag("Gun1")){
|
||||
gunSelected = 0;
|
||||
for (int i = 0; i < gun.Length; i++){
|
||||
if (i == gunSelected){
|
||||
gun[i].SetActive(true);
|
||||
}else{
|
||||
gun[i].SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(col.CompareTag("Gun2")){
|
||||
gunSelected = 1;
|
||||
for (int i = 0; i < gun.Length; i++){
|
||||
if (i == gunSelected){
|
||||
gun[i].SetActive(true);
|
||||
}else{
|
||||
gun[i].SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(col.CompareTag("Gun3")){
|
||||
gunSelected = 2;
|
||||
for (int i = 0; i < gun.Length; i++){
|
||||
if (i == gunSelected){
|
||||
gun[i].SetActive(true);
|
||||
}else{
|
||||
gun[i].SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
bool damaged;
|
||||
void OnCollisionEnter2D(Collision2D col){
|
||||
if(col.gameObject.CompareTag("Enemy") && !damaged || col.gameObject.CompareTag("BigEnemy") && !damaged){
|
||||
anim.SetBool("Damaged", true);
|
||||
if(gameController.level == 2){
|
||||
health.TakeDamage(6);
|
||||
}else if(gameController.level == 3){
|
||||
health.TakeDamage(7);
|
||||
}else{
|
||||
health.TakeDamage(5);
|
||||
}
|
||||
AudioManager.instance.Play("Hit");
|
||||
Invoke(nameof(Damaged), invulnerableTime);
|
||||
damaged = true;
|
||||
}
|
||||
if (col.gameObject.CompareTag("RocketEnemy")){
|
||||
anim.SetBool("Damaged", true);
|
||||
if (gameController.level == 2){
|
||||
health.TakeDamage(10);
|
||||
}else if (gameController.level == 3){
|
||||
health.TakeDamage(13);
|
||||
}else{
|
||||
health.TakeDamage(7);
|
||||
}
|
||||
AudioManager.instance.Play("Hit");
|
||||
Invoke(nameof(Damaged), invulnerableTime);
|
||||
damaged = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Damaged(){
|
||||
anim.SetBool("Damaged", false);
|
||||
damaged = false;
|
||||
}
|
||||
|
||||
void OnCollisionStay2D(Collision2D col){
|
||||
if(col.gameObject.CompareTag("CircleEnemy") && !damaged){
|
||||
if(col.gameObject.GetComponent<CircleEnemyController>().hp == 2){
|
||||
health.TakeDamage(0.1f);
|
||||
}else if(col.gameObject.GetComponent<CircleEnemyController>().hp == 1){
|
||||
health.TakeDamage(0.05f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/PlayerController.cs.meta
Normal file
11
Assets/Scripts/Player/PlayerController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: dc967a4d344b6a049aa2cfb3d360c356
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
25
Assets/Scripts/Player/PlayerHealth.cs
Normal file
25
Assets/Scripts/Player/PlayerHealth.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerHealth : MonoBehaviour{
|
||||
|
||||
public int maxHp;
|
||||
[HideInInspector]
|
||||
public float hp;
|
||||
public GameObject healthBar;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
hp = maxHp;
|
||||
}
|
||||
|
||||
public void TakeDamage(float damage){
|
||||
hp -= damage;
|
||||
if (hp > 0 && hp > damage){
|
||||
healthBar.transform.localScale = new Vector2(hp / maxHp, healthBar.transform.localScale.y);
|
||||
}else if (hp < damage){
|
||||
healthBar.transform.localScale = new Vector2(0, healthBar.transform.localScale.y);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/PlayerHealth.cs.meta
Normal file
11
Assets/Scripts/Player/PlayerHealth.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e69c8297fda776a449269ef7f7b4fb6b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
67
Assets/Scripts/Player/Shoot.cs
Normal file
67
Assets/Scripts/Player/Shoot.cs
Normal file
|
@ -0,0 +1,67 @@
|
|||
//#define TEST_DEATH
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class Shoot : MonoBehaviour{
|
||||
|
||||
public float[] timeBetweenShots;
|
||||
public Transform[] firePoint;
|
||||
public Transform secondaryFirePoint;
|
||||
|
||||
PlayerController player;
|
||||
float shotCounter;
|
||||
|
||||
bool shooting;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
player = GetComponent<PlayerController>();
|
||||
}
|
||||
|
||||
public void PlayerShoot(InputAction.CallbackContext state){
|
||||
if (state.performed){
|
||||
shooting = true;
|
||||
#if TEST_DEATH
|
||||
FindObjectOfType<HealthBar>().hp = 0f;
|
||||
#endif
|
||||
}
|
||||
if (state.canceled){
|
||||
shooting = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if (shooting && player.gunSelected == 0){
|
||||
shotCounter -= Time.deltaTime;
|
||||
if (shotCounter <= 0){
|
||||
shotCounter = timeBetweenShots[0];
|
||||
AudioManager.instance.Play("Shoot");
|
||||
ObjectPooler.Instance.SpawnFromPool("Bullet", firePoint[0].position, firePoint[0].rotation);
|
||||
player.speed = player.shootingSpeed;
|
||||
}
|
||||
}else if(shooting && player.gunSelected == 1){
|
||||
shotCounter -= Time.deltaTime;
|
||||
if (shotCounter <= 0){
|
||||
shotCounter = timeBetweenShots[1];
|
||||
AudioManager.instance.Play("Shoot");
|
||||
ObjectPooler.Instance.SpawnFromPool("BigBullet", firePoint[1].position, firePoint[1].rotation);
|
||||
player.speed = player.shootingSpeed;
|
||||
}
|
||||
}else if(shooting && player.gunSelected == 2){
|
||||
shotCounter -= Time.deltaTime;
|
||||
if (shotCounter <= 0){
|
||||
shotCounter = timeBetweenShots[2];
|
||||
AudioManager.instance.Play("Shoot");
|
||||
ObjectPooler.Instance.SpawnFromPool("Bullet", firePoint[2].position, firePoint[2].rotation);
|
||||
ObjectPooler.Instance.SpawnFromPool("Bullet", secondaryFirePoint.position, secondaryFirePoint.rotation);
|
||||
player.speed = player.shootingSpeed;
|
||||
}
|
||||
}else{
|
||||
shotCounter = 0;
|
||||
player.speed = player.defaultSpeed;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/Shoot.cs.meta
Normal file
11
Assets/Scripts/Player/Shoot.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0e38d1409562d6040af52ee5a90be837
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
22
Assets/Scripts/Sound.cs
Normal file
22
Assets/Scripts/Sound.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using UnityEngine.Audio;
|
||||
using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class Sound{
|
||||
|
||||
public string name;
|
||||
|
||||
public AudioClip clip;
|
||||
|
||||
[Range(0f, 1f)]
|
||||
public float volume = 1f;
|
||||
[Range(0.1f, 3f)]
|
||||
public float pitch = 1f;
|
||||
|
||||
public bool loop;
|
||||
|
||||
public AudioMixerGroup mixerGroup;
|
||||
|
||||
[HideInInspector]
|
||||
public AudioSource source;
|
||||
}
|
11
Assets/Scripts/Sound.cs.meta
Normal file
11
Assets/Scripts/Sound.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fdbe1dfe6e33be442b38e3d99238a3e8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Spawners.meta
Normal file
8
Assets/Scripts/Spawners.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 23a86ef3d6b52f44891ffd2507cd8590
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
29
Assets/Scripts/Spawners/BigEnemySpawner.cs
Normal file
29
Assets/Scripts/Spawners/BigEnemySpawner.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BigEnemySpawner : MonoBehaviour{
|
||||
|
||||
public string ObjectToSpawn;
|
||||
Vector2 whereToSpawn;
|
||||
GameController gameController;
|
||||
float nextSpawn;
|
||||
float spawnRate;
|
||||
|
||||
void Start(){
|
||||
gameController = FindObjectOfType<GameController>();
|
||||
spawnRate = gameController.actualBigEnemySpawnRate;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
spawnRate = gameController.actualBigEnemySpawnRate;
|
||||
if (Time.time > nextSpawn){
|
||||
nextSpawn = Time.time + spawnRate;
|
||||
float xPos = Random.Range(gameController.minSpawnPos.x, gameController.maxSpawnPos.x);
|
||||
float yPos = Random.Range(gameController.minSpawnPos.y, gameController.maxSpawnPos.y);
|
||||
whereToSpawn = new Vector2(xPos, yPos);
|
||||
ObjectPooler.Instance.SpawnFromPool(ObjectToSpawn, whereToSpawn, Quaternion.identity);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Spawners/BigEnemySpawner.cs.meta
Normal file
11
Assets/Scripts/Spawners/BigEnemySpawner.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c1306f89d472367469e4d98688605196
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
29
Assets/Scripts/Spawners/CircleEnemySpawner.cs
Normal file
29
Assets/Scripts/Spawners/CircleEnemySpawner.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CircleEnemySpawner : MonoBehaviour{
|
||||
|
||||
public string ObjectToSpawn;
|
||||
Vector2 whereToSpawn;
|
||||
GameController gameController;
|
||||
float nextSpawn;
|
||||
float spawnRate;
|
||||
|
||||
void Start(){
|
||||
gameController = FindObjectOfType<GameController>();
|
||||
spawnRate = gameController.actualCircleEnemySpawnRate;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
spawnRate = gameController.actualCircleEnemySpawnRate;
|
||||
if (Time.time > nextSpawn){
|
||||
nextSpawn = Time.time + spawnRate;
|
||||
float xPos = Random.Range(gameController.minSpawnPos.x, gameController.maxSpawnPos.x);
|
||||
float yPos = Random.Range(gameController.minSpawnPos.y, gameController.maxSpawnPos.y);
|
||||
whereToSpawn = new Vector2(xPos, yPos);
|
||||
ObjectPooler.Instance.SpawnFromPool(ObjectToSpawn, whereToSpawn, Quaternion.identity);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Spawners/CircleEnemySpawner.cs.meta
Normal file
11
Assets/Scripts/Spawners/CircleEnemySpawner.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9f7ebe079a4a0d443b7521b2f23780cd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
29
Assets/Scripts/Spawners/EnemySpawner.cs
Normal file
29
Assets/Scripts/Spawners/EnemySpawner.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class EnemySpawner : MonoBehaviour{
|
||||
|
||||
public string ObjectToSpawn;
|
||||
Vector2 whereToSpawn;
|
||||
GameController gameController;
|
||||
float nextSpawn;
|
||||
float spawnRate;
|
||||
|
||||
void Start(){
|
||||
gameController = FindObjectOfType<GameController>();
|
||||
spawnRate = gameController.actualStandardEnemySpawnRate;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
spawnRate = gameController.actualStandardEnemySpawnRate;
|
||||
if (Time.time > nextSpawn){
|
||||
nextSpawn = Time.time + spawnRate;
|
||||
float xPos = Random.Range(gameController.minSpawnPos.x, gameController.maxSpawnPos.x);
|
||||
float yPos = Random.Range(gameController.minSpawnPos.y, gameController.maxSpawnPos.y);
|
||||
whereToSpawn = new Vector2(xPos, yPos);
|
||||
ObjectPooler.Instance.SpawnFromPool(ObjectToSpawn, whereToSpawn, Quaternion.identity);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Spawners/EnemySpawner.cs.meta
Normal file
11
Assets/Scripts/Spawners/EnemySpawner.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c416e122dbe15954da9b496d2dec516f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
29
Assets/Scripts/Spawners/GunSpawner.cs
Normal file
29
Assets/Scripts/Spawners/GunSpawner.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GunSpawner : MonoBehaviour{
|
||||
|
||||
public string[] ObjectToSpawn;
|
||||
Vector2 whereToSpawn;
|
||||
GameController gameController;
|
||||
float nextSpawn;
|
||||
float spawnRate;
|
||||
|
||||
void Start(){
|
||||
gameController = FindObjectOfType<GameController>();
|
||||
spawnRate = gameController.actualGunSpawnRate;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
spawnRate = gameController.actualGunSpawnRate;
|
||||
if (Time.time > nextSpawn){
|
||||
nextSpawn = Time.time + spawnRate;
|
||||
float xPos = Random.Range(gameController.minSpawnPos.x, gameController.maxSpawnPos.x);
|
||||
float yPos = Random.Range(gameController.minSpawnPos.y, gameController.maxSpawnPos.y);
|
||||
whereToSpawn = new Vector2(xPos, yPos);
|
||||
ObjectPooler.Instance.SpawnFromPool(ObjectToSpawn[Mathf.RoundToInt(Random.Range(0f, 5f))], whereToSpawn, Quaternion.identity);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Spawners/GunSpawner.cs.meta
Normal file
11
Assets/Scripts/Spawners/GunSpawner.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f14d11e7980db544f999f7c689e08d19
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
29
Assets/Scripts/Spawners/RocketEnemySpawner.cs
Normal file
29
Assets/Scripts/Spawners/RocketEnemySpawner.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class RocketEnemySpawner : MonoBehaviour{
|
||||
|
||||
public string ObjectToSpawn;
|
||||
Vector2 whereToSpawn;
|
||||
GameController gameController;
|
||||
float nextSpawn;
|
||||
float spawnRate;
|
||||
|
||||
void Start(){
|
||||
gameController = FindObjectOfType<GameController>();
|
||||
spawnRate = gameController.actualRocketEnemySpawnRate;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
spawnRate = gameController.actualRocketEnemySpawnRate;
|
||||
if (Time.time > nextSpawn){
|
||||
nextSpawn = Time.time + spawnRate;
|
||||
float xPos = Random.Range(gameController.minSpawnPos.x, gameController.maxSpawnPos.x);
|
||||
float yPos = Random.Range(gameController.minSpawnPos.y, gameController.maxSpawnPos.y);
|
||||
whereToSpawn = new Vector2(xPos, yPos);
|
||||
ObjectPooler.Instance.SpawnFromPool(ObjectToSpawn, whereToSpawn, Quaternion.identity);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Spawners/RocketEnemySpawner.cs.meta
Normal file
11
Assets/Scripts/Spawners/RocketEnemySpawner.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 091023997a40832468f1c12258143a0d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue