gd: basic weapon and readability refacto
This commit is contained in:
@ -1,25 +1,25 @@
|
||||
[gd_scene load_steps=31 format=3 uid="uid://bei4nhkf8lwdo"]
|
||||
[gd_scene load_steps=32 format=3 uid="uid://bei4nhkf8lwdo"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bbbrf5ckydfna" path="res://player_controller/Scripts/PlayerController.cs" id="1_poq2x"]
|
||||
[ext_resource type="Resource" uid="uid://bl5crtu1gkrtr" path="res://systems/inputs/walk_mode/base_mode.tres" id="3_cresl"]
|
||||
[ext_resource type="Resource" uid="uid://cpdaw41ah5gic" path="res://systems/inputs/walk_mode/rotate_y.tres" id="4_rxwoh"]
|
||||
[ext_resource type="Resource" uid="uid://ccrb5xsnphc8" path="res://systems/inputs/walk_mode/rotate_floorplane.tres" id="5_4u7i3"]
|
||||
[ext_resource type="Resource" uid="uid://bl5crtu1gkrtr" path="res://systems/inputs/base_mode/base_mode.tres" id="3_cresl"]
|
||||
[ext_resource type="Resource" uid="uid://cpdaw41ah5gic" path="res://systems/inputs/base_mode/rotate_y.tres" id="4_rxwoh"]
|
||||
[ext_resource type="Resource" uid="uid://ccrb5xsnphc8" path="res://systems/inputs/base_mode/rotate_floorplane.tres" id="5_4u7i3"]
|
||||
[ext_resource type="Script" uid="uid://dv7v1ywmbvvcd" path="res://player_controller/Scripts/HealthSystem.cs" id="5_umw0l"]
|
||||
[ext_resource type="Script" uid="uid://vuq8rjq3vegn" path="res://player_controller/Scripts/Stamina.cs" id="6_lxtc4"]
|
||||
[ext_resource type="Script" uid="uid://cwbvxlfvmocc1" path="res://player_controller/Scripts/StairsSystem.cs" id="7_bmt5a"]
|
||||
[ext_resource type="Resource" uid="uid://dgfww8118d8gj" path="res://systems/inputs/walk_mode/aim.tres" id="7_cresl"]
|
||||
[ext_resource type="Resource" uid="uid://j1o5ud0plk4" path="res://systems/inputs/walk_mode/aim_release.tres" id="8_lhb11"]
|
||||
[ext_resource type="Resource" uid="uid://dgfww8118d8gj" path="res://systems/inputs/base_mode/aim.tres" id="7_cresl"]
|
||||
[ext_resource type="Resource" uid="uid://j1o5ud0plk4" path="res://systems/inputs/base_mode/aim_release.tres" id="8_lhb11"]
|
||||
[ext_resource type="Script" uid="uid://dd1yrt7eiiyf4" path="res://player_controller/Scripts/CapsuleCollider.cs" id="8_lmtjd"]
|
||||
[ext_resource type="PackedScene" uid="uid://wq1okogkhc5l" path="res://systems/mantle/mantle_system.tscn" id="8_qu4wy"]
|
||||
[ext_resource type="Resource" uid="uid://7wm8ywvujwf" path="res://systems/inputs/walk_mode/aim_cancel.tres" id="9_5p2qc"]
|
||||
[ext_resource type="Resource" uid="uid://7wm8ywvujwf" path="res://systems/inputs/base_mode/aim_cancel.tres" id="9_5p2qc"]
|
||||
[ext_resource type="Script" uid="uid://bt0xv2q8iv1vn" path="res://player_controller/Scripts/Gravity.cs" id="9_lsueh"]
|
||||
[ext_resource type="Resource" uid="uid://bdit2jy5gbpts" path="res://systems/inputs/walk_mode/jump.tres" id="10_4u7i3"]
|
||||
[ext_resource type="Resource" uid="uid://bdit2jy5gbpts" path="res://systems/inputs/base_mode/jump.tres" id="10_4u7i3"]
|
||||
[ext_resource type="Script" uid="uid://g8idirw62qe0" path="res://player_controller/Scripts/Bobbing.cs" id="10_7wk1w"]
|
||||
[ext_resource type="Resource" uid="uid://b5gx3q8nvu72e" path="res://systems/inputs/walk_mode/hit.tres" id="11_cresl"]
|
||||
[ext_resource type="Resource" uid="uid://b5gx3q8nvu72e" path="res://systems/inputs/base_mode/hit.tres" id="11_cresl"]
|
||||
[ext_resource type="PackedScene" uid="uid://0ysqmqphq6mq" path="res://systems/head/head_system.tscn" id="11_rxwoh"]
|
||||
[ext_resource type="Script" uid="uid://b6k73aj5povgv" path="res://player_controller/Scripts/FieldOfView.cs" id="12_m2mxi"]
|
||||
[ext_resource type="Script" uid="uid://b5nk6ntlps3x0" path="res://systems/inputs/input_system.gd" id="16_v31n3"]
|
||||
[ext_resource type="Resource" uid="uid://htqvokm8mufq" path="res://systems/inputs/walk_mode/move.tres" id="17_h6vvl"]
|
||||
[ext_resource type="Resource" uid="uid://htqvokm8mufq" path="res://systems/inputs/base_mode/move.tres" id="17_h6vvl"]
|
||||
[ext_resource type="PackedScene" uid="uid://cqduhd4opgwvm" path="res://systems/dash/dash_system.tscn" id="18_q5h8a"]
|
||||
[ext_resource type="Script" uid="uid://dyy5njw6pxoh4" path="res://systems/move/MoveSystem.cs" id="20_rxwoh"]
|
||||
[ext_resource type="PackedScene" uid="uid://dbe5f0p6lvqtr" path="res://systems/tween_queue/tween_queue_system.tscn" id="22_rpwev"]
|
||||
@ -28,6 +28,7 @@
|
||||
[ext_resource type="Script" uid="uid://jk2jm1g6q853" path="res://addons/godot_state_charts/compound_state.gd" id="26_infe6"]
|
||||
[ext_resource type="Script" uid="uid://cytafq8i1y8qm" path="res://addons/godot_state_charts/atomic_state.gd" id="27_34snm"]
|
||||
[ext_resource type="Script" uid="uid://cf1nsco3w0mf6" path="res://addons/godot_state_charts/transition.gd" id="28_n7qhm"]
|
||||
[ext_resource type="PackedScene" uid="uid://ckm3d6k08a72u" path="res://systems/weapon/weapon.tscn" id="29_wv70j"]
|
||||
|
||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_xc2g5"]
|
||||
|
||||
@ -127,7 +128,6 @@ offset_bottom = 1.0
|
||||
initial_node_to_watch = NodePath("../StateChart")
|
||||
|
||||
[node name="StateChart" type="Node" parent="."]
|
||||
unique_name_in_owner = true
|
||||
script = ExtResource("25_wv70j")
|
||||
metadata/_custom_type_script = "uid://couw105c3bde4"
|
||||
|
||||
@ -183,6 +183,12 @@ to = NodePath("../../Dashing")
|
||||
event = &"aim_pressed"
|
||||
delay_in_seconds = "0.0"
|
||||
|
||||
[node name="WeaponRoot" type="Node3D" parent="."]
|
||||
|
||||
[node name="WeaponSystem" parent="WeaponRoot" instance=ExtResource("29_wv70j")]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.953043, 0.302836, 0, -0.302836, 0.953043, 0.45268, 1.44035, -0.692528)
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[connection signal="input_aim_canceled" from="InputController" to="." method="OnInputAimCanceled"]
|
||||
[connection signal="input_aim_pressed" from="InputController" to="." method="OnInputAimPressed"]
|
||||
[connection signal="input_aim_released" from="InputController" to="." method="OnInputAimReleased"]
|
||||
|
@ -18,7 +18,8 @@ public partial class PlayerController : CharacterBody3D
|
||||
public HealthSystem HealthSystem;
|
||||
public MoveSystem MoveSystem;
|
||||
public TweenQueueSystem TweenQueueSystem;
|
||||
public StateChart PlayerState;
|
||||
public Node3D WeaponRoot;
|
||||
public WeaponSystem WeaponSystem;
|
||||
|
||||
private bool _movementEnabled = true;
|
||||
|
||||
@ -38,82 +39,89 @@ public partial class PlayerController : CharacterBody3D
|
||||
private bool _isAiming;
|
||||
private bool _dashCanceled;
|
||||
|
||||
private StateChart _playerState;
|
||||
private StateChartState _weaponInHand;
|
||||
private StateChartState _aiming;
|
||||
private StateChartState _dashing;
|
||||
private StateChartState _weaponThrown;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
///////////////////////////
|
||||
// Getting components /////
|
||||
///////////////////////////
|
||||
|
||||
// General use stuff
|
||||
TweenQueueSystem = GetNode<TweenQueueSystem>("TweenQueueSystem");
|
||||
// Node3D mapNode = GetTree().Root.FindChild("Map", true, false) as Node3D;
|
||||
|
||||
// Camera stuff
|
||||
HeadSystem = GetNode<HeadSystem>("HeadSystem");
|
||||
Bobbing = GetNode<Bobbing>("Bobbing");
|
||||
FieldOfView = GetNode<FieldOfView>("FieldOfView");
|
||||
Camera3D camera = GetNode<Camera3D>("HeadSystem/CameraSmooth/Camera3D");
|
||||
Node3D cameraSmooth = GetNode<Node3D>("HeadSystem/CameraSmooth");
|
||||
ColorRect vignetteRect = GetNode<ColorRect>(
|
||||
"HeadSystem/CameraSmooth/Camera3D/CLVignette(Layer_1)/HealthVignetteRect");
|
||||
ColorRect distortionRect = GetNode<ColorRect>(
|
||||
"HeadSystem/CameraSmooth/Camera3D/CLDistortion(Layer_2)/HealthDistortionRect");
|
||||
ColorRect blurRect = GetNode<ColorRect>("HeadSystem/CameraSmooth/Camera3D/CLBlur(Layer_2)/BlurRect");
|
||||
|
||||
// Movement stuff
|
||||
WeaponRoot = GetNode<Node3D>("WeaponRoot");
|
||||
WeaponSystem = GetNode<WeaponSystem>("WeaponRoot/WeaponSystem");
|
||||
MantleSystem = GetNode<MantleSystem>("MantleSystem");
|
||||
CapsuleCollider = GetNode<CapsuleCollider>("CapsuleCollider");
|
||||
Gravity = GetNode<Gravity>("Gravity");
|
||||
MoveSystem = GetNode<MoveSystem>("MoveSystem");
|
||||
DashSystem = GetNode<DashSystem>("DashSystem");
|
||||
StairsSystem = GetNode<StairsSystem>("StairsSystem");
|
||||
RayCast3D stairsBelowRayCast3D = GetNode<RayCast3D>("StairsBelowRayCast3D");
|
||||
RayCast3D stairsAheadRayCast3D = GetNode<RayCast3D>("StairsAheadRayCast3D");
|
||||
_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);
|
||||
}
|
||||
|
||||
// RPG Stuff
|
||||
Stamina = GetNode<Stamina>("Stamina");
|
||||
HealthSystem = GetNode<HealthSystem>("HealthSystem");
|
||||
|
||||
// State management
|
||||
_playerState = StateChart.Of(GetNode("StateChart"));
|
||||
_weaponInHand = StateChartState.Of(GetNode("StateChart/Root/WeaponInHand"));
|
||||
_aiming = StateChartState.Of(GetNode("StateChart/Root/Aiming"));
|
||||
_dashing = StateChartState.Of(GetNode("StateChart/Root/Dashing"));
|
||||
_weaponThrown = StateChartState.Of(GetNode("StateChart/Root/WeaponThrown"));
|
||||
|
||||
///////////////////////////
|
||||
// Initialize components //
|
||||
///////////////////////////
|
||||
|
||||
// General use stuff
|
||||
TweenQueueSystem.Init(this);
|
||||
|
||||
HeadSystem = GetNode<HeadSystem>("HeadSystem");
|
||||
// Camera stuff
|
||||
HeadSystem.Init();
|
||||
Bobbing.Init(camera);
|
||||
FieldOfView.Init(camera);
|
||||
|
||||
// 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");
|
||||
|
||||
RayCast3D stairsBelowRayCast3D = GetNode<RayCast3D>("StairsBelowRayCast3D");
|
||||
RayCast3D stairsAheadRayCast3D = GetNode<RayCast3D>("StairsAheadRayCast3D");
|
||||
|
||||
// Movement stuff
|
||||
|
||||
// Getting universal setting from GODOT editor to be in sync
|
||||
float gravitySetting = (float)ProjectSettings.GetSetting("physics/3d/default_gravity");
|
||||
|
||||
ColorRect vignetteRect = GetNode<ColorRect>(
|
||||
"HeadSystem/CameraSmooth/Camera3D/CLVignette(Layer_1)/HealthVignetteRect");
|
||||
|
||||
ColorRect distortionRect = GetNode<ColorRect>(
|
||||
"HeadSystem/CameraSmooth/Camera3D/CLDistortion(Layer_2)/HealthDistortionRect");
|
||||
|
||||
ColorRect blurRect = GetNode<ColorRect>("HeadSystem/CameraSmooth/Camera3D/CLBlur(Layer_2)/BlurRect");
|
||||
|
||||
// Node3D mapNode = GetTree().Root.FindChild("Map", true, false) as Node3D;
|
||||
|
||||
// Getting components
|
||||
|
||||
Bobbing = GetNode<Bobbing>("Bobbing");
|
||||
Bobbing.Init(camera);
|
||||
|
||||
FieldOfView = GetNode<FieldOfView>("FieldOfView");
|
||||
FieldOfView.Init(camera);
|
||||
|
||||
CapsuleCollider = GetNode<CapsuleCollider>("CapsuleCollider");
|
||||
|
||||
Gravity = GetNode<Gravity>("Gravity");
|
||||
Gravity.Init(gravitySetting);
|
||||
|
||||
MantleSystem = GetNode<MantleSystem>("MantleSystem");
|
||||
MantleSystem.Init(HeadSystem);
|
||||
|
||||
TweenQueueSystem = GetNode<TweenQueueSystem>("TweenQueueSystem");
|
||||
TweenQueueSystem.Init(this);
|
||||
|
||||
MoveSystem = GetNode<MoveSystem>("MoveSystem");
|
||||
var moveSystemParams = new MoveSystem.MoveSystemParameters(this, Gravity, MantleSystem, TweenQueueSystem,
|
||||
HeadSystem, CapsuleCollider);
|
||||
MoveSystem.Init(moveSystemParams);
|
||||
|
||||
Stamina = GetNode<Stamina>("Stamina");
|
||||
Stamina.SetSpeeds(MoveSystem.WalkSpeed, MoveSystem.SprintSpeed);
|
||||
|
||||
StairsSystem = GetNode<StairsSystem>("StairsSystem");
|
||||
StairsSystem.Init(stairsBelowRayCast3D, stairsAheadRayCast3D, cameraSmooth);
|
||||
|
||||
DashSystem = GetNode<DashSystem>("DashSystem");
|
||||
DashSystem.Init(HeadSystem, camera, TweenQueueSystem);
|
||||
DashSystem.DashEnded += OnDashEnded;
|
||||
|
||||
HealthSystem = GetNode<HealthSystem>("HealthSystem");
|
||||
WeaponSystem.Init(HeadSystem, camera, TweenQueueSystem);
|
||||
|
||||
// RPG Stuff
|
||||
HealthSystem.HealthSystemInitParams healthSystemParams = new HealthSystem.HealthSystemInitParams()
|
||||
{
|
||||
Gravity = Gravity,
|
||||
@ -125,6 +133,28 @@ public partial class PlayerController : CharacterBody3D
|
||||
BlurRect = blurRect,
|
||||
};
|
||||
HealthSystem.Init(healthSystemParams);
|
||||
Stamina.SetSpeeds(MoveSystem.WalkSpeed, MoveSystem.SprintSpeed);
|
||||
|
||||
///////////////////////////
|
||||
// Signal setup ///////////
|
||||
///////////////////////////
|
||||
|
||||
DashSystem.DashEnded += OnDashEnded;
|
||||
|
||||
_dashing.StateEntered += OnDashStarted;
|
||||
_weaponThrown.StateEntered += OnWeaponThrown;
|
||||
}
|
||||
|
||||
public void OnDashStarted()
|
||||
{
|
||||
DashSystem.Dash();
|
||||
}
|
||||
|
||||
public void OnWeaponThrown()
|
||||
{
|
||||
var (hasHit, location, collisionPoint, collisionNormal) = DashSystem.DashComputation;
|
||||
var (endWithMantle, dashLocation, mantleLocation) = DashSystem.DashResolve;
|
||||
var weaponThrowVector = dashLocation - Position;
|
||||
}
|
||||
|
||||
public void OnInputMove(Vector3 value)
|
||||
@ -144,30 +174,26 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
public void OnInputAimPressed()
|
||||
{
|
||||
PlayerState.SendEvent("aim_pressed");
|
||||
|
||||
if (_dashCanceled)
|
||||
return;
|
||||
|
||||
DashSystem.PrepareDash();
|
||||
_playerState.SendEvent("aim_pressed");
|
||||
}
|
||||
public void OnInputAimReleased()
|
||||
{
|
||||
PlayerState.SendEvent("aim_released");
|
||||
if (!_dashCanceled)
|
||||
DashSystem.Dash();
|
||||
_dashCanceled = false;
|
||||
_playerState.SendEvent("aim_released");
|
||||
}
|
||||
public void OnInputAimCanceled()
|
||||
{
|
||||
PlayerState.SendEvent("aim_canceled");
|
||||
_dashCanceled = true;
|
||||
_playerState.SendEvent("aim_canceled");
|
||||
DashSystem.CancelDash();
|
||||
}
|
||||
|
||||
public void OnInputHitPressed()
|
||||
{
|
||||
PlayerState.SendEvent("hit_pressed");
|
||||
_playerState.SendEvent("hit_pressed");
|
||||
}
|
||||
|
||||
public void OnDashEnded()
|
||||
{
|
||||
_playerState.SendEvent("dash_ended");
|
||||
}
|
||||
|
||||
public void OnInputJumpPressed()
|
||||
@ -178,19 +204,19 @@ public partial class PlayerController : CharacterBody3D
|
||||
if (!doesCapsuleHaveCrouchingHeight && !isPlayerDead)
|
||||
MoveSystem.Jump(IsOnFloor());
|
||||
}
|
||||
|
||||
public void OnDashEnded()
|
||||
{
|
||||
PlayerState.SendEvent("dash_ended");
|
||||
}
|
||||
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
TweenQueueSystem.ProcessTweens();
|
||||
WeaponRoot.SetRotation(HeadSystem.Rotation);
|
||||
|
||||
var isPlayerDead = HealthSystem.IsDead();
|
||||
var isHeadTouchingCeiling = IsHeadTouchingCeiling();
|
||||
|
||||
TweenQueueSystem.ProcessTweens();
|
||||
|
||||
if (_aiming.Active)
|
||||
DashSystem.PrepareDash();
|
||||
|
||||
var moveAroundParams = new MoveSystem.MoveAroundParameters(
|
||||
delta,
|
||||
_inputMove,
|
||||
|
Reference in New Issue
Block a user