2024-02-02 22:43:39 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.InputSystem;
|
2024-02-03 15:21:45 +01:00
|
|
|
using System.Linq;
|
2024-02-04 04:56:01 +01:00
|
|
|
using UnityEngine.InputSystem.DualShock;
|
2024-02-02 22:43:39 +01:00
|
|
|
|
2024-02-03 16:21:32 +01:00
|
|
|
[RequireComponent(typeof(PlayerInput))]
|
2024-02-03 14:07:03 +01:00
|
|
|
public class PlayerMovement : MonoBehaviour
|
2024-02-02 22:43:39 +01:00
|
|
|
{
|
|
|
|
public float moveSpeed = 5f;
|
|
|
|
private Rigidbody2D rb;
|
|
|
|
|
|
|
|
private bool right = false;
|
|
|
|
|
2024-02-03 14:07:03 +01:00
|
|
|
[Header("Whipping")]
|
|
|
|
[SerializeField]
|
2024-02-14 04:30:38 +01:00
|
|
|
//RopeWhipAttack whipAttack;
|
2024-02-04 09:52:47 +01:00
|
|
|
public float whipSmashSpeed = 2f;
|
|
|
|
public float whipSmashDamageMult = 2f;
|
2024-02-03 14:07:03 +01:00
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private float whipMoveSpeed = 25f;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private float maxWhipMoveSpeed = 30f;
|
|
|
|
|
2024-03-01 19:44:22 +01:00
|
|
|
private IMoveData playerInput;
|
2024-02-03 16:21:32 +01:00
|
|
|
|
2024-02-04 02:58:23 +01:00
|
|
|
private HealthComponent hp;
|
2024-02-04 09:52:47 +01:00
|
|
|
private PlayerCollideAttack attack;
|
2024-02-04 02:58:23 +01:00
|
|
|
|
2024-02-02 22:43:39 +01:00
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
rb = GetComponent<Rigidbody2D>();
|
2024-02-04 02:58:23 +01:00
|
|
|
hp = GetComponent<HealthComponent>();
|
2024-02-04 10:31:50 +01:00
|
|
|
attack = GetComponent<PlayerCollideAttack>();
|
2024-02-02 22:43:39 +01:00
|
|
|
|
2024-03-01 19:44:22 +01:00
|
|
|
// Try to get middleman first
|
|
|
|
if (TryGetComponent(out ReconciliationPlayerControllerMiddleman middleman))
|
2024-02-03 21:35:06 +01:00
|
|
|
{
|
2024-03-01 19:44:22 +01:00
|
|
|
playerInput = middleman;
|
2024-02-03 21:35:06 +01:00
|
|
|
}
|
2024-03-01 19:44:22 +01:00
|
|
|
else
|
2024-02-04 04:56:01 +01:00
|
|
|
{
|
2024-03-02 15:07:08 +01:00
|
|
|
Debug.LogWarning("[Network][Movement] Could not find input middleman. Defaulting back to normal player input");
|
2024-03-01 19:44:22 +01:00
|
|
|
playerInput = GetComponent<PlayerInput>();
|
2024-02-04 04:56:01 +01:00
|
|
|
}
|
2024-02-04 06:27:28 +01:00
|
|
|
|
2024-03-01 19:44:22 +01:00
|
|
|
playerInput.OnNewMoveData += PlayerInput_OnNewMoveData;
|
|
|
|
|
2024-02-04 06:27:28 +01:00
|
|
|
}
|
|
|
|
|
2024-03-01 19:44:22 +01:00
|
|
|
private void PlayerInput_OnNewMoveData(MoveData moveData)
|
2024-02-02 22:43:39 +01:00
|
|
|
{
|
2024-03-01 19:44:22 +01:00
|
|
|
rb.AddForce(moveData.Movement * moveSpeed);
|
2024-02-02 22:43:39 +01:00
|
|
|
}
|
2024-03-01 19:44:22 +01:00
|
|
|
|
2024-02-04 09:12:58 +01:00
|
|
|
void OnCollisionStay2D(Collision2D collision)
|
|
|
|
{
|
|
|
|
if (collision.collider.gameObject.CompareTag("Enemy"))
|
|
|
|
{ // Other object is an enemy
|
2024-02-06 14:21:29 +01:00
|
|
|
|
2024-03-01 19:44:22 +01:00
|
|
|
hp.TakeDamage(1f);
|
2024-02-06 14:21:29 +01:00
|
|
|
|
2024-02-04 09:12:58 +01:00
|
|
|
}
|
|
|
|
}
|
2024-02-02 22:43:39 +01:00
|
|
|
}
|