Collision State works on change!

This commit is contained in:
Dustin 2025-04-13 09:11:19 -07:00
parent 0ecea5fa00
commit 7acdc7633c
3 changed files with 37 additions and 1 deletions

View File

@ -7,10 +7,14 @@ export var callable_state_machine :NodePath
var request_state_change: FuncRef var request_state_change: FuncRef
onready var current_state :StateAnimatedActor onready var current_state :StateAnimatedActor
## return to default when no state function
export var default_shape_when_no_state_function :bool = true
# Declare member variables here. Examples: # Declare member variables here. Examples:
# var a = 2 # var a = 2
# var b = "text" # var b = "text"
var default_shape :Shape2D
var default_transform :Transform2D
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
@ -21,6 +25,10 @@ func _ready():
get_node(callable_state_machine).connect("state_changed", self,"_on_state_change") get_node(callable_state_machine).connect("state_changed", self,"_on_state_change")
## A reference to the current state machine state ## A reference to the current state machine state
current_state = get_node(callable_state_machine).current_state current_state = get_node(callable_state_machine).current_state
default_shape = shape.duplicate()
##TODO: Are transforms primitives? Do they get passed by value?
default_transform = transform
@ -35,6 +43,12 @@ func _on_state_change(old_state_name:String, new_state :State):
current_state = new_state current_state = new_state
if has_method('_on_state_change_' + current_state.name): if has_method('_on_state_change_' + current_state.name):
call('_on_state_change_' + current_state.name) call('_on_state_change_' + current_state.name)
else:
if default_shape_when_no_state_function:
if debug_component:
print ("Returning to default collision shape")
shape = default_shape
transform = default_transform
else: else:
push_warning("Received non animated Actor state.") push_warning("Received non animated Actor state.")

View File

@ -0,0 +1,21 @@
extends CollisionShape2D_StateReceiver
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _on_state_change_hurt():
print ("<---- Hey you called me to get hurt. Bruh.")
transform = transform.translated(Vector2(-10,10))
pass

View File

@ -30,7 +30,7 @@
[ext_resource path="res://src/components/PewMachine.tscn" type="PackedScene" id=28] [ext_resource path="res://src/components/PewMachine.tscn" type="PackedScene" id=28]
[ext_resource path="res://lib/components/Stamina_Component.tscn" type="PackedScene" id=29] [ext_resource path="res://lib/components/Stamina_Component.tscn" type="PackedScene" id=29]
[ext_resource path="res://src/actors/players/playerE/states/death.tres" type="Resource" id=30] [ext_resource path="res://src/actors/players/playerE/states/death.tres" type="Resource" id=30]
[ext_resource path="res://lib/classes/collision_shape2D_state_receiver.gd" type="Script" id=31] [ext_resource path="res://src/actors/players/playerE/PlayerE-CollisionShape2D_StateReceiver.gd" type="Script" id=31]
[sub_resource type="Resource" id=3] [sub_resource type="Resource" id=3]
resource_local_to_scene = true resource_local_to_scene = true
@ -133,6 +133,7 @@ sound_effects = [ SubResource( 4 ), SubResource( 5 ), SubResource( 6 ) ]
position = Vector2( 0, 2 ) position = Vector2( 0, 2 )
shape = SubResource( 1 ) shape = SubResource( 1 )
script = ExtResource( 31 ) script = ExtResource( 31 )
debug_component = true
callable_state_machine = NodePath("../Movement_StateMachine") callable_state_machine = NodePath("../Movement_StateMachine")
[node name="Health_Component" parent="." index="8" instance=ExtResource( 17 )] [node name="Health_Component" parent="." index="8" instance=ExtResource( 17 )]