mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 00:05:53 +00:00
FSM Player movement
This commit is contained in:
parent
7d9db8cfb6
commit
c59a480ffd
10 changed files with 131 additions and 36 deletions
|
|
@ -1,4 +1,4 @@
|
|||
[gd_resource type="Resource" script_class="DebugMapSelectData" load_steps=28 format=3 uid="uid://d1lc8lhq1b05p"]
|
||||
[gd_resource type="Resource" script_class="DebugMapSelectData" load_steps=29 format=3 uid="uid://d1lc8lhq1b05p"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://durmwwyw3dnm6" path="res://Scripts/Resources/DebugMenu/DebugMapSelectData.cs" id="1_6kwth"]
|
||||
[ext_resource type="Script" uid="uid://mja0rk7n2kln" path="res://Scripts/Resources/MapStartDataResource.cs" id="1_ov731"]
|
||||
|
|
@ -19,7 +19,7 @@ _name = "Intro"
|
|||
[sub_resource type="Resource" id="Resource_cfhv5"]
|
||||
script = ExtResource("1_ov731")
|
||||
EggIndex = 0
|
||||
StartingEquipment = Array[ExtResource("2_bkci5")]([])
|
||||
StartingEquipment = []
|
||||
|
||||
[sub_resource type="Resource" id="Resource_0k62o"]
|
||||
script = ExtResource("2_tnajf")
|
||||
|
|
@ -31,7 +31,7 @@ StartData = SubResource("Resource_cfhv5")
|
|||
[sub_resource type="Resource" id="Resource_tpb7s"]
|
||||
script = ExtResource("1_ov731")
|
||||
EggIndex = 0
|
||||
StartingEquipment = Array[ExtResource("2_bkci5")]([])
|
||||
StartingEquipment = []
|
||||
|
||||
[sub_resource type="Resource" id="Resource_edoov"]
|
||||
script = ExtResource("2_tnajf")
|
||||
|
|
@ -43,7 +43,7 @@ StartData = SubResource("Resource_tpb7s")
|
|||
[sub_resource type="Resource" id="Resource_1sw5g"]
|
||||
script = ExtResource("1_ov731")
|
||||
EggIndex = 255
|
||||
StartingEquipment = Array[ExtResource("2_bkci5")]([])
|
||||
StartingEquipment = []
|
||||
|
||||
[sub_resource type="Resource" id="Resource_47bot"]
|
||||
script = ExtResource("2_tnajf")
|
||||
|
|
@ -73,7 +73,7 @@ _name = "Rebel Base"
|
|||
[sub_resource type="Resource" id="Resource_maxpt"]
|
||||
script = ExtResource("1_ov731")
|
||||
EggIndex = 0
|
||||
StartingEquipment = Array[ExtResource("2_bkci5")]([])
|
||||
StartingEquipment = []
|
||||
|
||||
[sub_resource type="Resource" id="Resource_pein5"]
|
||||
script = ExtResource("2_tnajf")
|
||||
|
|
@ -118,6 +118,13 @@ Path = "res://Scenes/Maps/NewActorTest.tscn"
|
|||
_name = "New Actor Test"
|
||||
StartData = SubResource("Resource_ujm2a")
|
||||
|
||||
[sub_resource type="Resource" id="Resource_bkci5"]
|
||||
script = ExtResource("2_tnajf")
|
||||
Enabled = true
|
||||
Path = "res://Scenes/Maps/PlayerFSMTest.tscn"
|
||||
_name = "FSM Test"
|
||||
metadata/_custom_type_script = "uid://dnthdjrx78u6m"
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_6kwth")
|
||||
Maps = Array[Object]([SubResource("Resource_qnbi6"), SubResource("Resource_0k62o"), SubResource("Resource_edoov"), SubResource("Resource_47bot"), SubResource("Resource_mgdm6"), SubResource("Resource_v2as6"), SubResource("Resource_pein5"), SubResource("Resource_6wrc7"), SubResource("Resource_x3w7w"), SubResource("Resource_ajht5"), SubResource("Resource_7vmdn"), SubResource("Resource_6ijnv")])
|
||||
Maps = Array[Object]([SubResource("Resource_qnbi6"), SubResource("Resource_0k62o"), SubResource("Resource_edoov"), SubResource("Resource_47bot"), SubResource("Resource_mgdm6"), SubResource("Resource_v2as6"), SubResource("Resource_pein5"), SubResource("Resource_6wrc7"), SubResource("Resource_x3w7w"), SubResource("Resource_ajht5"), SubResource("Resource_7vmdn"), SubResource("Resource_6ijnv"), SubResource("Resource_bkci5")])
|
||||
|
|
|
|||
19
Scenes/Actors/fsm_enemy.tscn
Normal file
19
Scenes/Actors/fsm_enemy.tscn
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://bwwuqfhsbxg88"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://v2f387aad33k" path="res://Scripts/Components/FSM/ActorStateMachine.cs" id="1_3eiqy"]
|
||||
[ext_resource type="SpriteFrames" uid="uid://bcc5mlwwnkvri" path="res://Resources/Sprites/Fairy.tres" id="2_d4q8l"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_5xgmc"]
|
||||
|
||||
[node name="FSMEnemy" type="CharacterBody2D"]
|
||||
script = ExtResource("1_3eiqy")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_5xgmc")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
sprite_frames = ExtResource("2_d4q8l")
|
||||
animation = &"down"
|
||||
|
||||
[node name="Idle" type="Node2D" parent="."]
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
[gd_scene load_steps=12 format=4 uid="uid://6a6tjohypmmb"]
|
||||
[gd_scene load_steps=13 format=4 uid="uid://6a6tjohypmmb"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_t2k72"]
|
||||
[ext_resource type="PackedScene" uid="uid://bghghp5ep4w2j" path="res://Scenes/player.tscn" id="2_v2pdx"]
|
||||
[ext_resource type="Script" uid="uid://epnwjptvks3t" path="res://Scripts/Resources/LootItem.cs" id="3_e12id"]
|
||||
[ext_resource type="Script" uid="uid://mja0rk7n2kln" path="res://Scripts/Resources/MapStartDataResource.cs" id="4_s1vkf"]
|
||||
[ext_resource type="TileSet" uid="uid://6k28roiljylj" path="res://Tilesets/factory_tileset.tres" id="5_06rc0"]
|
||||
[ext_resource type="Script" uid="uid://krean0uywtms" path="res://Scripts/TilemapAvoidance.cs" id="6_up0ka"]
|
||||
|
|
@ -14,7 +15,7 @@
|
|||
[sub_resource type="Resource" id="Resource_6wo78"]
|
||||
script = ExtResource("4_s1vkf")
|
||||
EggIndex = 0
|
||||
StartingEquipment = []
|
||||
StartingEquipment = Array[ExtResource("3_e12id")]([])
|
||||
|
||||
[node name="GameScene" type="Node2D"]
|
||||
script = ExtResource("1_t2k72")
|
||||
|
|
|
|||
|
|
@ -1,15 +1,21 @@
|
|||
[gd_scene load_steps=18 format=4 uid="uid://dqyfnby0t7gu1"]
|
||||
[gd_scene load_steps=23 format=4 uid="uid://dqyfnby0t7gu1"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_c3v4x"]
|
||||
[ext_resource type="PackedScene" uid="uid://bghghp5ep4w2j" path="res://Scenes/player.tscn" id="2_w1v1g"]
|
||||
[ext_resource type="Resource" uid="uid://cs3ihltcn2166" path="res://Resources/Items/IcicleGun.tres" id="3_6314l"]
|
||||
[ext_resource type="PackedScene" uid="uid://crry0rgk7a8sm" path="res://Scenes/Weapons/BaseWeapon.tscn" id="3_b3hxm"]
|
||||
[ext_resource type="Script" uid="uid://mja0rk7n2kln" path="res://Scripts/Resources/MapStartDataResource.cs" id="4_u1i8n"]
|
||||
[ext_resource type="Resource" uid="uid://dhbltvgsa3g88" path="res://Resources/Items/Spider_Bomb_Pickup.tres" id="4_yyg8m"]
|
||||
[ext_resource type="TileSet" uid="uid://6k28roiljylj" path="res://Tilesets/factory_tileset.tres" id="5_6314l"]
|
||||
[ext_resource type="Script" uid="uid://epnwjptvks3t" path="res://Scripts/Resources/LootItem.cs" id="5_mljl7"]
|
||||
[ext_resource type="Script" uid="uid://krean0uywtms" path="res://Scripts/TilemapAvoidance.cs" id="6_yyg8m"]
|
||||
[ext_resource type="Script" uid="uid://v2f387aad33k" path="res://Scripts/Components/FSM/ActorStateMachine.cs" id="7_mljl7"]
|
||||
[ext_resource type="SpriteFrames" uid="uid://bcc5mlwwnkvri" path="res://Resources/Sprites/Fairy.tres" id="8_0knpf"]
|
||||
[ext_resource type="Script" uid="uid://bw2hakslndaxm" path="res://Scripts/Components/FSM/PlayerStateMachine.cs" id="8_b3hxm"]
|
||||
[ext_resource type="Script" uid="uid://cfya7sndh7vy2" path="res://Scenes/CameraController.gd" id="9_dj0ui"]
|
||||
[ext_resource type="Script" uid="uid://bl0o35xt8wxtg" path="res://Scripts/Components/FSM/Player/Active.cs" id="9_u1i8n"]
|
||||
[ext_resource type="SpriteFrames" uid="uid://bc7mghjx75qip" path="res://Resources/Sprites/player.tres" id="9_w1v1g"]
|
||||
[ext_resource type="Script" uid="uid://chwqogny2v8t1" path="res://Scripts/Components/FSM/Player/Init.cs" id="9_yyg8m"]
|
||||
[ext_resource type="Script" uid="uid://c5nxsq3tyxcx6" path="res://Scripts/InventoryManager.cs" id="10_qmakk"]
|
||||
[ext_resource type="Script" uid="uid://b4nixnxhj5qhw" path="res://Scripts/Components/Actors/PlayerWeaponProvider.cs" id="11_6314l"]
|
||||
[ext_resource type="PackedScene" uid="uid://dkwi1hu1bixoe" path="res://Scenes/HUD/HUD.tscn" id="11_hmqao"]
|
||||
[ext_resource type="Script" uid="uid://bdshph801ac2i" path="res://Scenes/CameraTarget.gd" id="12_8to53"]
|
||||
[ext_resource type="Script" uid="uid://cnkipcolyj61w" path="res://Scripts/AlarmManager.cs" id="13_8fnge"]
|
||||
|
|
@ -18,9 +24,7 @@
|
|||
[sub_resource type="Resource" id="Resource_6wo78"]
|
||||
script = ExtResource("4_u1i8n")
|
||||
EggIndex = 0
|
||||
StartingEquipment = []
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_5xgmc"]
|
||||
StartingEquipment = Array[ExtResource("5_mljl7")]([])
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_b3hxm"]
|
||||
|
||||
|
|
@ -31,6 +35,7 @@ PlayerTemplate = ExtResource("2_w1v1g")
|
|||
SpawnMarkers = Dictionary[int, NodePath]({
|
||||
0: NodePath("PlayerStartPosition")
|
||||
})
|
||||
StartingEquipment = [ExtResource("3_6314l"), ExtResource("4_yyg8m")]
|
||||
MapStartData = SubResource("Resource_6wo78")
|
||||
|
||||
[node name="Tilemaps" type="Node2D" parent="."]
|
||||
|
|
@ -55,24 +60,17 @@ metadata/_edit_lock_ = true
|
|||
[node name="Actors" type="Node2D" parent="Tilemaps"]
|
||||
metadata/_edit_lock_ = true
|
||||
|
||||
[node name="FSMEnemy" type="CharacterBody2D" parent="Tilemaps/Actors"]
|
||||
position = Vector2(161.783, 298.229)
|
||||
script = ExtResource("7_mljl7")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Tilemaps/Actors/FSMEnemy"]
|
||||
shape = SubResource("CircleShape2D_5xgmc")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="Tilemaps/Actors/FSMEnemy"]
|
||||
sprite_frames = ExtResource("8_0knpf")
|
||||
animation = &"down"
|
||||
|
||||
[node name="Idle" type="Node2D" parent="Tilemaps/Actors/FSMEnemy"]
|
||||
|
||||
[node name="FSMPlayer" type="CharacterBody2D" parent="Tilemaps/Actors"]
|
||||
position = Vector2(76, 295)
|
||||
script = ExtResource("8_b3hxm")
|
||||
InitialState = 1
|
||||
|
||||
[node name="Node2D" type="Node2D" parent="Tilemaps/Actors/FSMPlayer"]
|
||||
[node name="Init" type="Node2D" parent="Tilemaps/Actors/FSMPlayer"]
|
||||
script = ExtResource("9_yyg8m")
|
||||
|
||||
[node name="Active" type="Node2D" parent="Tilemaps/Actors/FSMPlayer"]
|
||||
script = ExtResource("9_u1i8n")
|
||||
State = 1
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Tilemaps/Actors/FSMPlayer"]
|
||||
shape = SubResource("CircleShape2D_b3hxm")
|
||||
|
|
@ -81,6 +79,10 @@ shape = SubResource("CircleShape2D_b3hxm")
|
|||
sprite_frames = ExtResource("9_w1v1g")
|
||||
animation = &"idle"
|
||||
|
||||
[node name="WeaponProvider" type="Node2D" parent="Tilemaps/Actors/FSMPlayer"]
|
||||
script = ExtResource("11_6314l")
|
||||
WeaponTemplate = ExtResource("3_b3hxm")
|
||||
|
||||
[node name="CameraController" type="Camera2D" parent="."]
|
||||
process_mode = 1
|
||||
script = ExtResource("9_dj0ui")
|
||||
|
|
|
|||
|
|
@ -16,12 +16,19 @@ public partial class PlayerWeaponProvider : Node2D
|
|||
|
||||
public Weapon EquippedWeapon { get; set; }
|
||||
|
||||
//private PlayerMovement _parent;
|
||||
private CharacterBody2D _parent;
|
||||
|
||||
//public Vector2 FacingDirection
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Init(CharacterBody2D parent)
|
||||
{
|
||||
_parent = parent;
|
||||
|
||||
_inventoryManager = this.GetInventoryManager();
|
||||
|
||||
_inventoryManager.WeaponEquip += this.EquipWeapon;
|
||||
|
|
@ -35,11 +42,6 @@ public partial class PlayerWeaponProvider : Node2D
|
|||
};
|
||||
}
|
||||
|
||||
public void Init(PlayerMovement parent)
|
||||
{
|
||||
//_parent = parent;
|
||||
}
|
||||
|
||||
public void AddWeapon(Weapon weapon)
|
||||
{
|
||||
EquippedWeapons.Add(weapon);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using Cirno.Scripts.Components.Actors;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM.Player;
|
||||
|
|
@ -17,12 +18,32 @@ public partial class Active : PlayerFSMState
|
|||
[Export] private string _nextWeaponActionName = "next_weapon";
|
||||
[Export] private string _previousWeaponActionName = "previous_weapon";
|
||||
|
||||
private PlayerWeaponProvider _weaponProvider;
|
||||
|
||||
private bool _isStrafing { get; set; }
|
||||
|
||||
[Export]
|
||||
public int Speed { get; set; } = 45;
|
||||
|
||||
[Export]
|
||||
public int StrafeSpeed { get; set; } = 35;
|
||||
|
||||
public int MovementSpeed => _isStrafing ? StrafeSpeed : Speed;
|
||||
|
||||
public override void Init(ActorStateMachine stateMachine)
|
||||
{
|
||||
base.Init(stateMachine);
|
||||
|
||||
_weaponProvider = stateMachine.GetNode<PlayerWeaponProvider>("WeaponProvider");
|
||||
|
||||
_weaponProvider.Init(stateMachine);
|
||||
}
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
// enable sprite
|
||||
// enable crosshair
|
||||
GD.Print(this.State.ToString());
|
||||
}
|
||||
|
||||
public override void ExitState()
|
||||
|
|
@ -32,7 +53,9 @@ public partial class Active : PlayerFSMState
|
|||
|
||||
public override void PhysicsProcessState(double delta)
|
||||
{
|
||||
_stateMachine.Velocity = _movementDirection * MovementSpeed;
|
||||
|
||||
_stateMachine.MoveAndSlide();
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
|
|
@ -63,7 +86,7 @@ public partial class Active : PlayerFSMState
|
|||
}
|
||||
}
|
||||
|
||||
// HandleShoot();
|
||||
HandleShoot();
|
||||
// FindInteractable();
|
||||
|
||||
// if (Input.IsActionJustPressed(_nextWeaponActionName))
|
||||
|
|
@ -112,6 +135,12 @@ public partial class Active : PlayerFSMState
|
|||
|
||||
}
|
||||
|
||||
private void HandleShoot()
|
||||
{
|
||||
if (!Input.IsActionPressed(_shootActionName)) return;
|
||||
_weaponProvider.Shoot(this._facingDirection);
|
||||
}
|
||||
|
||||
public Vector2 GetInput()
|
||||
{
|
||||
return Input.GetVector("left", "right", "up", "down");
|
||||
|
|
|
|||
27
Scripts/Components/FSM/Player/Init.cs
Normal file
27
Scripts/Components/FSM/Player/Init.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM.Player;
|
||||
|
||||
public partial class Init : PlayerFSMState
|
||||
{
|
||||
public override void EnterState()
|
||||
{
|
||||
GD.Print(this.State.ToString());
|
||||
}
|
||||
|
||||
public override void ExitState()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void PhysicsProcessState(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
1
Scripts/Components/FSM/Player/Init.cs.uid
Normal file
1
Scripts/Components/FSM/Player/Init.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://chwqogny2v8t1
|
||||
|
|
@ -5,8 +5,13 @@ namespace Cirno.Scripts.Components.FSM;
|
|||
|
||||
public partial class PlayerStateMachine : ActorStateMachine
|
||||
{
|
||||
[Export]
|
||||
public PlayerState InitialState { get; private set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
|
||||
this.SetState((int)InitialState);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -125,6 +125,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
_state = PlayerState.Active;
|
||||
|
||||
_weaponProvider = GetNode<PlayerWeaponProvider>("WeaponProvider");
|
||||
_weaponProvider.Init(this);
|
||||
|
||||
_animatedSprite = GetNode<AnimatedSprite2D>("./Smoothing2D/AnimatedSprite2D");
|
||||
_crosshair = GetNode<Sprite2D>("./Smoothing2D/Crosshair");
|
||||
|
|
@ -582,6 +583,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
public enum PlayerState
|
||||
{
|
||||
Init,
|
||||
Active,
|
||||
Paused,
|
||||
Controlling,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue