Level physics state modifier system added. Now just need to apply it to the actors.

This commit is contained in:
Nitsud Yarg 2024-06-30 10:59:43 -07:00
parent a87955eb0d
commit f35ab3703b
11 changed files with 174 additions and 9 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -1,4 +1,4 @@
[gd_resource type="TileSet" load_steps=13 format=2] [gd_resource type="TileSet" load_steps=15 format=2]
[ext_resource path="res://assets/Tiles/Assets/Assets.png" type="Texture" id=1] [ext_resource path="res://assets/Tiles/Assets/Assets.png" type="Texture" id=1]
@ -35,6 +35,12 @@ points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )
[sub_resource type="ConvexPolygonShape2D" id=12] [sub_resource type="ConvexPolygonShape2D" id=12]
points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 ) points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )
[sub_resource type="ConvexPolygonShape2D" id=13]
points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )
[sub_resource type="ConvexPolygonShape2D" id=14]
points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )
[resource] [resource]
0/name = "Assets.png 0" 0/name = "Assets.png 0"
0/texture = ExtResource( 1 ) 0/texture = ExtResource( 1 )
@ -122,5 +128,17 @@ points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 )
"one_way_margin": 1.0, "one_way_margin": 1.0,
"shape": SubResource( 12 ), "shape": SubResource( 12 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 ) "shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
}, {
"autotile_coord": Vector2( 8, 2 ),
"one_way": false,
"one_way_margin": 1.0,
"shape": SubResource( 13 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
}, {
"autotile_coord": Vector2( 9, 2 ),
"one_way": false,
"one_way_margin": 1.0,
"shape": SubResource( 14 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
} ] } ]
0/z_index = 0 0/z_index = 0

View File

