basically the whole game
This commit is contained in:
parent
949135cecb
commit
96dcfa9064
315 changed files with 34386 additions and 396 deletions
|
|
@ -1,46 +1,109 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class Enemy : Entity
|
||||
{
|
||||
private Ability abilitySelected;
|
||||
public SpriteRenderer sprite;
|
||||
private float currentState = 1;
|
||||
public float colorChangeSpeed;
|
||||
[Header("Movement")]
|
||||
private float currentMovement;
|
||||
public float moveSpeed;
|
||||
public float moveSpeedDelta;
|
||||
[Header("wobble")]
|
||||
public bool preventWobble;
|
||||
public Vector3 originalPosition;
|
||||
[SerializeField] private float variance;
|
||||
public Coroutine currentMovementRoutine;
|
||||
[Header("boss stuff")]
|
||||
[SerializeField] private bool isBossEnemy;
|
||||
[SerializeField] private bool hasStartedDialogue;
|
||||
[Header("Attack")]
|
||||
[SerializeField] private float attackCooldown;
|
||||
private float currentAttackCooldown;
|
||||
[SerializeField] private DialogueScript thisBossDialogue;
|
||||
public event Action onTakeDamage;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
moveSpeed += Random.Range(-moveSpeedDelta, moveSpeedDelta);
|
||||
currentAttackCooldown = Random.Range(0, attackCooldown);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (!isStalled)
|
||||
{
|
||||
foreach (Ability ability in abilities)
|
||||
if (!preventWobble && currentMovementRoutine == null)
|
||||
{
|
||||
ability.direction = WaveManager.instance.GetRandomPlayerPoint();
|
||||
bool success = ability.TryAbility();
|
||||
if (!success && ability.currentCooldown <= 0.5f && currentState >= 1f)
|
||||
//Debug.Log("reset movement");
|
||||
//StopCoroutine(currentMovementRoutine);
|
||||
Vector3 newPosition = new Vector3(originalPosition.x + Random.Range(-variance, variance),
|
||||
originalPosition.y + Random.Range(-variance*0.5f, variance*0.5f));
|
||||
currentMovementRoutine = StartCoroutine(MoveToPosition(transform.position, newPosition, moveSpeed));
|
||||
}
|
||||
if (currentAttackCooldown <= 0)
|
||||
{
|
||||
List<Ability> freeAbilities = new();
|
||||
foreach (Ability ability in abilities)
|
||||
{
|
||||
if (ability.currentCooldown <= 0)
|
||||
{
|
||||
freeAbilities.Add(ability);
|
||||
}
|
||||
}
|
||||
|
||||
if (freeAbilities.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!abilitySelected)
|
||||
{
|
||||
abilitySelected = freeAbilities[Random.Range(0, freeAbilities.Count)];
|
||||
}
|
||||
bool success = abilitySelected.TryAbility();
|
||||
if (!success && abilitySelected.currentCooldown <= 0.5f && currentState >= 1f)
|
||||
{
|
||||
currentState = 0f;
|
||||
StartCoroutine(ImminentAttackAnim());
|
||||
}
|
||||
else
|
||||
{
|
||||
abilitySelected = null;
|
||||
currentAttackCooldown = attackCooldown;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
currentAttackCooldown -= Time.deltaTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void TakeDamage(int damage)
|
||||
{
|
||||
base.TakeDamage(damage);
|
||||
if (isBossEnemy)
|
||||
{
|
||||
WaveManager.instance.UpdateBossUI(); //this is fucking stupid but it works i guess
|
||||
}
|
||||
onTakeDamage?.Invoke();
|
||||
}
|
||||
|
||||
protected override void OnDeath()
|
||||
{
|
||||
base.OnDeath();
|
||||
Destroy(gameObject);
|
||||
WaveManager.instance.enemiesInPlay.Remove(this);
|
||||
WaveManager.instance.UpdateKills();
|
||||
if (isBossEnemy)
|
||||
{
|
||||
WaveManager.instance.bossUI.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator ImminentAttackAnim()
|
||||
|
|
@ -53,16 +116,25 @@ public class Enemy : Entity
|
|||
}
|
||||
}
|
||||
|
||||
public IEnumerator MoveToPosition(Vector3 moveDirection)
|
||||
public IEnumerator MoveToPosition(Vector3 origin, Vector3 moveDirection, float lerpSpeed)
|
||||
{
|
||||
float currentMovement = 0;
|
||||
while (currentMovement < 1)
|
||||
{
|
||||
currentMovement += Time.deltaTime * moveSpeed;
|
||||
currentMovement += Time.deltaTime * lerpSpeed;
|
||||
if (currentMovement >= 1)
|
||||
{
|
||||
isStalled = false;
|
||||
invulnerable = false;
|
||||
currentMovementRoutine = null;
|
||||
if (isBossEnemy && !hasStartedDialogue)
|
||||
{
|
||||
hasStartedDialogue = true;
|
||||
DialogueManager.instance.StartDialogue(thisBossDialogue); //the worst code ever
|
||||
isStalled = true;
|
||||
}
|
||||
}
|
||||
transform.position = Vector3.Lerp(WaveManager.instance.enemySpawnPoint.position, moveDirection, currentMovement);
|
||||
transform.position = Vector3.Lerp(origin, moveDirection, currentMovement);
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,12 +10,16 @@ public class Entity : MonoBehaviour
|
|||
|
||||
[Header("State")]
|
||||
public bool isStalled;
|
||||
public bool invulnerable;
|
||||
[Header("Abilities")]
|
||||
public List<Ability> abilities = new();
|
||||
|
||||
public virtual void TakeDamage(int damage)
|
||||
{
|
||||
health -= damage;
|
||||
if (!invulnerable)
|
||||
{
|
||||
health -= damage;
|
||||
}
|
||||
if (health <= 0)
|
||||
{
|
||||
OnDeath();
|
||||
|
|
|
|||
|
|
@ -4,24 +4,55 @@ using UnityEngine;
|
|||
|
||||
public class Player : Entity
|
||||
{
|
||||
[Header("Invulnerability")]
|
||||
[SerializeField] private float invulnerabilityLength;
|
||||
private float currentInvulnerabilityTime;
|
||||
[Header("UI")]
|
||||
[SerializeField] private TextMeshProUGUI livesText;
|
||||
|
||||
[Header("SFX")]
|
||||
[SerializeField] private AudioClip hurtSound;
|
||||
[SerializeField] private float hurtVolume = 1f;
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
if (!isStalled)
|
||||
{
|
||||
abilities[0].TryAbility();
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
abilities[0].TryAbility();
|
||||
}
|
||||
if (Input.GetMouseButtonDown(1)) //this way kinda sucks but i'll fix it when i feel like it
|
||||
{
|
||||
abilities[1].TryAbility();
|
||||
}
|
||||
}
|
||||
if (Input.GetMouseButtonDown(1)) //this way kinda sucks but i'll fix it when i feel like it
|
||||
|
||||
if (currentInvulnerabilityTime > 0)
|
||||
{
|
||||
abilities[1].TryAbility();
|
||||
currentInvulnerabilityTime -= Time.deltaTime;
|
||||
if (currentInvulnerabilityTime <= 0)
|
||||
{
|
||||
invulnerable = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void TakeDamage(int damage)
|
||||
{
|
||||
base.TakeDamage(damage);
|
||||
if (!invulnerable)
|
||||
{
|
||||
WaveManager.instance.audioSource.PlayOneShot(hurtSound, hurtVolume);
|
||||
currentInvulnerabilityTime = invulnerabilityLength;
|
||||
invulnerable = true;
|
||||
}
|
||||
UpdateLivesUI();
|
||||
GameManager.instance.livesLost++;
|
||||
}
|
||||
|
||||
protected override void OnDeath()
|
||||
{
|
||||
GameManager.instance.LoseGame();
|
||||
}
|
||||
private void UpdateLivesUI()
|
||||
{
|
||||
|
|
|
|||
43
Assets/Scripts/Entities/ZombieFairy.cs
Normal file
43
Assets/Scripts/Entities/ZombieFairy.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class ZombieFairy : Enemy
|
||||
{
|
||||
[SerializeField] private Ability deathAbility;
|
||||
[SerializeField] private bool hasDiedOnce;
|
||||
[SerializeField] private float disappearanceTime;
|
||||
private float currentDisappearanceTime;
|
||||
protected override void OnDeath()
|
||||
{
|
||||
if (!hasDiedOnce)
|
||||
{
|
||||
hasDiedOnce = true;
|
||||
health = maxHealth;
|
||||
invulnerable = true;
|
||||
isStalled = true;
|
||||
currentDisappearanceTime = disappearanceTime;
|
||||
sprite.color = Color.black;
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
WaveManager.instance.enemiesInPlay.Remove(this);
|
||||
WaveManager.instance.UpdateKills();
|
||||
}
|
||||
deathAbility.TryAbility();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
if (currentDisappearanceTime > 0)
|
||||
{
|
||||
currentDisappearanceTime -= Time.deltaTime;
|
||||
if (currentDisappearanceTime <= 0)
|
||||
{
|
||||
invulnerable = false;
|
||||
isStalled = false;
|
||||
sprite.color = Color.white;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Entities/ZombieFairy.cs.meta
Normal file
2
Assets/Scripts/Entities/ZombieFairy.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f2a09223bdc8572ce868c17f69e123d9
|
||||
Loading…
Add table
Add a link
Reference in a new issue