Collision Shape 2D state receiver

This commit is contained in:
Dustin 2025-04-13 08:40:42 -07:00
parent f67fdbbe3e
commit 0ecea5fa00
3 changed files with 50 additions and 1 deletions

View File

@ -0,0 +1,40 @@
class_name CollisionShape2D_StateReceiver
extends CollisionShape2D
## Standard vars for state receivers
export var debug_component: bool = false
export var callable_state_machine :NodePath
var request_state_change: FuncRef
onready var current_state :StateAnimatedActor
# 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():
## Standard ready routines for state receivers
request_state_change = funcref(get_node(callable_state_machine), 'change_to_known_state')
## Connect signal to get alerted of state change
get_node(callable_state_machine).connect("state_changed", self,"_on_state_change")
## A reference to the current state machine state
current_state = get_node(callable_state_machine).current_state
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
## Standard function for receiving state change
func _on_state_change(old_state_name:String, new_state :State):
###### State machine
if new_state is StateAnimatedActor: #Testing this. Update: It works
current_state = new_state
if has_method('_on_state_change_' + current_state.name):
call('_on_state_change_' + current_state.name)
else:
push_warning("Received non animated Actor state.")

View File

@ -29,6 +29,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://src/classes/camera_guide.gd"
}, {
"base": "CollisionShape2D",
"class": "CollisionShape2D_StateReceiver",
"language": "GDScript",
"path": "res://lib/classes/collision_shape2D_state_receiver.gd"
}, {
"base": "",
"class": "GitAPI",
"language": "NativeScript",
@ -154,6 +159,7 @@ _global_script_class_icons={
"AnimatedSprite_StateReceiver": "",
"AudioStreamPlayer_StateReceiver": "",
"CameraGuide": "",
"CollisionShape2D_StateReceiver": "",
"GitAPI": "",
"HealthComponent": "",
"HealthPickup": "",

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=37 format=2]
[gd_scene load_steps=38 format=2]
[ext_resource path="res://lib/parent_scenes/actor.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/actors/players/playerE/PlayerE_SpriteFrames.tres" type="SpriteFrames" id=2]
@ -30,6 +30,7 @@
[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://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]
[sub_resource type="Resource" id=3]
resource_local_to_scene = true
@ -131,6 +132,8 @@ sound_effects = [ SubResource( 4 ), SubResource( 5 ), SubResource( 6 ) ]
[node name="CollisionShape2D" type="CollisionShape2D" parent="." index="7"]
position = Vector2( 0, 2 )
shape = SubResource( 1 )
script = ExtResource( 31 )
callable_state_machine = NodePath("../Movement_StateMachine")
[node name="Health_Component" parent="." index="8" instance=ExtResource( 17 )]
unique_name_in_owner = true