new state machines and layers

pull/3/head
HumanoidSandvichDispenser 2023-05-23 00:25:28 -07:00
parent 7dfd061c16
commit 64a9b98644
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
7 changed files with 959 additions and 104 deletions

View File

@ -1,9 +1,9 @@
[gd_scene load_steps=26 format=3 uid="uid://ddcf6bfv212wj"] [gd_scene load_steps=26 format=3 uid="uid://bf55wbq7m1gpp"]
[ext_resource type="Script" path="res://Characters/Enemy.cs" id="1_2yopk"] [ext_resource type="Script" path="res://Characters/Enemy.cs" id="1_2yopk"]
[ext_resource type="Shader" path="res://Shaders/Flash.gdshader" id="1_fx1w5"] [ext_resource type="Shader" path="res://Shaders/Flash.gdshader" id="1_fx1w5"]
[ext_resource type="Script" path="res://Characters/States/Machine.cs" id="3_k4ypw"]
[ext_resource type="Texture2D" uid="uid://bej8thq7ruyty" path="res://Assets/Sprites/Characters/forsen2.png" id="3_ocaae"] [ext_resource type="Texture2D" uid="uid://bej8thq7ruyty" path="res://Assets/Sprites/Characters/forsen2.png" id="3_ocaae"]
[ext_resource type="Script" path="res://State/Machine.cs" id="4_4nwgr"]
[ext_resource type="Script" path="res://Characters/States/NPCIdleState.cs" id="4_8r2qn"] [ext_resource type="Script" path="res://Characters/States/NPCIdleState.cs" id="4_8r2qn"]
[ext_resource type="Script" path="res://Characters/States/NPCMoveState.cs" id="5_utogm"] [ext_resource type="Script" path="res://Characters/States/NPCMoveState.cs" id="5_utogm"]
[ext_resource type="PackedScene" uid="uid://cjgxyhgcyvsv7" path="res://BoundingBoxes/Hurtbox.tscn" id="6_jo0cg"] [ext_resource type="PackedScene" uid="uid://cjgxyhgcyvsv7" path="res://BoundingBoxes/Hurtbox.tscn" id="6_jo0cg"]
@ -133,6 +133,7 @@ y_sort_enabled = true
texture_filter = 3 texture_filter = 3
material = SubResource("ShaderMaterial_ms3xg") material = SubResource("ShaderMaterial_ms3xg")
collision_layer = 10 collision_layer = 10
collision_mask = 17
script = ExtResource("1_2yopk") script = ExtResource("1_2yopk")
Health = 50.0 Health = 50.0
Sprite = NodePath("Sprite") Sprite = NodePath("Sprite")
@ -142,15 +143,16 @@ Faction = 2
[node name="Sprite" type="AnimatedSprite2D" parent="."] [node name="Sprite" type="AnimatedSprite2D" parent="."]
use_parent_material = true use_parent_material = true
position = Vector2(0, -4)
sprite_frames = SubResource("SpriteFrames_6pejo") sprite_frames = SubResource("SpriteFrames_6pejo")
animation = &"move" animation = &"move"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, 8) position = Vector2(0, 4)
shape = SubResource("RectangleShape2D_uict5") shape = SubResource("RectangleShape2D_uict5")
[node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("InitialState", "Character")] [node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("InitialState", "Character")]
script = ExtResource("3_k4ypw") script = ExtResource("4_4nwgr")
InitialState = NodePath("Idle") InitialState = NodePath("Idle")
Character = NodePath("..") Character = NodePath("..")
@ -163,6 +165,7 @@ script = ExtResource("5_utogm")
IdleState = NodePath("../Idle") IdleState = NodePath("../Idle")
[node name="Hurtbox" parent="." instance=ExtResource("6_jo0cg")] [node name="Hurtbox" parent="." instance=ExtResource("6_jo0cg")]
position = Vector2(0, -4)
Faction = 2 Faction = 2
[node name="CollisionShape2D" parent="Hurtbox" index="0"] [node name="CollisionShape2D" parent="Hurtbox" index="0"]

View File

