From 19c15fab5de83a374ea379f5efe979806b7b8ca5 Mon Sep 17 00:00:00 2001 From: Dustin Date: Sun, 13 Apr 2025 12:39:18 -0700 Subject: [PATCH] Working on level and hitbox stuff mostly because I forgot to commit to the feature branch --- .../LegacyFantasy-High_Forest/tileset.tres | 43 +++++++++++++++++-- .../collision_shape2D_state_receiver.gd | 10 ++++- .../Hitbox-CollisionShape2D_StateReceiver.gd | 29 +++++++++++++ src/actors/players/playerE/PlayerE.tscn | 21 ++++++++- src/levels/TestBox.tscn | 17 ++++++-- 5 files changed, 110 insertions(+), 10 deletions(-) create mode 100644 src/actors/players/playerE/Hitbox-CollisionShape2D_StateReceiver.gd diff --git a/assets/levels/LegacyFantasy-High_Forest/tileset.tres b/assets/levels/LegacyFantasy-High_Forest/tileset.tres index 275ef99..ff46254 100644 --- a/assets/levels/LegacyFantasy-High_Forest/tileset.tres +++ b/assets/levels/LegacyFantasy-High_Forest/tileset.tres @@ -1,4 +1,4 @@ -[gd_resource type="TileSet" load_steps=17 format=2] +[gd_resource type="TileSet" load_steps=21 format=2] [ext_resource path="res://assets/levels/LegacyFantasy-High_Forest/Tiles/Tiles.png" type="Texture" id=1] @@ -38,6 +38,18 @@ points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 ) [sub_resource type="ConvexPolygonShape2D" id=12] points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 ) +[sub_resource type="ConvexPolygonShape2D" id=16] +points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 ) + +[sub_resource type="ConvexPolygonShape2D" id=17] +points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 ) + +[sub_resource type="ConvexPolygonShape2D" id=18] +points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 ) + +[sub_resource type="ConvexPolygonShape2D" id=19] +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 ) @@ -203,9 +215,34 @@ points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 ) 3/navigation_offset = Vector2( 0, 0 ) 3/shape_offset = Vector2( 0, 0 ) 3/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) +3/shape = SubResource( 16 ) 3/shape_one_way = false -3/shape_one_way_margin = 0.0 -3/shapes = [ ] +3/shape_one_way_margin = 1.0 +3/shapes = [ { +"autotile_coord": Vector2( 1, 1 ), +"one_way": false, +"one_way_margin": 1.0, +"shape": SubResource( 16 ), +"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 ) +}, { +"autotile_coord": Vector2( 2, 1 ), +"one_way": false, +"one_way_margin": 1.0, +"shape": SubResource( 17 ), +"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 ) +}, { +"autotile_coord": Vector2( 3, 1 ), +"one_way": false, +"one_way_margin": 1.0, +"shape": SubResource( 18 ), +"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 ) +}, { +"autotile_coord": Vector2( 4, 1 ), +"one_way": false, +"one_way_margin": 1.0, +"shape": SubResource( 19 ), +"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 ) +} ] 3/z_index = 0 4/name = "Pillar" 4/texture = ExtResource( 1 ) diff --git a/lib/classes/collision_shape2D_state_receiver.gd b/lib/classes/collision_shape2D_state_receiver.gd index 3425b74..82e4e9f 100644 --- a/lib/classes/collision_shape2D_state_receiver.gd +++ b/lib/classes/collision_shape2D_state_receiver.gd @@ -9,10 +9,14 @@ onready var current_state :StateAnimatedActor ## return to default when no state function export var default_shape_when_no_state_function :bool = true +export var disable_shape_when_no_state_function :bool = false # Declare member variables here. Examples: # var a = 2 -# var b = "text" +# var b = "text +## Generic parent ref node, can be kinematic2d area, etc. +var parent + var default_shape :Shape2D var default_transform :Transform2D @@ -26,6 +30,8 @@ func _ready(): ## A reference to the current state machine state current_state = get_node(callable_state_machine).current_state + parent = get_parent() + default_shape = shape.duplicate() ##TODO: Are transforms primitives? Do they get passed by value? default_transform = transform @@ -49,6 +55,8 @@ func _on_state_change(old_state_name:String, new_state :State): print ("Returning to default collision shape") shape = default_shape transform = default_transform + if disable_shape_when_no_state_function: + set_deferred("disabled", true) else: push_warning("Received non animated Actor state.") diff --git a/src/actors/players/playerE/Hitbox-CollisionShape2D_StateReceiver.gd b/src/actors/players/playerE/Hitbox-CollisionShape2D_StateReceiver.gd new file mode 100644 index 0000000..dfb53ce --- /dev/null +++ b/src/actors/players/playerE/Hitbox-CollisionShape2D_StateReceiver.gd @@ -0,0 +1,29 @@ +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_attack_sword(): + print ("<---- Hey you called me to Hurt Someone!") + transform = transform.translated(Vector2(-10,10)) + match current_state.animation_frame: + 2: + transform.origin = Vector2(0,-16) + 3: + transform.origin = Vector2(19,0) + 5: + transform.origin = Vector2(20,0) + _: + set_deferred("disabled", true) diff --git a/src/actors/players/playerE/PlayerE.tscn b/src/actors/players/playerE/PlayerE.tscn index c8a68cd..6154701 100644 --- a/src/actors/players/playerE/PlayerE.tscn +++ b/src/actors/players/playerE/PlayerE.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=38 format=2] +[gd_scene load_steps=41 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] @@ -31,6 +31,8 @@ [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/PlayerE-CollisionShape2D_StateReceiver.gd" type="Script" id=31] +[ext_resource path="res://src/actors/players/playerE/Hitbox-CollisionShape2D_StateReceiver.gd" type="Script" id=32] +[ext_resource path="res://lib/components/Hitbox_Component.tscn" type="PackedScene" id=33] [sub_resource type="Resource" id=3] resource_local_to_scene = true @@ -76,6 +78,9 @@ extents = Vector2( 7, 14 ) [sub_resource type="RectangleShape2D" id=2] extents = Vector2( 9, 15 ) +[sub_resource type="RectangleShape2D" id=7] +extents = Vector2( 10, 3 ) + [node name="PlayerE" instance=ExtResource( 1 )] script = ExtResource( 3 ) actor_type = "Player" @@ -87,7 +92,8 @@ states = [ ExtResource( 4 ), ExtResource( 9 ), ExtResource( 7 ), ExtResource( 8 [node name="AnimatedSprite_StateReceiver" parent="." index="1"] frames = ExtResource( 2 ) -animation = "attack-shoot" +animation = "attack-sword" +frame = 3 script = ExtResource( 5 ) __meta__ = { "_aseprite_wizard_config_": { @@ -161,5 +167,16 @@ interactable_parent_callback = "touch_the_thing" [node name="PewMachine" parent="." index="12" instance=ExtResource( 28 )] +[node name="Hitbox_Component" parent="." index="13" instance=ExtResource( 33 )] +collision_layer = 64 +damage_amount = 10 + +[node name="CollisionShape2D_StateReceiver" type="CollisionShape2D" parent="Hitbox_Component" index="0"] +modulate = Color( 1, 0, 0, 1 ) +position = Vector2( -20, 0 ) +shape = SubResource( 7 ) +script = ExtResource( 32 ) +callable_state_machine = NodePath("../../Movement_StateMachine") + [connection signal="state_changed" from="Movement_StateMachine" to="." method="_on_Movement_StateMachine_state_changed"] [connection signal="health_depleted" from="Health_Component" to="." method="_on_Health_Component_health_depleted"] diff --git a/src/levels/TestBox.tscn b/src/levels/TestBox.tscn index 67dbed8..987221e 100644 --- a/src/levels/TestBox.tscn +++ b/src/levels/TestBox.tscn @@ -52,7 +52,7 @@ music_track = ExtResource( 5 ) [node name="TileMap Collision" parent="." index="1"] tile_set = ExtResource( 2 ) -tile_data = PoolIntArray( 0, 4, 65536, 19, 4, 65536, 65536, 4, 65536, 65555, 4, 65536, 131072, 4, 65536, 131091, 4, 65536, 196608, 4, 65536, 196620, 2, 0, 196621, 2, 1, 196622, 2, 2, 196627, 4, 65536, 262144, 4, 0, 262156, 2, 65536, 262157, 2, 65537, 262158, 2, 65538, 262163, 4, 0, 327680, 4, 65536, 327699, 4, 65536, 393216, 4, 65536, 393237, 4, 0, 458752, 4, 65536, 458773, 4, 0, 589823, 0, 1, 524288, 4, 131072, 524289, 0, 3, 524290, 0, 1, 524291, 0, 2, 524292, 0, 3, 524293, 0, 1, 524294, 0, 2, 524295, 0, 3, 524296, 0, 1, 524297, 0, 2, 524298, 0, 3, 524299, 0, 1, 524300, 0, 2, 524301, 0, 3, 524302, 0, 1, 524303, 0, 2, 524304, 0, 3, 524305, 0, 1, 524306, 0, 2, 524308, 0, 1, 524309, 4, 0, 524310, 0, 3, 655359, 0, 65537, 589824, 0, 65538, 589825, 0, 65539, 589826, 0, 65537, 589827, 0, 65538, 589828, 0, 65539, 589829, 0, 65537, 589830, 0, 65538, 589831, 0, 65539, 589832, 0, 65537, 589833, 0, 65538, 589834, 0, 65539, 589835, 0, 65537, 589836, 0, 65538, 589837, 0, 65539, 589838, 0, 65537, 589839, 0, 65538, 589840, 0, 65539, 589841, 0, 65537, 589842, 0, 65538, 589843, 0, 65539, 589844, 0, 65537, 589845, 0, 65538, 589846, 0, 65539, 720895, 0, 131073, 655360, 0, 131074, 655361, 0, 131075, 655362, 0, 131073, 655363, 0, 131074, 655364, 0, 131075, 655365, 0, 131073, 655366, 0, 131074, 655367, 0, 131075, 655368, 0, 131073, 655369, 0, 131074, 655370, 0, 131075, 655371, 0, 131073, 655372, 0, 131074, 655373, 0, 131075, 655374, 0, 131073, 655375, 0, 131074, 655376, 0, 131075, 655377, 0, 131073, 655378, 0, 131074, 655379, 0, 131075, 655380, 0, 131073, 655381, 0, 131074, 655382, 0, 131075, 786431, 0, 196609, 720896, 0, 196610, 720897, 0, 196611, 720898, 0, 196609, 720899, 0, 196610, 720900, 0, 196611, 720901, 0, 196609, 720902, 0, 196610, 720903, 0, 196611, 720904, 0, 196609, 720905, 0, 196610, 720906, 0, 196611, 720907, 0, 196609, 720908, 0, 196610, 720909, 0, 196611, 720910, 0, 196609, 720911, 0, 196610, 720912, 0, 196611, 720913, 0, 196609, 720914, 0, 196610, 720915, 0, 196611, 720916, 0, 196609, 720917, 0, 196610, 720918, 0, 196611, 851967, 0, 262145, 786432, 0, 262146, 786433, 0, 262147, 786434, 0, 262145, 786435, 0, 262146, 786436, 0, 262147, 786437, 0, 262145, 786438, 0, 262146, 786439, 0, 262147, 786440, 0, 262145, 786441, 0, 262146, 786442, 0, 262147, 786443, 0, 262145, 786444, 0, 262146, 786445, 0, 262147, 786446, 0, 262145, 786447, 0, 262146, 786448, 0, 262147, 786449, 0, 262145, 786450, 0, 262146, 786451, 0, 262147, 786452, 0, 262145, 786453, 0, 262146, 786454, 0, 262147 ) +tile_data = PoolIntArray( 0, 4, 65536, 19, 4, 65536, 65536, 4, 65536, 65555, 4, 65536, 131072, 4, 65536, 131091, 4, 65536, 196608, 4, 65536, 196620, 2, 0, 196621, 2, 1, 196622, 2, 2, 196627, 4, 65536, 262144, 4, 0, 262156, 2, 65536, 262157, 2, 65537, 262158, 2, 65538, 262163, 4, 0, 327680, 4, 65536, 327699, 4, 65536, 327723, 0, 3, 327724, 0, 2, 327725, 0, 3, 327726, 0, 3, 327727, 0, 2, 327728, 0, 3, 327729, 0, 3, 327730, 0, 2, 327731, 0, 3, 393216, 4, 65536, 393237, 4, 0, 393257, 1, 65536, 393258, 1, 65537, 393259, 0, 65538, 393260, 0, 65537, 393261, 0, 65538, 393262, 0, 65538, 393263, 0, 65537, 393264, 0, 65538, 393265, 0, 65538, 393266, 0, 65537, 393267, 0, 65538, 458752, 4, 65536, 458773, 4, 0, 458790, 1, 1, 458791, 1, 65536, 458792, 1, 65537, 458793, 1, 131072, 458794, 1, 131073, 458795, 0, 196611, 458796, 0, 196610, 458797, 0, 196611, 458798, 0, 196611, 458799, 0, 196610, 458800, 0, 196611, 458801, 0, 196611, 458802, 0, 196610, 458803, 0, 196611, 589823, 0, 1, 524288, 4, 131072, 524289, 0, 3, 524290, 0, 1, 524291, 0, 2, 524292, 0, 3, 524293, 0, 1, 524294, 0, 2, 524295, 0, 3, 524296, 0, 1, 524297, 0, 2, 524298, 0, 3, 524299, 0, 1, 524300, 0, 2, 524301, 0, 3, 524302, 0, 1, 524303, 0, 2, 524304, 0, 3, 524305, 0, 1, 524306, 0, 2, 524308, 0, 1, 524309, 4, 0, 524310, 0, 3, 524311, 0, 4, 524315, 3, 0, 524316, 3, 1, 524317, 3, 2, 524318, 3, 3, 524319, 3, 1, 524320, 3, 2, 524321, 3, 3, 524322, 3, 1, 524323, 3, 2, 524324, 3, 3, 524325, 1, 65536, 524326, 1, 65537, 524327, 1, 131072, 524328, 1, 131073, 524329, 0, 131074, 524330, 0, 131075, 524331, 0, 196610, 524332, 0, 196610, 524333, 0, 196610, 524334, 0, 196610, 524335, 0, 196610, 524336, 0, 196610, 524337, 0, 196610, 524338, 0, 196610, 524339, 0, 196610, 655359, 0, 65537, 589824, 0, 65538, 589825, 0, 65539, 589826, 0, 65537, 589827, 0, 65538, 589828, 0, 65539, 589829, 0, 65537, 589830, 0, 65538, 589831, 0, 65539, 589832, 0, 65537, 589833, 0, 65538, 589834, 0, 65539, 589835, 0, 65537, 589836, 0, 65538, 589837, 0, 65539, 589838, 0, 65537, 589839, 0, 65538, 589840, 0, 65539, 589841, 0, 65537, 589842, 0, 65538, 589843, 0, 65539, 589844, 0, 65537, 589845, 0, 65538, 589846, 0, 65539, 589847, 0, 65540, 589851, 3, 65536, 589852, 3, 65537, 589853, 3, 65538, 589854, 3, 65539, 589855, 3, 65537, 589856, 3, 65538, 589857, 3, 65539, 589858, 3, 65537, 589859, 3, 65538, 589860, 3, 65539, 589861, 1, 131072, 589862, 1, 131073, 589863, 0, 131073, 589864, 0, 131074, 589865, 0, 196610, 589866, 0, 196610, 589867, 0, 196610, 589868, 0, 196610, 589869, 0, 196610, 589870, 0, 196610, 589871, 0, 196610, 589872, 0, 196610, 589873, 0, 196610, 589874, 0, 196610, 589875, 0, 196610, 720895, 0, 131073, 655360, 0, 131074, 655361, 0, 131075, 655362, 0, 131073, 655363, 0, 131074, 655364, 0, 131075, 655365, 0, 131073, 655366, 0, 131074, 655367, 0, 131075, 655368, 0, 131073, 655369, 0, 131074, 655370, 0, 131075, 655371, 0, 131073, 655372, 0, 131074, 655373, 0, 131075, 655374, 0, 131073, 655375, 0, 131074, 655376, 0, 131075, 655377, 0, 131073, 655378, 0, 131074, 655379, 0, 131075, 655380, 0, 131073, 655381, 0, 131074, 655382, 0, 131075, 655383, 0, 131076, 655387, 3, 131072, 655388, 3, 131073, 655389, 3, 131074, 655390, 3, 131075, 655391, 3, 131073, 655392, 3, 131074, 655393, 3, 131075, 655394, 3, 131073, 655395, 3, 131074, 655396, 3, 131075, 655397, 0, 131074, 655398, 0, 131075, 655399, 0, 131073, 655400, 0, 196610, 655401, 0, 196610, 655402, 0, 196610, 655403, 0, 196610, 655404, 0, 196610, 655405, 0, 196610, 655406, 0, 196610, 655407, 0, 196610, 655408, 0, 196610, 655409, 0, 196610, 655410, 0, 196610, 655411, 0, 196610, 786431, 0, 196609, 720896, 0, 196610, 720897, 0, 196611, 720898, 0, 196609, 720899, 0, 196610, 720900, 0, 196611, 720901, 0, 196609, 720902, 0, 196610, 720903, 0, 196611, 720904, 0, 196609, 720905, 0, 196610, 720906, 0, 196611, 720907, 0, 196609, 720908, 0, 196610, 720909, 0, 196611, 720910, 0, 196609, 720911, 0, 196610, 720912, 0, 196611, 720913, 0, 196609, 720914, 0, 196610, 720915, 0, 196611, 720916, 0, 196609, 720917, 0, 196610, 720918, 0, 196611, 720919, 0, 196612, 720923, 3, 196608, 720924, 3, 196609, 720925, 3, 196609, 720926, 3, 196609, 720927, 3, 196609, 720928, 3, 196609, 720929, 3, 196609, 720930, 3, 196609, 720931, 3, 196609, 720932, 3, 196609, 720933, 0, 196609, 720934, 0, 196610, 720935, 0, 196610, 720936, 0, 196611, 720937, 0, 196610, 720938, 0, 196610, 720939, 0, 196610, 720940, 0, 196610, 720941, 0, 196610, 720942, 0, 196610, 720943, 0, 196610, 720944, 0, 196610, 720945, 0, 196610, 720946, 0, 196610, 720947, 0, 196610, 851967, 0, 262145, 786432, 0, 262146, 786433, 0, 262147, 786434, 0, 262145, 786435, 0, 262146, 786436, 0, 262147, 786437, 0, 262145, 786438, 0, 262146, 786439, 0, 262147, 786440, 0, 262145, 786441, 0, 262146, 786442, 0, 262147, 786443, 0, 262145, 786444, 0, 262146, 786445, 0, 262147, 786446, 0, 262145, 786447, 0, 262146, 786448, 0, 262147, 786449, 0, 262145, 786450, 0, 262146, 786451, 0, 262147, 786452, 0, 262145, 786453, 0, 262146, 786454, 0, 262147, 786455, 0, 262148 ) [node name="TileMap Foreground" parent="." index="2"] tile_set = ExtResource( 2 ) @@ -117,7 +117,7 @@ show_collision = true collision_layer = 256 collision_mask = 0 format = 1 -tile_data = PoolIntArray( -65536, 0, 0, -65521, 0, 0, 65535, 0, 0, 16, 0, 0, 524287, 0, 0, 524304, 0, 0, 589824, 0, 0, 589838, 0, 0 ) +tile_data = PoolIntArray( -65536, 0, 0, -65521, 0, 0, -65514, 0, 0, -65507, 0, 0, 65535, 0, 0, 524287, 0, 0, 589824, 0, 0, 589838, 0, 0, 589845, 0, 0, 589851, 0, 0 ) [node name="ItemPickup" parent="." index="9" instance=ExtResource( 7 )] position = Vector2( 203, 38 ) @@ -128,8 +128,17 @@ count = 10 [node name="CollisionShape2D" type="CollisionShape2D" parent="ItemPickup" index="0"] shape = SubResource( 6 ) -[node name="ItemPickup2" parent="." index="10" instance=ExtResource( 7 )] -position = Vector2( 155, 133 ) +[node name="ItemPickup3" parent="." index="10" instance=ExtResource( 7 )] +position = Vector2( 817, 75 ) +type_name = "item_pickup" +item = ExtResource( 8 ) +count = 10 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="ItemPickup3" index="0"] +shape = SubResource( 6 ) + +[node name="ItemPickup2" parent="." index="11" instance=ExtResource( 7 )] +position = Vector2( 162, 109 ) type_name = "item_pickup" item = ExtResource( 9 )