Compare commits

...

2 Commits

Author SHA1 Message Date
7acdc7633c Collision State works on change! 2025-04-13 09:11:19 -07:00
0ecea5fa00 Collision Shape 2D state receiver 2025-04-13 08:40:42 -07:00
4 changed files with 86 additions and 1 deletions

View File

@ -0,0 +1,54 @@
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
## return to default when no state function
export var default_shape_when_no_state_function :bool = true
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var default_shape :Shape2D
var default_transform :Transform2D
# 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
default_shape = shape.duplicate()
##TODO: Are transforms primitives? Do they get passed by value?
default_transform = transform
# 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:
if default_shape_when_no_state_function:
if debug_component:
print ("Returning to default collision shape")
shape = default_shape
transform = default_transform
else:
push_warning("Received non animated Actor state.")

View File

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

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

@ -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://lib/parent_scenes/actor.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/actors/players/playerE/PlayerE_SpriteFrames.tres" type="SpriteFrames" id=2] [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://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://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
@ -131,6 +132,9 @@ sound_effects = [ SubResource( 4 ), SubResource( 5 ), SubResource( 6 ) ]
[node name="CollisionShape2D" type="CollisionShape2D" parent="." index="7"] [node name="CollisionShape2D" type="CollisionShape2D" parent="." index="7"]
position = Vector2( 0, 2 ) position = Vector2( 0, 2 )
shape = SubResource( 1 ) shape = SubResource( 1 )
script = ExtResource( 31 )
debug_component = true
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 )]
unique_name_in_owner = true unique_name_in_owner = true