gd,refacto: added state chart addon and namespace cleanup
This commit is contained in:
@ -1,9 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices.JavaScript;
|
||||
using Godot;
|
||||
using RustyOptions;
|
||||
|
||||
namespace PolarBears.PlayerControllerAddon;
|
||||
using GodotStateCharts;
|
||||
using Movementtests.systems;
|
||||
using Movementtests.player_controller.Scripts;
|
||||
|
||||
public partial class PlayerController : CharacterBody3D
|
||||
{
|
||||
@ -20,77 +18,30 @@ public partial class PlayerController : CharacterBody3D
|
||||
public HealthSystem HealthSystem;
|
||||
public MoveSystem MoveSystem;
|
||||
public TweenQueueSystem TweenQueueSystem;
|
||||
public StateChart PlayerState;
|
||||
|
||||
private bool _movementEnabled = true;
|
||||
|
||||
private bool _shouldMantle = false;
|
||||
private bool _shouldMantle;
|
||||
private Vector3 _dashLocation = Vector3.Zero;
|
||||
private Vector3 _mantleLocation = Vector3.Zero;
|
||||
|
||||
private float _lastFrameWasOnFloor = -Mathf.Inf;
|
||||
|
||||
private const int NumOfHeadCollisionDetectors = 4;
|
||||
private const int NUM_OF_HEAD_COLLISION_DETECTORS = 4;
|
||||
private RayCast3D[] _headCollisionDetectors;
|
||||
|
||||
private Vector3 _inputMove = Vector3.Zero;
|
||||
private float _inputRotateY = 0.0f;
|
||||
private float _inputRotateFloorplane = 0.0f;
|
||||
private float _inputRotateY;
|
||||
private float _inputRotateFloorplane;
|
||||
|
||||
private bool _isAiming = false;
|
||||
private bool _dashCanceled = false;
|
||||
|
||||
public void OnInputMove(Vector3 value)
|
||||
{
|
||||
_inputMove = value;
|
||||
}
|
||||
|
||||
public void OnInputRotateY(float value)
|
||||
{
|
||||
_inputRotateY = value;
|
||||
}
|
||||
|
||||
public void OnInputRotateFloorplane(float value)
|
||||
{
|
||||
_inputRotateFloorplane = value;
|
||||
}
|
||||
|
||||
public void OnInputAimPressed()
|
||||
{
|
||||
if (_dashCanceled)
|
||||
return;
|
||||
|
||||
DashSystem.PrepareDash();
|
||||
}
|
||||
public void OnInputAimReleased()
|
||||
{
|
||||
if (!_dashCanceled)
|
||||
DashSystem.Dash();
|
||||
_dashCanceled = false;
|
||||
}
|
||||
public void OnInputAimCanceled()
|
||||
{
|
||||
_dashCanceled = true;
|
||||
DashSystem.CancelDash();
|
||||
}
|
||||
|
||||
public void OnInputHitPressed()
|
||||
{
|
||||
GD.Print("OnInputHitPressed");
|
||||
}
|
||||
|
||||
public void OnInputJumpPressed()
|
||||
{
|
||||
bool doesCapsuleHaveCrouchingHeight = CapsuleCollider.IsCrouchingHeight();
|
||||
bool isPlayerDead = HealthSystem.IsDead();
|
||||
|
||||
if (!doesCapsuleHaveCrouchingHeight && !isPlayerDead)
|
||||
MoveSystem.Jump(IsOnFloor());
|
||||
}
|
||||
private bool _isAiming;
|
||||
private bool _dashCanceled;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_headCollisionDetectors = new RayCast3D[NumOfHeadCollisionDetectors];
|
||||
for (int i = 0; i < NumOfHeadCollisionDetectors; i++)
|
||||
_headCollisionDetectors = new RayCast3D[NUM_OF_HEAD_COLLISION_DETECTORS];
|
||||
for (int i = 0; i < NUM_OF_HEAD_COLLISION_DETECTORS; i++)
|
||||
{
|
||||
_headCollisionDetectors[i] = GetNode<RayCast3D>(
|
||||
"HeadCollisionDetectors/HeadCollisionDetector" + i);
|
||||
@ -99,7 +50,14 @@ public partial class PlayerController : CharacterBody3D
|
||||
HeadSystem = GetNode<HeadSystem>("HeadSystem");
|
||||
HeadSystem.Init();
|
||||
|
||||
// Getting dependencies of the components(In godot we manage this from upwards to downwards not vice versa)
|
||||
// Get the state chart node and wrap it in a StateChart object like so, GetNode doesn't work
|
||||
PlayerState = StateChart.Of(GetNode("%StateChart"));
|
||||
|
||||
// Get the poisoned state node and wrap it in a State object, so we can easily
|
||||
// interact with it from C#.
|
||||
// _poisonedStateChartState = StateChartState.Of(GetNode("%Poisoned"));
|
||||
|
||||
// Getting dependencies of the components (In godot we manage this from upwards to downwards not vice versa)
|
||||
Camera3D camera = GetNode<Camera3D>("HeadSystem/CameraSmooth/Camera3D");
|
||||
Node3D cameraSmooth = GetNode<Node3D>("HeadSystem/CameraSmooth");
|
||||
|
||||
@ -118,7 +76,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
ColorRect blurRect = GetNode<ColorRect>("HeadSystem/CameraSmooth/Camera3D/CLBlur(Layer_2)/BlurRect");
|
||||
|
||||
Node3D mapNode = GetTree().Root.FindChild("Map", true, false) as Node3D;
|
||||
// Node3D mapNode = GetTree().Root.FindChild("Map", true, false) as Node3D;
|
||||
|
||||
// Getting components
|
||||
|
||||
@ -168,6 +126,56 @@ public partial class PlayerController : CharacterBody3D
|
||||
HealthSystem.Init(healthSystemParams);
|
||||
}
|
||||
|
||||
public void OnInputMove(Vector3 value)
|
||||
{
|
||||
_inputMove = value;
|
||||
}
|
||||
|
||||
public void OnInputRotateY(float value)
|
||||
{
|
||||
_inputRotateY = value;
|
||||
}
|
||||
|
||||
public void OnInputRotateFloorplane(float value)
|
||||
{
|
||||
_inputRotateFloorplane = value;
|
||||
}
|
||||
|
||||
public void OnInputAimPressed()
|
||||
{
|
||||
PlayerState.SendEvent("aim_started");
|
||||
|
||||
if (_dashCanceled)
|
||||
return;
|
||||
|
||||
DashSystem.PrepareDash();
|
||||
}
|
||||
public void OnInputAimReleased()
|
||||
{
|
||||
if (!_dashCanceled)
|
||||
DashSystem.Dash();
|
||||
_dashCanceled = false;
|
||||
}
|
||||
public void OnInputAimCanceled()
|
||||
{
|
||||
_dashCanceled = true;
|
||||
DashSystem.CancelDash();
|
||||
}
|
||||
|
||||
public void OnInputHitPressed()
|
||||
{
|
||||
GD.Print("OnInputHitPressed");
|
||||
}
|
||||
|
||||
public void OnInputJumpPressed()
|
||||
{
|
||||
bool doesCapsuleHaveCrouchingHeight = CapsuleCollider.IsCrouchingHeight();
|
||||
bool isPlayerDead = HealthSystem.IsDead();
|
||||
|
||||
if (!doesCapsuleHaveCrouchingHeight && !isPlayerDead)
|
||||
MoveSystem.Jump(IsOnFloor());
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
TweenQueueSystem.ProcessTweens();
|
||||
@ -265,7 +273,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
private bool IsHeadTouchingCeiling()
|
||||
{
|
||||
for (int i = 0; i < NumOfHeadCollisionDetectors; i++)
|
||||
for (int i = 0; i < NUM_OF_HEAD_COLLISION_DETECTORS; i++)
|
||||
{
|
||||
if (_headCollisionDetectors[i].IsColliding())
|
||||
{
|
||||
|
Reference in New Issue
Block a user