@ -2,10 +2,10 @@
[ext_resource type="Script" path="res://Characters/Player.cs" id="1_flygr"] [ext_resource type="Script" path="res://Characters/Player.cs" id="1_flygr"]
[ext_resource type="Shader" path="res://Shaders/Flash.gdshader" id="2_ngsgt"] [ext_resource type="Shader" path="res://Shaders/Flash.gdshader" id="2_ngsgt"]
[ext_resource type="Script" path="res://Characters/States/Machine.cs" id="3_npkjp"]
[ext_resource type="Script" path="res://Characters/States/PlayerIdleState.cs" id="4_4k4mb"] [ext_resource type="Script" path="res://Characters/States/PlayerIdleState.cs" id="4_4k4mb"]
[ext_resource type="Texture2D" uid="uid://bej8thq7ruyty" path="res://Assets/Sprites/Characters/forsen2.png" id="4_5vird"] [ext_resource type="Texture2D" uid="uid://bej8thq7ruyty" path="res://Assets/Sprites/Characters/forsen2.png" id="4_5vird"]
[ext_resource type="PackedScene" uid="uid://cl56eadpklnbo" path="res://Utils/PlayerCamera.tscn" id="4_ym125"] [ext_resource type="PackedScene" uid="uid://cl56eadpklnbo" path="res://Utils/PlayerCamera.tscn" id="4_ym125"]
[ext_resource type="Script" path="res://State/Machine.cs" id="5_glslt"]
[ext_resource type="Script" path="res://Characters/States/PlayerMoveState.cs" id="5_tx5rw"] [ext_resource type="Script" path="res://Characters/States/PlayerMoveState.cs" id="5_tx5rw"]
[ext_resource type="Script" path="res://Characters/States/PlayerRollState.cs" id="6_6bgrj"] [ext_resource type="Script" path="res://Characters/States/PlayerRollState.cs" id="6_6bgrj"]
[ext_resource type="PackedScene" uid="uid://d72ehtv1ks0e" path="res://Items/Weapons/Sword.tscn" id="7_4rxuv"] [ext_resource type="PackedScene" uid="uid://d72ehtv1ks0e" path="res://Items/Weapons/Sword.tscn" id="7_4rxuv"]
@ -61,7 +61,7 @@ animations = [{
}], }],
"loop": true, "loop": true,
"name": &"idle", "name": &"idle",
"speed": 5.0 "speed": 2.0
}, { }, {
"frames": [{ "frames": [{
"duration": 1.0, "duration": 1.0,
@ -84,7 +84,7 @@ animations = [{
}], }],
"loop": true, "loop": true,
"name": &"move", "name": &"move",
"speed": 12.0 "speed": 10.0
}] }]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_bfqew"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_bfqew"]
@ -94,7 +94,7 @@ size = Vector2(16, 8)
font_size = 24 font_size = 24
[sub_resource type="RectangleShape2D" id="RectangleShape2D_cjk6b"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_cjk6b"]
size = Vector2(11, 14) size = Vector2(8, 8)
[sub_resource type="Animation" id="Animation_dxevc"] [sub_resource type="Animation" id="Animation_dxevc"]
resource_name = "Hurt" resource_name = "Hurt"
@ -139,6 +139,7 @@ texture_filter = 3
material = SubResource("ShaderMaterial_h78y7") material = SubResource("ShaderMaterial_h78y7")
position = Vector2(0, -12) position = Vector2(0, -12)
collision_layer = 6 collision_layer = 6
collision_mask = 17
script = ExtResource("1_flygr") script = ExtResource("1_flygr")
Camera = NodePath("Camera2D") Camera = NodePath("Camera2D")
Speed = 64.0 Speed = 64.0
@ -153,14 +154,14 @@ position_smoothing_speed = 8.0
[node name="Sprite" type="AnimatedSprite2D" parent="."] [node name="Sprite" type="AnimatedSprite2D" parent="."]
use_parent_material = true use_parent_material = true
sprite_frames = SubResource("SpriteFrames_2h7cf") sprite_frames = SubResource("SpriteFrames_2h7cf")
animation = &"move" animation = &"idle"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, 8) position = Vector2(0, 8)
shape = SubResource("RectangleShape2D_bfqew") shape = SubResource("RectangleShape2D_bfqew")
[node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("InitialState", "Character")] [node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("InitialState", "Character")]
script = ExtResource("3_npkjp") script = ExtResource("5_glslt")
InitialState = NodePath("Idle") InitialState = NodePath("Idle")
Character = NodePath("..") Character = NodePath("..")
DebugLevel = 2 DebugLevel = 2
@ -198,7 +199,7 @@ horizontal_alignment = 1
[node name="Inventory" type="Node2D" parent="."] [node name="Inventory" type="Node2D" parent="."]
y_sort_enabled = true y_sort_enabled = true
position = Vector2(0, 2) position = Vector2(0, 4)
script = ExtResource("7_xyenu") script = ExtResource("7_xyenu")
InventoryMap = { InventoryMap = {
"equip_1": 0, "equip_1": 0,
@ -206,13 +207,14 @@ InventoryMap = {
} }
[node name="Sword" parent="Inventory" instance=ExtResource("7_4rxuv")] [node name="Sword" parent="Inventory" instance=ExtResource("7_4rxuv")]
position = Vector2(0, 0) z_index = -1
position = Vector2(0, 2)
[node name="Hurtbox" parent="." instance=ExtResource("9_avyu4")] [node name="Hurtbox" parent="." instance=ExtResource("9_avyu4")]
Faction = 1 Faction = 1
[node name="CollisionShape2D" parent="Hurtbox" index="0"] [node name="CollisionShape2D" parent="Hurtbox" index="0"]
position = Vector2(-0.5, 5) position = Vector2(0, 6)
shape = SubResource("RectangleShape2D_cjk6b") shape = SubResource("RectangleShape2D_cjk6b")
[node name="FlashAnimation" type="AnimationPlayer" parent="."] [node name="FlashAnimation" type="AnimationPlayer" parent="."]

View File

@ -1,90 +0,0 @@
using Godot;
namespace SupaLidlGame.Characters.State
{
public partial class Machine : Node
{
protected Character _character;
public CharacterState State { get; protected set; }
[Export]
public CharacterState InitialState { get; set; }
[Export]
public Character Character { get; set; }
[Export]
public int DebugLevel { get; set; }
public override void _Ready()
{
ChangeState(InitialState);
}
public void ChangeState(CharacterState nextState, bool isProxied = false)
{
if (nextState is null)
return;
if (DebugLevel >= 2)
{
if (State is not null)
{
string proxyNote = isProxied ? " (proxied)" : "";
GD.Print($"Transition{proxyNote} {State.Name} -> {nextState.Name}");
}
}
if (DebugLevel >= 1)
{
if (GetNode<Label>("../Debug/State") is Label label)
{
label.Text = nextState.Name;
}
}
nextState.Character = Character;
if (State != null)
{
State.Exit(nextState);
}
var nextNextState = nextState.Enter(State);
State = nextState;
if (nextNextState is not null)
{
ChangeState(nextNextState, true);
}
}
public void Process(double delta)
{
CharacterState nextState = State.Process(delta);
if (nextState is not null)
{
ChangeState(nextState);
}
}
public void PhysicsProcess(double delta)
{
CharacterState nextState = State.PhysicsProcess(delta);
if (nextState is not null)
{
ChangeState(nextState);
}
}
public void Input(InputEvent @event)
{
CharacterState nextState = State.Input(@event);
if (nextState is not null)
{
ChangeState(nextState);
}
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=5 format=3 uid="uid://k4pkkaitpnv8"] [gd_scene load_steps=5 format=3 uid="uid://k4pkkaitpnv8"]
[ext_resource type="PackedScene" uid="uid://clwv2owvk6abe" path="res://Scenes/BaseMap.tscn" id="1_hpj8x"] [ext_resource type="PackedScene" uid="uid://clwv2owvk6abe" path="res://Scenes/BaseMap.tscn" id="1_hpj8x"]
[ext_resource type="PackedScene" uid="uid://ddcf6bfv212wj" path="res://Characters/ExampleEnemy.tscn" id="2_4dkyx"] [ext_resource type="PackedScene" uid="uid://bf55wbq7m1gpp" path="res://Characters/ExampleEnemy.tscn" id="2_4dkyx"]
[ext_resource type="Script" path="res://BoundingBoxes/ConnectorBox.cs" id="2_7ucgi"] [ext_resource type="Script" path="res://BoundingBoxes/ConnectorBox.cs" id="2_7ucgi"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_v7m2q"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_v7m2q"]

View File

@ -88,6 +88,7 @@ equip_3={
2d_physics/layer_2="Character" 2d_physics/layer_2="Character"
2d_physics/layer_3="Player" 2d_physics/layer_3="Player"
2d_physics/layer_4="NPC" 2d_physics/layer_4="NPC"
2d_physics/layer_5="World Clip"
[physics] [physics]