@ -49,6 +49,11 @@ _global_script_classes=[ {
"language": "GDScript", "language": "GDScript",
"path": "res://src/state_modifier_properties.gd" "path": "res://src/state_modifier_properties.gd"
}, { }, {
"base": "Node2D",
"class": "Modifier_Receiver",
"language": "GDScript",
"path": "res://src/components/Modifier_Receiver.gd"
}, {
"base": "Node", "base": "Node",
"class": "MovementComponent", "class": "MovementComponent",
"language": "GDScript", "language": "GDScript",
@ -93,6 +98,7 @@ _global_script_class_icons={
"Interactable_Receiver": "", "Interactable_Receiver": "",
"Level": "", "Level": "",
"ModifierProperties": "", "ModifierProperties": "",
"Modifier_Receiver": "",
"MovementComponent": "", "MovementComponent": "",
"State": "", "State": "",
"StateAnimatedActor": "", "StateAnimatedActor": "",

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,48 @@
extends Area2D
var modifier_type = 0
export var modifier_name :String = ''
var animation_name: String = '' # Not using this one
var timeout_seconds: float = 0.0 # Not doing timeout based ones yet either.
export var move_speed: float = 0.0
export var move_acceleration: float = 0.0
export var move_speed_modifier: float = 0.0
export var move_modifier_move_acceleration: float = 0.0
export var jerk_factor: float = 0
export var gravity_modifier: int = 0
#var state_timeout: Timer
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var modifier :StateModifier
#var modifier_properties: ModifierProperties
# Called when the node enters the scene tree for the first time.
func _ready():
modifier = StateModifier.new()
modifier.ready( modifier_name, animation_name , modifier.TYPE.NONE, timeout_seconds)
modifier.modifier_properties = ModifierProperties.new( move_speed,
gravity_modifier,
move_acceleration,
move_speed_modifier,
move_modifier_move_acceleration,
jerk_factor)
func _on_Modifier_Component_body_entered(body):
var colliding_node = body
if colliding_node.has_node("Modifier_Receiver"):
colliding_node.get_node("Modifier_Receiver").register_modifier(modifier)
func _on_Modifier_Component_body_exited(body):
var colliding_node = body
if colliding_node.has_node("Modifier_Receiver"):
colliding_node.get_node("Modifier_Receiver").remove_modifier(modifier)

View File

@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://src/components/Modifier_Component.gd" type="Script" id=1]
[node name="Modifier_Component" type="Area2D"]
script = ExtResource( 1 )
[connection signal="body_entered" from="." to="." method="_on_Modifier_Component_body_entered"]
[connection signal="body_exited" from="." to="." method="_on_Modifier_Component_body_exited"]

View File

@ -0,0 +1,53 @@
class_name Modifier_Receiver
extends Node2D
# This may be stupid but we're going to have two kinds of callbacks here.
# It's going to be up to the parent/actor/kinematicbody2d/whatever to know
# what conditions have to be met before being able to call that interactible's
# function.
# This is a nice and generic interface that I might be able to use for
# things like opening doors in a level, opening chests/flipping switches etc.
# This node can keep an array of various interactibles within a level
# and provide several helper functions for managing them perhaps.
export(String) var modifier_parent_callback = ""
export var debug_receiver :bool = false
var call_function: FuncRef
#var interactable_function_callables = []
var modifier_collection = []
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
##NOTE:
## Call function should be implemented as two parameters, one expecting a modifier
## and the other expecting a boolean as to whether its being added
# Called when the node enters the scene tree for the first time.
func _ready():
if modifier_parent_callback:
call_function = funcref(owner, modifier_parent_callback)
else:
print("Warning: No modifier receiver function defined on ", owner.name)
# Switching to a new model that starts with Hitbox
func register_modifier(modifier: StateModifier):
if modifier_collection.has(modifier) == false:
print("New Modifier Registered " + modifier.name)
modifier_collection.append(modifier)
if call_function.is_valid():
call_function.call_func(modifier, true)
func remove_modifier(modifier):
print("Modifier Removal " + modifier.name)
if modifier_collection.has(modifier):
var modifier_index = modifier_collection.rfind(modifier)
if modifier_index != -1:
modifier_collection.remove(modifier_index)
if call_function.is_valid():
call_function.call_func(modifier, false)

View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://src/components/Modifier_Receiver.gd" type="Script" id=1]
[node name="Modifier_Receiver" type="Node2D"]
script = ExtResource( 1 )

View File

@ -27,6 +27,13 @@ func hit_Receiver(damage):
yield( get_tree().create_timer(2 + $movement_state_machine/hurt.timeout_seconds), "timeout") yield( get_tree().create_timer(2 + $movement_state_machine/hurt.timeout_seconds), "timeout")
$Hurtbox_Component.set_hurtbox(true) $Hurtbox_Component.set_hurtbox(true)
func receive_modifier(incomming_modifier :StateModifier, is_adding_modifier_operation: bool):
#var mod :StateModifier
if is_adding_modifier_operation:
print("Player Received modifier:", incomming_modifier.name)
else:
print("Player Removed modifier:", incomming_modifier.name)
func touch_the_thing(the_thing: Interactable) -> bool: func touch_the_thing(the_thing: Interactable) -> bool:
print("You see! a THING...", the_thing.name) print("You see! a THING...", the_thing.name)
if the_thing is HealthPickup: if the_thing is HealthPickup:

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=126 format=2] [gd_scene load_steps=127 format=2]
[ext_resource path="res://src/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1] [ext_resource path="res://src/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
[ext_resource path="res://src/playerD/movement_component.gd" type="Script" id=2] [ext_resource path="res://src/playerD/movement_component.gd" type="Script" id=2]
@ -8,6 +8,7 @@
[ext_resource path="res://src/playerD/states/fall.gd" type="Script" id=6] [ext_resource path="res://src/playerD/states/fall.gd" type="Script" id=6]
[ext_resource path="res://src/components/Health_Component.tscn" type="PackedScene" id=7] [ext_resource path="res://src/components/Health_Component.tscn" type="PackedScene" id=7]
[ext_resource path="res://src/playerD/states/jump.gd" type="Script" id=8] [ext_resource path="res://src/playerD/states/jump.gd" type="Script" id=8]
[ext_resource path="res://src/components/Modifier_Receiver.tscn" type="PackedScene" id=9]
[ext_resource path="res://src/playerD/states/attack.gd" type="Script" id=10] [ext_resource path="res://src/playerD/states/attack.gd" type="Script" id=10]
[ext_resource path="res://src/playerD/states/dash.gd" type="Script" id=11] [ext_resource path="res://src/playerD/states/dash.gd" type="Script" id=11]
[ext_resource path="res://src/playerD/states/hurt.gd" type="Script" id=12] [ext_resource path="res://src/playerD/states/hurt.gd" type="Script" id=12]
@ -578,14 +579,12 @@ roll_node = NodePath("../roll")
[node name="fall" parent="movement_state_machine" index="1"] [node name="fall" parent="movement_state_machine" index="1"]
script = ExtResource( 6 ) script = ExtResource( 6 )
debug_state = true
move_speed = 90.0 move_speed = 90.0
animation_sequence = [ "jump" ] animation_sequence = [ "jump" ]
landing_node = NodePath("") landing_node = NodePath("")
[node name="move" parent="movement_state_machine" index="2"] [node name="move" parent="movement_state_machine" index="2"]
script = ExtResource( 5 ) script = ExtResource( 5 )
debug_state = true
move_speed = 90.0 move_speed = 90.0
animation_sequence = [ "step", "run" ] animation_sequence = [ "step", "run" ]
jump_node = NodePath("../jump") jump_node = NodePath("../jump")
@ -593,7 +592,6 @@ attack_node = NodePath("../attack")
[node name="jump" type="Node" parent="movement_state_machine" index="3"] [node name="jump" type="Node" parent="movement_state_machine" index="3"]
script = ExtResource( 8 ) script = ExtResource( 8 )
debug_state = true
move_speed = 90.0 move_speed = 90.0
animation_sequence = [ "jump" ] animation_sequence = [ "jump" ]
idle_node = NodePath("../idle") idle_node = NodePath("../idle")
@ -675,6 +673,10 @@ default_color = Color( 1, 0.607843, 0, 1 )
script = ExtResource( 16 ) script = ExtResource( 16 )
interactable_parent_callback = "touch_the_thing" interactable_parent_callback = "touch_the_thing"
[node name="Modifier_Receiver" parent="." index="9" instance=ExtResource( 9 )]
modifier_parent_callback = "receive_modifier"
debug_receiver = true
[connection signal="do_attack" from="movement_state_machine/attack" to="." method="_on_attack_do_attack"] [connection signal="do_attack" from="movement_state_machine/attack" to="." method="_on_attack_do_attack"]
[connection signal="frame_reached" from="movement_state_machine/roll" to="." method="_on_roll_frame_reached"] [connection signal="frame_reached" from="movement_state_machine/roll" to="." method="_on_roll_frame_reached"]
[connection signal="state_exited" from="movement_state_machine/roll" to="." method="_on_roll_state_exited"] [connection signal="state_exited" from="movement_state_machine/roll" to="." method="_on_roll_state_exited"]

View File

@ -92,6 +92,7 @@ func get_modifier_properties() -> ModifierProperties:
modifier_properties.jerk_factor) modifier_properties.jerk_factor)
func ready(modifier_name:String, anim_name:String = '', type = TYPE.NONE, timeout : float = 0, parent:Node = null, function_name : String = "") -> Timer: func ready(modifier_name:String, anim_name:String = '', type = TYPE.NONE, timeout : float = 0, parent:Node = null, function_name : String = "") -> Timer:
name = modifier_name
# If somebody forgot to specify the type # If somebody forgot to specify the type
if anim_name != '' and type == TYPE.NONE: if anim_name != '' and type == TYPE.NONE:
modifier_type = TYPE.REPLACE_ANIMATION modifier_type = TYPE.REPLACE_ANIMATION