Merge remote-tracking branch 'origin/Over' into Syntriax
This commit is contained in:
3
Assets/Scripts/Orientation.meta
Normal file
3
Assets/Scripts/Orientation.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e7bd18e73b54264ba94803d6535b10c
|
||||
timeCreated: 1645462463
|
8
Assets/Scripts/Orientation/Orientation.cs
Normal file
8
Assets/Scripts/Orientation/Orientation.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Orientation
|
||||
{
|
||||
public enum Orientation
|
||||
{
|
||||
Left,
|
||||
Right
|
||||
}
|
||||
}
|
3
Assets/Scripts/Orientation/Orientation.cs.meta
Normal file
3
Assets/Scripts/Orientation/Orientation.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ec0be57a6f644319bcf493cfbbb7495
|
||||
timeCreated: 1645462472
|
@@ -1,8 +1,142 @@
|
||||
using System;
|
||||
using Movement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Player
|
||||
{
|
||||
public class PlayerController : MonoBehaviour
|
||||
public class PlayerController : MonoBehaviour, IMovement, Input.PlayerInput.IPlayerControlActions
|
||||
{
|
||||
private const float DefaultJumpForce = 1200.0f;
|
||||
private const float DefaultMass = 80.0f;
|
||||
private const float DefaultSpeed = 500.0f;
|
||||
private const float GravityScale = 3.0f;
|
||||
|
||||
private Input.PlayerInput _controls;
|
||||
private Rigidbody2D _playerRigidbody2D;
|
||||
private SpriteRenderer _playerSpriteRenderer;
|
||||
private CollisionChecker _playerGroundTrigger;
|
||||
|
||||
private bool _moveKeyPressed;
|
||||
private bool _jumpKeyPressed;
|
||||
|
||||
private bool _isOnAir;
|
||||
|
||||
private float _xAxisValue;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
this._playerRigidbody2D = gameObject.GetComponent<Rigidbody2D>();
|
||||
this._playerGroundTrigger = GameObject.Find("PlayerGroundTrigger").GetComponent<CollisionChecker>();
|
||||
this._playerSpriteRenderer = gameObject.GetComponent<SpriteRenderer>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
this._playerRigidbody2D.gravityScale = GravityScale;
|
||||
this._playerRigidbody2D.mass = DefaultMass;
|
||||
BaseSpeed = DefaultSpeed;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (_controls == null)
|
||||
{
|
||||
_controls = new Input.PlayerInput();
|
||||
_controls.PlayerControl.SetCallbacks(this);
|
||||
}
|
||||
|
||||
_controls.PlayerControl.Enable();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_controls.Disable();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (_moveKeyPressed)
|
||||
Move(_xAxisValue);
|
||||
else
|
||||
_playerRigidbody2D.velocity = new Vector2(0.0f, _playerRigidbody2D.velocity.y);
|
||||
|
||||
if (_jumpKeyPressed && _playerGroundTrigger.IsCollided)
|
||||
Jump();
|
||||
}
|
||||
|
||||
// PAUSE METHODS
|
||||
|
||||
public bool IsPaused { get; private set; }
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
IsPaused = true;
|
||||
}
|
||||
|
||||
public void Resume()
|
||||
{
|
||||
IsPaused = false;
|
||||
}
|
||||
|
||||
// MOVE METHODS
|
||||
|
||||
public float BaseSpeed { get; set; }
|
||||
|
||||
public void Move(float value)
|
||||
{
|
||||
switch (_xAxisValue)
|
||||
{
|
||||
case < 0:
|
||||
_playerSpriteRenderer.flipX = true;
|
||||
break;
|
||||
case > 0:
|
||||
_playerSpriteRenderer.flipX = false;
|
||||
break;
|
||||
}
|
||||
|
||||
_playerRigidbody2D.velocity = new Vector2(BaseSpeed * _xAxisValue * Time.fixedDeltaTime,
|
||||
_playerRigidbody2D.velocity.y);
|
||||
}
|
||||
|
||||
private void Jump()
|
||||
{
|
||||
_playerRigidbody2D.velocity = new Vector2(_playerRigidbody2D.velocity.x, 0);
|
||||
_playerRigidbody2D.AddForce(Vector2.up.normalized * DefaultJumpForce, ForceMode2D.Impulse);
|
||||
}
|
||||
|
||||
private void Climb()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// INPUT HANDLING
|
||||
|
||||
public void OnMove(InputAction.CallbackContext context)
|
||||
{
|
||||
switch (context.canceled)
|
||||
{
|
||||
case true:
|
||||
_moveKeyPressed = false;
|
||||
break;
|
||||
case false:
|
||||
_moveKeyPressed = true;
|
||||
_xAxisValue = context.ReadValue<float>();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnJump(InputAction.CallbackContext context)
|
||||
{
|
||||
switch (context.canceled)
|
||||
{
|
||||
case true:
|
||||
_jumpKeyPressed = false;
|
||||
break;
|
||||
case false:
|
||||
_jumpKeyPressed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user