Added health, respawning and Bullet spawners

This commit is contained in:
2022-04-18 00:32:24 +02:00
parent 1bd6d79672
commit 209470d610
227 changed files with 53417 additions and 40 deletions

View File

@@ -4,14 +4,16 @@ using UnityEngine;
public enum PatternTypes
{
DEFAULT
DEFAULT,
DOUBLE_SPINNING,
QUADRUPLE_SPINNING,
}
[System.Serializable]
public class PatternMap
{
public PatternTypes patternType;
public Pattern pattern;
public GameObject pattern;
}
public class BulletManager : MonoBehaviour
{
@@ -31,8 +33,10 @@ public class BulletManager : MonoBehaviour
}
public Pattern SpawnPattern(PatternTypes pattern)
public void SpawnPattern(PatternTypes pattern, Enemy enemy)
{
return null;
GameObject patternObject = Instantiate(PatternMap.Find(x => x.patternType == pattern).pattern, enemy.transform.position, Quaternion.identity);
Pattern patternScript = patternObject.GetComponent<Pattern>();
patternScript.enemy = enemy;
}
}

View File

@@ -1,4 +1,5 @@
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
@@ -21,7 +22,7 @@ public class GameManager : MonoBehaviour
// Start is called before the first frame update
void Start()
{
player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
}
// Update is called once per frame
@@ -49,4 +50,11 @@ public class GameManager : MonoBehaviour
{
}
public void RestartGame()
{
//get active scene and reload it
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}

View File

@@ -5,8 +5,9 @@ using UnityEngine;
public class Pattern : MonoBehaviour
{
public string name = "Default Pattern";
public ParticleSystem particleSystem;
private Enemy enemy;
public float duration;
public bool notified = false;
public Enemy enemy;
// Start is called before the first frame update
void Start()
@@ -15,14 +16,47 @@ public class Pattern : MonoBehaviour
}
// Update is called once per frame
void Update()
private void Update()
{
OnPatternUpdate();
duration -= Time.deltaTime;
if (duration <= 0)
{
//find all particle systems in children and stop them
foreach (ParticleSystem ps in GetComponentsInChildren<ParticleSystem>())
{
ps.Stop();
}
//find all particle systems in children and sum their particle counts
int totalParticles = 0;
foreach (ParticleSystem ps in GetComponentsInChildren<ParticleSystem>())
{
totalParticles += ps.particleCount;
}
if (totalParticles == 0)
{
Destroy(gameObject);
return;
}
if (enemy && !notified)
{
enemy.OnPatternFinished();
notified = true;
}
}
}
public virtual void OnPatternUpdate()
{
//override this
}
public void StartPattern(Enemy enemy)
{
//Start pattern
}
}

View File

@@ -1,19 +1,33 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class UIManager : MonoBehaviour
{
public TextMeshProUGUI playerHealthLabel;
public TextMeshProUGUI gameOverLabel;
public Button restartButton;
private GameManager gameManager;
// Start is called before the first frame update
void Start()
{
gameManager = FindObjectOfType<GameManager>();
}
// Update is called once per frame
void Update()
{
//round player health
playerHealthLabel.text = "Health: " + Mathf.Round(gameManager.player.health).ToString();
if (gameManager.player.health <= 0)
{
gameOverLabel.gameObject.SetActive(true);
restartButton.gameObject.SetActive(true);
}
}
}

View File

@@ -6,12 +6,14 @@ public class Enemy : MonoBehaviour
{
public int baseScore;
public PatternTypes[] patterns;
public int CurrentPattern;
public int CurrentPattern = 0;
private BulletManager bulletManager;
// Start is called before the first frame update
void Start()
{
bulletManager = GameObject.Find("BulletManager").GetComponent<BulletManager>();
Attack();
}
// Update is called once per frame
@@ -19,10 +21,10 @@ public class Enemy : MonoBehaviour
{
}
private void Attack()
{
//Spawn pattern
bulletManager.SpawnPattern(patterns[CurrentPattern], this);
}
public void Consumed()
@@ -31,9 +33,14 @@ public class Enemy : MonoBehaviour
}
private void OnPatternFinished()
public void OnPatternFinished()
{
//Increment pattern
CurrentPattern++;
if (CurrentPattern >= patterns.Length)
{
//Destroy(gameObject);
}
Attack();
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8f0f077c8ee165d49b65384c60248459
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static UnityEngine.ParticleSystem;
public class RotatingPattern : Pattern
{
public float speed = 1;
// Start is called before the first frame update
void Start()
{
}
public override void OnPatternUpdate()
{
// transform.Rotate(Vector3.up, speed * Time.deltaTime);
//find all particle systems in children
ParticleSystem[] systems = GetComponentsInChildren<ParticleSystem>();
foreach (ParticleSystem system in systems)
{
ShapeModule shape = system.shape;
shape.rotation = new Vector3(0, shape.rotation.y + speed * Time.deltaTime, 0);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b5d3d6fc4fb04da4bbc0ebf8895d9423
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -8,4 +8,14 @@ public class Pickup : MonoBehaviour
{
}
public void OnTriggerEnter(Collider other)
{
Debug.Log("Pickup");
if (other.gameObject.tag == "Player")
{
OnPickup();
Destroy(gameObject);
}
}
}

View File

@@ -4,20 +4,26 @@ using UnityEngine;
public class Extinguisher : Pickup
{
public Player player;
[SerializeField]
private float amount;
public override void OnPickup()
{
throw new System.NotImplementedException();
// we have to stop the particle system before making changes
ParticleSystem system = player.trail.GetComponent<ParticleSystem>();
system.Stop();
system.startLifetime *= amount;
system.Play();
}
// Start is called before the first frame update
void Start()
{
}
player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
// Update is called once per frame
void Update()
{
}
}

View File

@@ -7,7 +7,6 @@ public class Player : MonoBehaviour
{
public float health;
public float speed;
public float trailLength;
public GameObject trail;
public float rotationSpeed;
public float direction;
@@ -40,14 +39,27 @@ public class Player : MonoBehaviour
if (isLit)
{
health -= 100.0f * Time.deltaTime;
Debug.Log("Health: " + health);
}
//if health below 0 die
if (health <= 0)
{
gameObject.SetActive(false);
}
/* Todo: Improve player movement
* Turning doesn't feel right, should be snappier
*/
//move player forward
transform.position += transform.forward * speed * Time.deltaTime;
//rotate based on direction
transform.Rotate(0, direction * rotationSpeed * 2 * Time.deltaTime, 0);
float horzExtent = camera.orthographicSize * Screen.width / Screen.height;
float vertExtent = camera.orthographicSize;
@@ -83,6 +95,14 @@ public class Player : MonoBehaviour
private void OnParticleCollision(GameObject other)
{
Debug.Log("Particle Collision" + other.name);
ParticleSystem ps = trail.GetComponent<ParticleSystem>();
ps.Stop();
//TODO: refactor magic number to a variable or constant
ps.startLifetime += 2;
ps.Play();
if (other == trail)
{
//Debug.Log(other.name);