Working player hitbox and enemy hurtbox
This commit is contained in:
parent
2ed3c12bc0
commit
6a1c1ae27a
@ -1,5 +1,74 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &845841979693538474
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 8232860728131925587}
|
||||
- component: {fileID: 1299758831766912866}
|
||||
m_Layer: 0
|
||||
m_Name: HurtBox
|
||||
m_TagString: EnemyHurtBox
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &8232860728131925587
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 845841979693538474}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 243343966221896818}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!70 &1299758831766912866
|
||||
CapsuleCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 845841979693538474}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 3
|
||||
m_Density: 1
|
||||
m_Material: {fileID: 0}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_LayerOverridePriority: 0
|
||||
m_ForceSendLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_ForceReceiveLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_ContactCaptureLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_CallbackLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_IsTrigger: 0
|
||||
m_UsedByEffector: 0
|
||||
m_CompositeOperation: 0
|
||||
m_CompositeOrder: 0
|
||||
m_Offset: {x: 0.001541889, y: -0.6988835}
|
||||
m_Size: {x: 0.56149423, y: 0.24480417}
|
||||
m_Direction: 1
|
||||
--- !u!1 &4203408371334536830
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -208,6 +277,7 @@ Transform:
|
||||
m_Children:
|
||||
- {fileID: 2045680922754072471}
|
||||
- {fileID: 1693662441197515017}
|
||||
- {fileID: 8232860728131925587}
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!70 &3140493390153182690
|
||||
|
||||
@ -8,24 +8,5 @@ namespace AI.Base {
|
||||
public class EnemyStateManager : MonoBehaviour {
|
||||
public static EnemyStateManager Instance;
|
||||
public static List<GoblerStateManager> Goblers = new List<GoblerStateManager>();
|
||||
public static Action UpdateTick;
|
||||
public static Action GizmoTick;
|
||||
|
||||
public void Awake() {
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public void Update() {
|
||||
UpdateTick?.Invoke();
|
||||
}
|
||||
|
||||
public void OnDrawGizmos() {
|
||||
//GizmoTick?.Invoke();
|
||||
}
|
||||
|
||||
public static void DrawWireSphere(Color color, Vector3 center, float radius) {
|
||||
Gizmos.color = color;
|
||||
Gizmos.DrawWireSphere(center, radius);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ using System.Xml.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class GoblerStateManager {
|
||||
public class GoblerStateManager : Alive {
|
||||
[Header("Mechanics Attributes")]
|
||||
[SerializeField] public float ChaseDistance = 10f;
|
||||
[SerializeField] public float ChaseDistanceBuffer = 1f;
|
||||
@ -40,6 +40,12 @@ public class GoblerStateManager {
|
||||
PathAgent.updateRotation = false;
|
||||
PathAgent.updateUpAxis = false;
|
||||
PathAgent.speed = Speed;
|
||||
IsUpdating = false;
|
||||
|
||||
MaxHealth = 100;
|
||||
CurrentHealth = MaxHealth;
|
||||
OnDeath += () => SetState(State.Die);
|
||||
|
||||
SetState(State.GoToCrystal);
|
||||
EnemySpawnerManager.UpdateTick += Update;
|
||||
EnemySpawnerManager.GizmoTick += OnDrawGizmos;
|
||||
@ -72,6 +78,7 @@ public class GoblerStateManager {
|
||||
private bool IsUpdating;
|
||||
protected void Update() {
|
||||
if (Owner == null) return;
|
||||
if (GameManager.Crystal == null) return;
|
||||
if (IsUpdating) return;
|
||||
IsUpdating = true;
|
||||
|
||||
@ -87,8 +94,8 @@ public class GoblerStateManager {
|
||||
case State.GoToCrystal:
|
||||
PathAgent.SetDestination(CrystalPos);
|
||||
|
||||
if (DistFromCrystal < 1)
|
||||
SetState(State.Die);
|
||||
//if (DistFromCrystal < 1)
|
||||
// SetState(State.Die);
|
||||
break;
|
||||
|
||||
|
||||
@ -102,8 +109,8 @@ public class GoblerStateManager {
|
||||
|
||||
if (DistFromPlayer > ChaseDistance + ChaseDistanceBuffer)
|
||||
SetState(State.GoToCrystal);
|
||||
else if (DistFromPlayer < 1)
|
||||
SetState(State.Die);
|
||||
//else if (DistFromPlayer < 1)
|
||||
// SetState(State.Die);
|
||||
break;
|
||||
|
||||
|
||||
@ -115,7 +122,7 @@ public class GoblerStateManager {
|
||||
|
||||
|
||||
case State.Die:
|
||||
EnemySpawnerManager.RemoveGobler(this);
|
||||
EnemySpawnerManager.RemoveGobler(Owner);
|
||||
SetState(State.None);
|
||||
break;
|
||||
|
||||
@ -172,7 +179,7 @@ public class GoblerStateManager {
|
||||
}
|
||||
|
||||
private void DrawChaseDistance() {
|
||||
EnemyStateManager.DrawWireSphere(Color.green, MyPos, ChaseDistance);
|
||||
EnemySpawnerManager.DrawWireSphere(Color.green, MyPos, ChaseDistance);
|
||||
}
|
||||
|
||||
private void DrawAttackDistance() {
|
||||
@ -188,6 +195,49 @@ public class GoblerStateManager {
|
||||
Vector2 direction2D = (PlayerPos - MyPos).normalized;
|
||||
Vector2 point2D = MyPos + direction2D * AttackDistance;
|
||||
//Gizmos.DrawWireSphere(point2D, AttackMaskDiameter);
|
||||
EnemyStateManager.DrawWireSphere(Color.red, point2D, AttackMaskDiameter);
|
||||
EnemySpawnerManager.DrawWireSphere(Color.red, point2D, AttackMaskDiameter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class Alive {
|
||||
public int MaxHealth { get; protected set; }
|
||||
public int CurrentHealth { get; protected set; }
|
||||
public bool IsDead => CurrentHealth <= 0;
|
||||
|
||||
public bool IsInvincible => Time.time < invincibleUntil;
|
||||
protected float invincibleUntil = 0f;
|
||||
|
||||
protected float invincibilityDuration = 1f;
|
||||
|
||||
public event Action<int, Vector2> OnTakeDamage;
|
||||
public event Action OnDeath;
|
||||
public event Action<int> OnHeal;
|
||||
|
||||
public void TakeDamage(int amount, Vector2 hitDirection) {
|
||||
if (IsDead || IsInvincible) return;
|
||||
|
||||
CurrentHealth -= amount;
|
||||
CurrentHealth = Mathf.Max(CurrentHealth, 0);
|
||||
invincibleUntil = Time.time + invincibilityDuration;
|
||||
|
||||
hitDirection = hitDirection.normalized;
|
||||
OnTakeDamage?.Invoke(amount, hitDirection);
|
||||
|
||||
if (CurrentHealth == 0) OnDeath?.Invoke();
|
||||
}
|
||||
|
||||
public void Heal(int amount) {
|
||||
if (IsDead) return;
|
||||
|
||||
CurrentHealth += amount;
|
||||
CurrentHealth = Mathf.Min(CurrentHealth, MaxHealth);
|
||||
OnHeal?.Invoke(amount);
|
||||
}
|
||||
|
||||
public void Reset() {
|
||||
CurrentHealth = MaxHealth;
|
||||
invincibleUntil = 0f;
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
@ -20,6 +21,8 @@ public class ClassBase {
|
||||
//[HideInInspector] public List<Ability> Abilities;
|
||||
|
||||
protected Player Player;
|
||||
protected Transform PlayerTransform { get { return Player.transform; } }
|
||||
protected Vector2 PlayerPos { get { return PlayerTransform.position; } }
|
||||
protected Animator Animator;
|
||||
protected AttackAnimatorFactory AttackAnimator;
|
||||
protected float PlayerOriginalSpeed;
|
||||
@ -91,4 +94,40 @@ public class ClassBase {
|
||||
Debug.Log($"[{Name}] Updating skill count [{SkillCount}/{SkillCountMax}]");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected Coroutine AttackCoroutine;
|
||||
protected void CreateHitBoxOffset(float centerOffset, float radius, float hitDelay, float hitDuration) {
|
||||
if (AttackCoroutine != null)
|
||||
Player.Instance.StopCoroutine(AttackCoroutine);
|
||||
var center = PlayerPos + Player.PrevDirection * centerOffset;
|
||||
AttackCoroutine = Player.Instance.StartCoroutine(CreateHitBoxHelper(center, radius, hitDelay, hitDuration));
|
||||
}
|
||||
|
||||
protected IEnumerator CreateHitBoxHelper(Vector2 center, float radius, float hitDelay, float hitDuration) {
|
||||
HitBoxDraw.Center = center;
|
||||
Debug.Log(PlayerPos);
|
||||
HitBoxDraw.Center += Vector2.down;
|
||||
HitBoxDraw.Radius = radius;
|
||||
HitBoxDraw.Color = Color.green;
|
||||
HitBoxDraw.Draw = true;
|
||||
|
||||
yield return new WaitForSeconds(hitDelay);
|
||||
HitBoxDraw.Active = true;
|
||||
HitBoxDraw.Color = Color.red;
|
||||
|
||||
yield return new WaitForSeconds(hitDuration);
|
||||
HitBoxDraw.Active = false;
|
||||
HitBoxDraw.Draw = false;
|
||||
}
|
||||
|
||||
public HitBoxDrawClass HitBoxDraw = new HitBoxDrawClass();
|
||||
public class HitBoxDrawClass {
|
||||
public bool Draw;
|
||||
public bool Active;
|
||||
public Vector2 Center;
|
||||
public float Radius;
|
||||
public Color Color;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using static UnityEngine.RuleTile.TilingRuleOutput;
|
||||
|
||||
[System.Serializable]
|
||||
public class MeleeFighterClass : ClassBase {
|
||||
@ -26,6 +28,7 @@ public class MeleeFighterClass : ClassBase {
|
||||
Skills.Add(AttackState.BladeVortex, new ClassSkill("BladeVortex", 2f, 3));
|
||||
Skills.Add(AttackState.Shockwave, new ClassSkill("Shockwave", 2f, 3));
|
||||
GenerateAvailableSkillsList();
|
||||
Player.GizmoTick += GizmoTick;
|
||||
}
|
||||
|
||||
|
||||
@ -59,11 +62,23 @@ public class MeleeFighterClass : ClassBase {
|
||||
Player.SkillInUse = false;
|
||||
return;
|
||||
|
||||
|
||||
case AttackState.BasicAttack1:
|
||||
AllowBladeVortex = ComboTimeElapsed <= 0.1f;
|
||||
break;
|
||||
|
||||
|
||||
case AttackState.BasicAttack3:
|
||||
if (ComboTimeElapsed <= 0.1) break;
|
||||
ChangeState(AttackState.KineticSurgeRelease);
|
||||
AttackAnimator.MeleeResetKineticCharge();
|
||||
AttackAnimator.MeleeKineticSurge();
|
||||
AnimationToPlay = "Attack1";
|
||||
TextPopUp.SpawnFloatingText("KineticSurge", Color.red, 3);
|
||||
AllowBladeVortex = ComboTimeElapsed <= 0.1f;
|
||||
break;
|
||||
|
||||
|
||||
//case AttackState.ChargeSurgeA:
|
||||
// ChargingAnAttack = Input.GetMouseButton(0);
|
||||
// HandleCharging(TimeElapsed);
|
||||
@ -78,15 +93,6 @@ public class MeleeFighterClass : ClassBase {
|
||||
// break;
|
||||
}
|
||||
|
||||
if (CurrentState == AttackState.BasicAttack3 && ComboTimeElapsed > 0.1) {
|
||||
ChangeState(AttackState.KineticSurgeRelease);
|
||||
AttackAnimator.MeleeResetKineticCharge();
|
||||
AttackAnimator.MeleeKineticSurge();
|
||||
AnimationToPlay = "Attack1";
|
||||
TextPopUp.SpawnFloatingText("KineticSurge", Color.red, 3);
|
||||
//Player.SkillInUse = false;
|
||||
//Player.MoveSpeed = PlayerOriginalSpeed;
|
||||
}
|
||||
|
||||
if (!ChargingAnAttack && TimesUp || Player.IsJumping) {
|
||||
Player.MoveSpeedDampener = 1;
|
||||
@ -210,8 +216,7 @@ public class MeleeFighterClass : ClassBase {
|
||||
case AttackState.None:
|
||||
if (Player.IsDashing) {
|
||||
} else if (Player.IsJumping) {
|
||||
} else {
|
||||
}
|
||||
} else { }
|
||||
break;
|
||||
|
||||
case AttackState.Shockwave:
|
||||
@ -227,16 +232,19 @@ public class MeleeFighterClass : ClassBase {
|
||||
case AttackState.BasicAttack1:
|
||||
AnimationToPlay = "Attack1";
|
||||
AttackAnimator.MeleeBasic(1);
|
||||
CreateHitBoxOffset(2, 3, 0.1f, 0.1f);
|
||||
break;
|
||||
|
||||
case AttackState.BasicAttack2:
|
||||
AnimationToPlay = "Attack2";
|
||||
AttackAnimator.MeleeBasic(2);
|
||||
CreateHitBoxOffset(2, 3, 0.1f, 0.1f);
|
||||
break;
|
||||
|
||||
case AttackState.BasicAttack3:
|
||||
AnimationToPlay = "Attack1";
|
||||
AttackAnimator.MeleeBasic(3);
|
||||
CreateHitBoxOffset(2, 3, 0.1f, 0.1f);
|
||||
break;
|
||||
|
||||
case AttackState.KineticSurgeRelease:
|
||||
@ -246,6 +254,14 @@ public class MeleeFighterClass : ClassBase {
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void GizmoTick() {
|
||||
if (HitBoxDraw == null) return;
|
||||
if (!HitBoxDraw.Draw) return;
|
||||
|
||||
Player.DrawWireSphere(HitBoxDraw.Color, HitBoxDraw.Center, HitBoxDraw.Radius);
|
||||
}
|
||||
|
||||
public void RotateTowardsMouse() {
|
||||
return;
|
||||
Vector3 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
@ -256,4 +272,6 @@ public class MeleeFighterClass : ClassBase {
|
||||
Player.LastDirection = (direction.y > 0) ? Player.Direction.Up : Player.Direction.Down;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
54
Assets/Scripts/Runtime/Characters/Player/PlayerHitHandler.cs
Normal file
54
Assets/Scripts/Runtime/Characters/Player/PlayerHitHandler.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
public class PlayerHitHandler {
|
||||
|
||||
}
|
||||
|
||||
public class PlayerHealth {
|
||||
public int MaxHealth { get; private set; }
|
||||
public int CurrentHealth { get; private set; }
|
||||
public bool IsDead => CurrentHealth <= 0;
|
||||
|
||||
public bool IsInvincible => Time.time < invincibleUntil;
|
||||
private float invincibleUntil = 0f;
|
||||
|
||||
private float invincibilityDuration = 1f; // seconds
|
||||
|
||||
public event Action<int, Vector2> OnTakeDamage;
|
||||
public event Action OnDeath;
|
||||
public event Action<int> OnHeal;
|
||||
|
||||
public PlayerHealth(int maxHealth, float invincibilityDuration = 1f) {
|
||||
MaxHealth = maxHealth;
|
||||
CurrentHealth = maxHealth;
|
||||
this.invincibilityDuration = invincibilityDuration;
|
||||
}
|
||||
|
||||
public void TakeDamage(int amount, Vector2 hitDirection) {
|
||||
if (IsDead || IsInvincible) return;
|
||||
|
||||
CurrentHealth -= amount;
|
||||
CurrentHealth = Mathf.Max(CurrentHealth, 0);
|
||||
invincibleUntil = Time.time + invincibilityDuration;
|
||||
|
||||
OnTakeDamage?.Invoke(amount, hitDirection);
|
||||
|
||||
if (CurrentHealth == 0) {
|
||||
OnDeath?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public void Heal(int amount) {
|
||||
if (IsDead) return;
|
||||
|
||||
CurrentHealth += amount;
|
||||
CurrentHealth = Mathf.Min(CurrentHealth, MaxHealth);
|
||||
OnHeal?.Invoke(amount);
|
||||
}
|
||||
|
||||
public void Reset() {
|
||||
CurrentHealth = MaxHealth;
|
||||
invincibleUntil = 0f;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 988d61f0d3db97b4fb922459bd019de3
|
||||
@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
@ -5,6 +6,7 @@ using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using static UnityEngine.EventSystems.EventTrigger;
|
||||
|
||||
[SelectionBase]
|
||||
public class Player : MonoBehaviour {
|
||||
@ -54,6 +56,7 @@ public class Player : MonoBehaviour {
|
||||
[HideInInspector] public GameObjectPool VfxShockwavePool;
|
||||
|
||||
private BoxCollider2D[] BoxColliders;
|
||||
private bool LockMovement;
|
||||
|
||||
|
||||
public Vector2 PrevDirection = Vector2.zero;
|
||||
@ -88,16 +91,21 @@ public class Player : MonoBehaviour {
|
||||
SetClass(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void Update() {
|
||||
KeyPressActions();
|
||||
GatherInput();
|
||||
UpdatePlayerStatus();
|
||||
ActiveClass.Tick();
|
||||
UpdateActiveClass();
|
||||
}
|
||||
|
||||
private void GatherInput() {
|
||||
if (LockMovement) return;
|
||||
MoveDirection.x = Input.GetAxisRaw("Horizontal");
|
||||
MoveDirection.y = Input.GetAxisRaw("Vertical");
|
||||
if (MoveDirection.x != 0 || MoveDirection.y != 0)
|
||||
PrevDirection = MoveDirection;
|
||||
}
|
||||
|
||||
private void KeyPressActions() {
|
||||
@ -123,6 +131,7 @@ public class Player : MonoBehaviour {
|
||||
private void DoDash() {
|
||||
if (!CanDash) return;
|
||||
if (!ActionAfterJumpReady) return;
|
||||
if (LockMovement) return;
|
||||
if (Stamina < 25) return;
|
||||
Stamina -= 25;
|
||||
CanDash = false;
|
||||
@ -130,12 +139,16 @@ public class Player : MonoBehaviour {
|
||||
DashDirection = MoveDirection.normalized;
|
||||
if (DashDirection == Vector2.zero) return;
|
||||
DashSpeed = DashSpeedInitial;
|
||||
if (IsJumping) {
|
||||
LockMovement = true;
|
||||
DashSpeed /= 2;
|
||||
}
|
||||
}
|
||||
|
||||
private void Jump() {
|
||||
private void Jump(bool setJumpTime = true) {
|
||||
if (SkillInUse) return;
|
||||
IsJumping = true;
|
||||
LastJumpTime = Time.time;
|
||||
if (setJumpTime) LastJumpTime = Time.time;
|
||||
foreach (var col in BoxColliders)
|
||||
col.enabled = false;
|
||||
if (CoroutineJumpReset != null)
|
||||
@ -150,6 +163,7 @@ public class Player : MonoBehaviour {
|
||||
foreach (var col in BoxColliders)
|
||||
col.enabled = true;
|
||||
IsJumping = false;
|
||||
LockMovement = false;
|
||||
MoveSpeedDampener = 1;
|
||||
}
|
||||
|
||||
@ -178,6 +192,20 @@ public class Player : MonoBehaviour {
|
||||
StaminaSliderHud.value = Stamina;
|
||||
}
|
||||
|
||||
private void UpdateActiveClass() {
|
||||
if (ActiveClass == null) return;
|
||||
ActiveClass.Tick();
|
||||
|
||||
if (ActiveClass.HitBoxDraw == null) return;
|
||||
if (!ActiveClass.HitBoxDraw.Active) return;
|
||||
Collider2D[] hits = Physics2D.OverlapCircleAll(ActiveClass.HitBoxDraw.Center, ActiveClass.HitBoxDraw.Radius);
|
||||
foreach (var hit in hits) {
|
||||
if (!hit.CompareTag("EnemyHurtBox")) continue;
|
||||
|
||||
GameObject parent = hit.transform.parent?.gameObject;
|
||||
EnemySpawnerData.Goblers[parent].TakeDamage(30, transform.position - parent.transform.position);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -193,13 +221,16 @@ public class Player : MonoBehaviour {
|
||||
private void MovementUpdate() {
|
||||
var movement = (MoveDirection.normalized * MoveSpeed) / MoveSpeedDampener;
|
||||
if (IsDashing) {
|
||||
if (DashSpeed < 0.2f) {
|
||||
if (DashSpeed < (IsJumping ? 0.4f : 0.2f)) {
|
||||
DashSpeed = 0;
|
||||
CanDash = true;
|
||||
IsDashing = false;
|
||||
} else if (DashSpeed > (movement.magnitude * 2)) {
|
||||
if (IsJumping) Jump();
|
||||
if (IsJumping) Jump(false);
|
||||
movement = DashDirection * DashSpeed;
|
||||
if (IsJumping)
|
||||
DashSpeed *= Mathf.Exp(-DashDecayRate * Time.deltaTime / 3);
|
||||
else
|
||||
DashSpeed *= Mathf.Exp(-DashDecayRate * Time.deltaTime);
|
||||
} else {
|
||||
movement = ((DashDirection * DashSpeed) + movement) / 2;
|
||||
@ -221,22 +252,93 @@ public class Player : MonoBehaviour {
|
||||
public enum Direction { Up, Down, Left, Right }
|
||||
public Direction LastDirection = Direction.Down;
|
||||
private string GetAnimationState(Vector2 input) {
|
||||
if (SkillInUse) return ActiveClass.AnimationToPlay;
|
||||
if (!IsJumping && input.sqrMagnitude < 0.01f) return "Idle";
|
||||
|
||||
if (Mathf.Abs(input.x) > 0)
|
||||
LastDirection = (input.x > 0) ? Direction.Right : Direction.Left;
|
||||
else if (Mathf.Abs(input.y) > 0)
|
||||
LastDirection = (input.y > 0) ? Direction.Up : Direction.Down;
|
||||
|
||||
|
||||
if (SkillInUse) return ActiveClass.AnimationToPlay;
|
||||
if (!IsJumping && input.sqrMagnitude < 0.01f) return "Idle";
|
||||
if (IsJumping) return "Jump";
|
||||
return "Run";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//[Header("Health Settings")]
|
||||
//public int maxHealth = 100;
|
||||
//public float invincibilityTime = 1f;
|
||||
|
||||
//[Header("Knockback")]
|
||||
//public float knockbackForce = 5f;
|
||||
|
||||
//private Rigidbody2D rb;
|
||||
//private PlayerHealth health;
|
||||
|
||||
//void Start() {
|
||||
// rb = GetComponent<Rigidbody2D>();
|
||||
// health = new PlayerHealth(maxHealth, invincibilityTime);
|
||||
|
||||
// health.OnTakeDamage += HandleDamage;
|
||||
// health.OnDeath += HandleDeath;
|
||||
// health.OnHeal += HandleHeal;
|
||||
//}
|
||||
|
||||
//void HandleDamage(int damage, Vector2 hitDirection) {
|
||||
// Debug.Log($"Took {damage} damage from {hitDirection}. Remaining: {health.CurrentHealth}");
|
||||
|
||||
// // Apply knockback
|
||||
// Vector2 knockDir = hitDirection.normalized;
|
||||
// rb.velocity = Vector2.zero; // cancel momentum before applying
|
||||
// rb.AddForce(knockDir * knockbackForce, ForceMode2D.Impulse);
|
||||
|
||||
// // TODO: Play hit animation, flash sprite, etc.
|
||||
//}
|
||||
|
||||
//void HandleHeal(int amount) {
|
||||
// Debug.Log($"Healed {amount}. Current HP: {health.CurrentHealth}");
|
||||
//}
|
||||
|
||||
//void HandleDeath() {
|
||||
// Debug.Log("Player has died.");
|
||||
// // TODO: Trigger death animation, disable input, etc.
|
||||
//}
|
||||
|
||||
//public void ReceiveHit(int damage, Vector2 hitOrigin) {
|
||||
// Vector2 hitDirection = (transform.position - (Vector3)hitOrigin).normalized;
|
||||
// health.TakeDamage(damage, hitDirection);
|
||||
//}
|
||||
|
||||
//public void Heal(int amount) {
|
||||
// health.Heal(amount);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static Action GizmoTick;
|
||||
void OnDrawGizmos() {
|
||||
DrawPlayerDirection();
|
||||
GizmoTick?.Invoke();
|
||||
}
|
||||
|
||||
public static void DrawWireSphere(Color color, Vector3 center, float radius) {
|
||||
Gizmos.color = color;
|
||||
Gizmos.DrawWireSphere(center, radius);
|
||||
}
|
||||
|
||||
private void DrawPlayerDirection() {
|
||||
|
||||
@ -34,15 +34,14 @@ public class EnemySpawnerManager : MonoBehaviour {
|
||||
GoblerPool = new GameObjectPool(GoblerPreFab, 50, 200);
|
||||
}
|
||||
|
||||
public static void RemoveGobler(GoblerStateManager goblerManager) {
|
||||
Destroy(EnemySpawnerData.Goblers[goblerManager]);
|
||||
EnemySpawnerData.Goblers.Remove(goblerManager);
|
||||
public static void RemoveGobler(GameObject gameObject) {
|
||||
Destroy(gameObject);
|
||||
EnemySpawnerData.Goblers.Remove(gameObject);
|
||||
}
|
||||
|
||||
public void Update() {
|
||||
StartSpawning();
|
||||
UpdateTick?.Invoke();
|
||||
GizmoTick?.Invoke();
|
||||
}
|
||||
|
||||
public void StartSpawning() {
|
||||
@ -50,18 +49,23 @@ public class EnemySpawnerManager : MonoBehaviour {
|
||||
|
||||
while (EnemySpawnerData.Goblers.Count() < EnemySpawnerData.MaxGoblers) {
|
||||
var gobler = GoblerPool.Get(transform.position, Quaternion.identity);
|
||||
EnemySpawnerData.Goblers.Add(new GoblerStateManager(gobler), gobler);
|
||||
EnemySpawnerData.Goblers.Add(gobler, new GoblerStateManager(gobler));
|
||||
}
|
||||
|
||||
CanStartSpawning = false;
|
||||
}
|
||||
|
||||
public static void OnDrawGizmos() {
|
||||
public void OnDrawGizmos() {
|
||||
GizmoTick?.Invoke();
|
||||
}
|
||||
|
||||
public static void DrawWireSphere(Color color, Vector3 center, float radius) {
|
||||
Gizmos.color = color;
|
||||
Gizmos.DrawWireSphere(center, radius);
|
||||
}
|
||||
}
|
||||
|
||||
public static class EnemySpawnerData {
|
||||
public static Dictionary<GoblerStateManager, GameObject> Goblers = new Dictionary<GoblerStateManager, GameObject>();
|
||||
public static Dictionary<GameObject, GoblerStateManager> Goblers = new Dictionary<GameObject, GoblerStateManager>();
|
||||
public static int MaxGoblers = 100;
|
||||
}
|
||||
|
||||
@ -466,22 +466,22 @@ MonoBehaviour:
|
||||
x: 0
|
||||
y: 21
|
||||
width: 967.33325
|
||||
height: 513
|
||||
m_Scale: {x: 0.7125, y: 0.7125}
|
||||
m_Translation: {x: 483.66663, y: 256.5}
|
||||
height: 510.3333
|
||||
m_Scale: {x: 0.70879626, y: 0.70879626}
|
||||
m_Translation: {x: 483.66663, y: 255.16666}
|
||||
m_MarginLeft: 0
|
||||
m_MarginRight: 0
|
||||
m_MarginTop: 0
|
||||
m_MarginBottom: 0
|
||||
m_LastShownAreaInsideMargins:
|
||||
serializedVersion: 2
|
||||
x: -678.8304
|
||||
x: -682.3775
|
||||
y: -360
|
||||
width: 1357.6608
|
||||
width: 1364.755
|
||||
height: 720
|
||||
m_MinimalGUI: 1
|
||||
m_defaultScale: 0.7125
|
||||
m_LastWindowPixelSize: {x: 967.33325, y: 534}
|
||||
m_defaultScale: 0.70879626
|
||||
m_LastWindowPixelSize: {x: 967.33325, y: 531.3333}
|
||||
m_ClearInEditMode: 1
|
||||
m_NoCameraWarning: 1
|
||||
m_LowResolutionForAspectRatios: 00000000000000000000
|
||||
@ -1030,6 +1030,20 @@ MonoBehaviour:
|
||||
layout: 4
|
||||
size: {x: 0, y: 0}
|
||||
sizeOverridden: 0
|
||||
- dockPosition: 1
|
||||
containerId: overlay-container--right
|
||||
displayed: 0
|
||||
id: AINavigationOverlay
|
||||
index: 15
|
||||
contents: '{"m_Layout":4,"m_Collapsed":false,"m_Floating":false,"m_FloatingSnapOffset":{"x":0.0,"y":0.0},"m_SnapOffsetDelta":{"x":0.0,"y":0.0},"m_FloatingSnapCorner":0,"m_Size":{"x":0.0,"y":0.0},"m_SizeOverridden":false}'
|
||||
floating: 0
|
||||
collapsed: 0
|
||||
snapOffset: {x: 0, y: 0}
|
||||
snapOffsetDelta: {x: 0, y: 0}
|
||||
snapCorner: 0
|
||||
layout: 4
|
||||
size: {x: 0, y: 0}
|
||||
sizeOverridden: 0
|
||||
m_ContainerData:
|
||||
- containerId: overlay-toolbar__top
|
||||
scrollOffset: 0
|
||||
@ -1057,7 +1071,7 @@ MonoBehaviour:
|
||||
m_AudioPlay: 0
|
||||
m_DebugDrawModesUseInteractiveLightBakingData: 0
|
||||
m_Position:
|
||||
m_Target: {x: 18.246088, y: -15.302499, z: -0.026065793}
|
||||
m_Target: {x: 2.3566494, y: 51.885063, z: 0}
|
||||
speed: 2
|
||||
m_Value: {x: 18.246088, y: -15.302499, z: -0.026065793}
|
||||
m_RenderMode: 0
|
||||
@ -1109,7 +1123,7 @@ MonoBehaviour:
|
||||
speed: 2
|
||||
m_Value: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_Size:
|
||||
m_Target: 12.606543
|
||||
m_Target: 31.994295
|
||||
speed: 2
|
||||
m_Value: 12.606543
|
||||
m_Ortho:
|
||||
@ -1375,7 +1389,7 @@ MonoBehaviour:
|
||||
scrollPos: {x: 0, y: 0}
|
||||
m_SelectedIDs: 03ca9a3b
|
||||
m_LastClickedID: 1000000003
|
||||
m_ExpandedIDs: 00000000e8a50000eaa50000eca50000eea50000f0a50000f2a50000f4a50000f6a50000f8a50000faa50000fca50000fea5000000a6000002a6000004a6000006a6000008a600000aa600000ca600000ea6000010a6000012a6000014a6000016a6000018a600001aa600001ca600001ea6000020a6000022a6000024a6000026a6000028a600002aa60000
|
||||
m_ExpandedIDs: 00000000aea70000b0a70000b2a70000b4a70000b6a70000b8a70000baa70000bca70000bea70000c0a70000c2a70000c4a70000c6a70000c8a70000caa70000cca70000cea70000d0a70000d2a70000d4a70000d6a70000d8a70000daa70000dca70000dea70000e0a70000e2a70000e4a70000e6a70000e8a70000eaa70000eca70000eea70000f0a70000
|
||||
m_RenameOverlay:
|
||||
m_UserAcceptedRename: 0
|
||||
m_Name:
|
||||
@ -1404,7 +1418,7 @@ MonoBehaviour:
|
||||
scrollPos: {x: 0, y: 0}
|
||||
m_SelectedIDs:
|
||||
m_LastClickedID: 0
|
||||
m_ExpandedIDs: 00000000e8a50000eaa50000eca50000eea50000f0a50000f2a50000f4a50000f6a50000f8a50000faa50000fca50000fea5000000a6000002a6000004a6000006a6000008a600000aa600000ca600000ea6000010a6000012a6000014a6000016a6000018a600001aa600001ca600001ea6000020a6000022a6000024a6000026a6000028a600002aa60000
|
||||
m_ExpandedIDs: 00000000aea70000b0a70000b2a70000b4a70000b6a70000b8a70000baa70000bca70000bea70000c0a70000c2a70000c4a70000c6a70000c8a70000caa70000cca70000cea70000d0a70000d2a70000d4a70000d6a70000d8a70000daa70000dca70000dea70000e0a70000e2a70000e4a70000e6a70000e8a70000eaa70000eca70000eea70000f0a70000
|
||||
m_RenameOverlay:
|
||||
m_UserAcceptedRename: 0
|
||||
m_Name:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user