Add damage settings for hitbox class to be passed to enemy.damage

This commit is contained in:
Nico 2025-07-15 02:07:07 -07:00
parent 909f1e0ae7
commit f7552b362e
6 changed files with 26 additions and 15 deletions

View File

@ -23,6 +23,7 @@ public class Gobler : Alive {
[SerializeField] public float Health = 10f;
[SerializeField] public float Energy = 10f;
protected FloatingTextSpawner TextPopUp;
private Player Player { get { return Player.Instance; } }
@ -56,6 +57,8 @@ public class Gobler : Alive {
Rigidbody = Owner.GetComponent<Rigidbody2D>();
Materials = Owner.GetComponentsInChildren<SpriteRenderer>().Select(x => x.material).ToList();
TextPopUp = new FloatingTextSpawner(Owner.transform, 1);
SetState(State.GoToCrystal);
EnemyManagers[Enemies.Gobler].UpdateTick += Update;
EnemyManagers[Enemies.Gobler].GizmoTick += OnDrawGizmos;
@ -173,6 +176,7 @@ public class Gobler : Alive {
case State.TakeDamage:
PathAgent.isStopped = true;
TextPopUp.SpawnFloatingText(DamageTaken.ToString(), Color.red, 3);
Materials.ForEach(x => x.SetColor("_FlashColor", Color.white));
break;

View File

@ -36,7 +36,7 @@ public class ClassBase {
Player = player;
Animator = Player.Animator;
AttackAnimator = PlayerAttackAnimatorFactory.Instance;
TextPopUp = new FloatingTextSpawner(player.transform);
TextPopUp = new FloatingTextSpawner(player.transform, 0.5f);
}
virtual public void Tick() {
@ -98,13 +98,14 @@ public class ClassBase {
protected Coroutine AttackCoroutine;
protected void CreateHitBoxOffset(float centerOffset, float radius, float hitDelay, float hitDuration, int knockback) {
protected void CreateHitBoxOffset(float centerOffset, float radius, float hitDelay, float hitDuration, int damage, int knockback) {
if (AttackCoroutine != null)
Player.Instance.StopCoroutine(AttackCoroutine);
var center = PlayerPos + Player.PrevDirection * centerOffset;
hitDelay = 0;
HitBoxDraw.Knockback = knockback;
HitBoxDraw.Directional = centerOffset != 0;
HitBoxDraw.Damage = damage;
AttackCoroutine = Player.Instance.StartCoroutine(CreateHitBoxHelper(center, radius, hitDelay, hitDuration));
}
@ -134,5 +135,6 @@ public class ClassBase {
public float Radius;
public Color Color;
public int Knockback;
public int Damage;
}
}

View File

@ -19,6 +19,9 @@ public class MeleeFighterClass : ClassBase {
public float Cooldown;
public bool TimesUp;
public int DamageMultiplier = 1;
public int DamageOffset = 0;
public VfxHandlerBase VfxKineticSurgeHandler { get { return Player.VfxKineticSurgeHandler; } }
@ -74,9 +77,9 @@ public class MeleeFighterClass : ClassBase {
AttackAnimator?.MeleeResetKineticCharge();
AttackAnimator?.MeleeKineticSurge();
AnimationToPlay = "Attack1";
TextPopUp.SpawnFloatingText("KineticSurge", Color.red, 3);
//TextPopUp.SpawnFloatingText("KineticSurge", Color.red, 3);
AllowBladeVortex = ComboTimeElapsed <= 0.1f;
CreateHitBoxOffset(0, 5, 0.1f, 0.1f, 20);
CreateHitBoxOffset(0, 5, 0.1f, 0.1f, (10 * DamageMultiplier) + DamageOffset, 20);
break;
@ -207,7 +210,7 @@ public class MeleeFighterClass : ClassBase {
Player.MoveSpeedDampener = (state == AttackState.None) ? 1 : 1 / decreasedSpeed;
if (state == AttackState.None) return;
Cooldown = cooldown;
TextPopUp.SpawnFloatingText(state.ToString(), Color.red, 3);
//TextPopUp.SpawnFloatingText(state.ToString(), Color.red, 3);
ComboResetTime = resetTime;
LastComboTime = Time.time;
@ -224,7 +227,7 @@ public class MeleeFighterClass : ClassBase {
case AttackState.Shockwave:
AnimationToPlay = "Shockwave";
Player.VfxShockwavePool.Get(Player.transform.position);
CreateHitBoxOffset(0, 5, 0.1f, 0.1f, 20);
CreateHitBoxOffset(0, 5, 0.1f, 0.1f, (20 * DamageMultiplier) + DamageOffset, 20);
Player.IsJumping = false;
break;
@ -234,17 +237,17 @@ public class MeleeFighterClass : ClassBase {
case AttackState.BasicAttack1:
AnimationToPlay = "Attack1";
CreateHitBoxOffset(4, 4, 0.1f, 0.1f, 10);
CreateHitBoxOffset(4, 4, 0.1f, 0.1f, (2 * DamageMultiplier) + DamageOffset, 10);
break;
case AttackState.BasicAttack2:
AnimationToPlay = "Attack2";
CreateHitBoxOffset(4, 4, 0.1f, 0.1f, 15);
CreateHitBoxOffset(4, 4, 0.1f, 0.1f, (4 * DamageMultiplier) + DamageOffset, 15);
break;
case AttackState.BasicAttack3:
AnimationToPlay = "Attack1";
CreateHitBoxOffset(4, 4, 0.1f, 0.1f, 20);
CreateHitBoxOffset(4, 4, 0.1f, 0.1f, (6 * DamageMultiplier) + DamageOffset, 20);
break;
case AttackState.KineticSurgeRelease:

View File

@ -21,7 +21,7 @@ public class PlayerAttackAnimatorFactory : MonoBehaviour {
public void Awake() {
Instance = this;
Player = GetComponentInParent<Player>();
TextPopUp = new FloatingTextSpawner(this.transform);
TextPopUp = new FloatingTextSpawner(this.transform, 0.5f);
BuildMeleeAnimationClips();
}

View File

@ -204,7 +204,7 @@ public class Player : MonoBehaviour {
GameObject parent = hit.transform.parent?.gameObject;
Vector2 knockbakDirection = ActiveClass.HitBoxDraw.Directional ? PrevDirection : parent.transform.position - transform.position;
EnemySpawnerData.EnemyMap[parent].Damage(0, knockbakDirection, ActiveClass.HitBoxDraw.Knockback);
EnemySpawnerData.EnemyMap[parent].Damage(ActiveClass.HitBoxDraw.Damage, knockbakDirection, ActiveClass.HitBoxDraw.Knockback);
}
}

View File

@ -8,10 +8,12 @@ using UnityEngine;
public class FloatingTextSpawner {
private static GameObject GameObjectContainer = new GameObject($"Floating Text Container");
private Transform Transform;
private float YOffset;
private List<Transform> TextList = new List<Transform>();
public FloatingTextSpawner(Transform transform) {
public FloatingTextSpawner(Transform transform, float yOffset) {
Transform = transform;
YOffset = yOffset;
}
public void SpawnFloatingText(string message, Color color, float duration = 1.5f) {
@ -33,7 +35,7 @@ public class FloatingTextSpawner {
renderer.sortingLayerName = "UI";
renderer.sortingOrder = 0;
textObj.AddComponent<FloatingText>().Init(duration, ref TextList);
textObj.AddComponent<FloatingText>().Init(duration, ref TextList, YOffset);
UnityEngine.Object.Instantiate(textObj, GameObjectContainer.transform);
} catch (Exception e) { }
}
@ -47,7 +49,7 @@ public class FloatingText : MonoBehaviour {
private TextMesh textMesh;
public void Init(float duration, ref List<Transform> textList) {
public void Init(float duration, ref List<Transform> textList, float yOffset) {
try {
lifetime = duration;
textMesh = GetComponent<TextMesh>();
@ -57,7 +59,7 @@ public class FloatingText : MonoBehaviour {
if (textList[i] == null)
textList.RemoveAt(i);
else
textList[i].position += Vector3.up * 0.5f;
textList[i].position += Vector3.up * yOffset;
}
textList.Add(this.transform);