feat: Phase 1 complete - attack system, enemy damage, timers, and study notes summary
This commit is contained in:
@@ -5,11 +5,20 @@ public class Player : MonoBehaviour
|
||||
private Animator anim;
|
||||
private Rigidbody2D rb;
|
||||
|
||||
|
||||
[Header("Attack details")]
|
||||
[SerializeField] private float attackRadius;
|
||||
[SerializeField] private Transform attackPoint;
|
||||
[SerializeField] private LayerMask whatIsEnemy;
|
||||
|
||||
|
||||
[Header("Movement details")]
|
||||
[SerializeField] private float moveSpeed = 4.58f;
|
||||
[SerializeField] private float moveSpeed = 8f;
|
||||
[SerializeField] private float jumpForce = 12;
|
||||
private bool facingRight = true;
|
||||
private float xInput;
|
||||
private bool canMove = true;
|
||||
private bool canJump = true;
|
||||
|
||||
[Header("Collision details")]
|
||||
[SerializeField] private float groundCheckDistance;
|
||||
@@ -32,31 +41,66 @@ public class Player : MonoBehaviour
|
||||
HandleFlip();
|
||||
}
|
||||
|
||||
public void DamageEnemies()
|
||||
{
|
||||
Collider2D[] enemyColliders = Physics2D.OverlapCircleAll(attackPoint.position, attackRadius, whatIsEnemy);
|
||||
foreach (Collider2D enemy in enemyColliders)
|
||||
{
|
||||
enemy.GetComponent<Enemy>().TakeDamage();
|
||||
}
|
||||
}
|
||||
|
||||
public void EnableMovementAndJump(bool enable)
|
||||
{
|
||||
canMove = enable;
|
||||
canJump = enable;
|
||||
}
|
||||
|
||||
private void HandleInput()
|
||||
{
|
||||
xInput = Input.GetAxisRaw("Horizontal");
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.K))
|
||||
{
|
||||
jump();
|
||||
TryToJump();
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.J))
|
||||
{
|
||||
TryToAttack();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void TryToAttack()
|
||||
{
|
||||
if(isGrounded && canMove)
|
||||
{
|
||||
anim.SetTrigger("attack");
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleAnimations()
|
||||
{
|
||||
bool isMoving = rb.linearVelocity.x != 0;
|
||||
anim.SetBool("isMoving", isMoving);
|
||||
anim.SetFloat("xVelocity", rb.linearVelocity.x);
|
||||
anim.SetFloat("yVelocity", rb.linearVelocity.y);
|
||||
anim.SetBool("isGrounded", isGrounded);
|
||||
}
|
||||
|
||||
private void HandleMovement()
|
||||
{
|
||||
rb.linearVelocity = new Vector2(xInput * moveSpeed, rb.linearVelocity.y);
|
||||
if(canMove)
|
||||
{
|
||||
rb.linearVelocity = new Vector2(xInput * moveSpeed, rb.linearVelocity.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
rb.linearVelocity = new Vector2(0, rb.linearVelocity.y);
|
||||
}
|
||||
}
|
||||
|
||||
private void jump()
|
||||
private void TryToJump()
|
||||
{
|
||||
if (isGrounded)
|
||||
if (isGrounded && canJump)
|
||||
{
|
||||
rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpForce);
|
||||
}
|
||||
@@ -69,7 +113,7 @@ public class Player : MonoBehaviour
|
||||
|
||||
private void HandleFlip()
|
||||
{
|
||||
if(rb.linearVelocity.x > 0 && facingRight == false)
|
||||
if (rb.linearVelocity.x > 0 && facingRight == false)
|
||||
{
|
||||
Flip();
|
||||
}
|
||||
@@ -88,6 +132,7 @@ public class Player : MonoBehaviour
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
Gizmos.DrawLine(transform.position, transform.position + new Vector3(0, -groundCheckDistance));
|
||||
Gizmos.DrawWireSphere(attackPoint.position, attackRadius);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user