convert game playing..
This commit is contained in:
@@ -16,6 +16,8 @@ namespace BumpCombat.Player
|
||||
Animator.StringToHash("Base Layer.BackBumpAttack");
|
||||
private static readonly int ArtifactUseState =
|
||||
Animator.StringToHash("Base Layer.ArtifactUse");
|
||||
private static readonly int DeathState =
|
||||
Animator.StringToHash("Base Layer.Death");
|
||||
|
||||
public const string BumpAttackStateName = "BumpAttack";
|
||||
public const string BackBumpAttackStateName = "BackBumpAttack";
|
||||
@@ -45,6 +47,7 @@ namespace BumpCombat.Player
|
||||
public bool IsDamageKnockbackActive { get; private set; }
|
||||
public bool IsHurtMovementLocked =>
|
||||
playerHealth != null && playerHealth.IsHurtMovementLocked;
|
||||
public bool IsTransitionLocked { get; private set; }
|
||||
public Vector2 PlayerClampHalfExtents
|
||||
{
|
||||
get
|
||||
@@ -95,6 +98,23 @@ namespace BumpCombat.Player
|
||||
return TryPlayCombatAnimation(ArtifactUseState, false);
|
||||
}
|
||||
|
||||
public float PlayDeathAnimation()
|
||||
{
|
||||
if (animator == null
|
||||
|| animator.runtimeAnimatorController == null
|
||||
|| !animator.isActiveAndEnabled
|
||||
|| !animator.HasState(0, DeathState))
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
|
||||
SetTransitionLocked(true);
|
||||
animator.SetBool(IsMovingParameter, false);
|
||||
animator.Play(DeathState, 0, 0f);
|
||||
animator.Update(0f);
|
||||
return Mathf.Max(0f, animator.GetCurrentAnimatorStateInfo(0).length);
|
||||
}
|
||||
|
||||
private bool TryPlayCombatAnimation(
|
||||
int stateHash,
|
||||
bool blockActiveArtifactUse)
|
||||
@@ -148,7 +168,7 @@ namespace BumpCombat.Player
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!RunManager.GameplayInputEnabled || IsHurtMovementLocked)
|
||||
if (!RunManager.GameplayInputEnabled || IsHurtMovementLocked || IsTransitionLocked)
|
||||
{
|
||||
SetMoveInput(Vector2.zero);
|
||||
return;
|
||||
@@ -172,6 +192,13 @@ namespace BumpCombat.Player
|
||||
private void FixedUpdate()
|
||||
{
|
||||
AttackIntentVelocity = Vector2.zero;
|
||||
if (IsTransitionLocked)
|
||||
{
|
||||
if (body != null) body.linearVelocity = Vector2.zero;
|
||||
CurrentVelocity = Vector2.zero;
|
||||
return;
|
||||
}
|
||||
|
||||
if (dashController != null && dashController.IsDashing)
|
||||
{
|
||||
pendingImpactRecoil = Vector2.zero;
|
||||
@@ -244,6 +271,57 @@ namespace BumpCombat.Player
|
||||
- GameplayConstants.Current.Player.ArenaPadding.y));
|
||||
}
|
||||
|
||||
public Vector2 ClampMovementToTerrain(Vector2 start, Vector2 desiredPosition)
|
||||
{
|
||||
Vector2 desired = ClampToArena(desiredPosition);
|
||||
Vector2 delta = desired - start;
|
||||
float distance = delta.magnitude;
|
||||
if (distance <= 0.0001f)
|
||||
{
|
||||
return desired;
|
||||
}
|
||||
|
||||
Collider2D ownCollider = GetComponent<Collider2D>();
|
||||
float radius = 0.2f;
|
||||
if (ownCollider != null)
|
||||
{
|
||||
Vector2 extents = ownCollider.bounds.extents;
|
||||
radius = Mathf.Max(0.05f, Mathf.Min(extents.x, extents.y) * 0.9f);
|
||||
}
|
||||
|
||||
Vector2 direction = delta / distance;
|
||||
RaycastHit2D[] hits = Physics2D.CircleCastAll(
|
||||
start,
|
||||
radius,
|
||||
direction,
|
||||
distance,
|
||||
Physics2D.AllLayers);
|
||||
float allowedDistance = distance;
|
||||
for (int i = 0; i < hits.Length; i++)
|
||||
{
|
||||
Collider2D collider = hits[i].collider;
|
||||
if (collider == null
|
||||
|| collider.isTrigger
|
||||
|| collider == ownCollider
|
||||
|| collider.transform.IsChildOf(transform))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bool isTerrain = collider.GetComponentInParent<BumpCombat.Stage.StageObstacle>() != null
|
||||
|| collider.name.StartsWith("Wall_")
|
||||
|| collider.gameObject.name.Contains("Wall");
|
||||
if (isTerrain)
|
||||
{
|
||||
allowedDistance = Mathf.Min(
|
||||
allowedDistance,
|
||||
Mathf.Max(0f, hits[i].distance - 0.02f));
|
||||
}
|
||||
}
|
||||
|
||||
return start + direction * allowedDistance;
|
||||
}
|
||||
|
||||
public bool TryReposition(Vector2 position)
|
||||
{
|
||||
if (body == null)
|
||||
@@ -338,5 +416,36 @@ namespace BumpCombat.Player
|
||||
spriteRenderer.flipX = input.x < 0f;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTransitionLocked(bool locked)
|
||||
{
|
||||
IsTransitionLocked = locked;
|
||||
if (locked)
|
||||
{
|
||||
moveInput = Vector2.zero;
|
||||
CurrentVelocity = Vector2.zero;
|
||||
AttackIntentVelocity = Vector2.zero;
|
||||
if (body != null)
|
||||
{
|
||||
body.linearVelocity = Vector2.zero;
|
||||
}
|
||||
if (animator != null && animator.isActiveAndEnabled)
|
||||
{
|
||||
animator.SetBool(IsMovingParameter, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFacingDirection(Vector2 direction)
|
||||
{
|
||||
if (direction.sqrMagnitude > 0.0001f)
|
||||
{
|
||||
FacingDirection = direction.normalized;
|
||||
if (spriteRenderer != null && !Mathf.Approximately(direction.x, 0f))
|
||||
{
|
||||
spriteRenderer.flipX = direction.x < 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user