From c291f425314ab02b7f369ab86cf9486aa7ffa7bf Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Tue, 13 May 2025 00:44:44 +0200 Subject: [PATCH] Refactor brick throwing mechanics; integrate new input handling and projectile initialization components --- objects/entities/brick.tscn | 27 +++++++-- objects/entities/brick_player.tscn | 10 +--- objects/entities/exploding_brick.tscn | 8 ++- objects/entities/fire_brick.tscn | 29 +++++++-- objects/entities/ice_brick.tscn | 29 +++++++-- objects/player_skills/brick_throw_skill.tscn | 4 +- resources/skills/brick_throw.tres | 5 +- resources/skills/explosive_brick.tres | 5 +- resources/skills/fire_brick.tres | 4 +- resources/skills/ice_brick.tres | 4 +- .../throw_behaviors/charge_throw_input.tres | 11 ++++ .../throw_behaviors/tap_throw_input.tres | 7 +++ scripts/components/brick_throw.gd | 39 ++++++------ scripts/components/chargable_component.gd | 2 - scripts/components/chargable_component.gd.uid | 1 - .../components/projectile_init_component.gd | 20 +++++++ .../projectile_init_component.gd.uid | 1 + .../resources/charge_throw_input_resource.gd | 56 ++++++++++++++++++ .../charge_throw_input_resource.gd.uid | 1 + scripts/resources/tap_throw_input_resource.gd | 6 ++ .../resources/tap_throw_input_resource.gd.uid | 1 + scripts/resources/throw_input_resource.gd | 16 +++++ scripts/resources/throw_input_resource.gd.uid | 1 + scripts/skill_manager.gd | 2 +- scripts/ui/charge_progress_bar.gd | 59 ++++++++++++++----- 25 files changed, 276 insertions(+), 72 deletions(-) create mode 100644 resources/throw_behaviors/charge_throw_input.tres create mode 100644 resources/throw_behaviors/tap_throw_input.tres delete mode 100644 scripts/components/chargable_component.gd delete mode 100644 scripts/components/chargable_component.gd.uid create mode 100644 scripts/components/projectile_init_component.gd create mode 100644 scripts/components/projectile_init_component.gd.uid create mode 100644 scripts/resources/charge_throw_input_resource.gd create mode 100644 scripts/resources/charge_throw_input_resource.gd.uid create mode 100644 scripts/resources/tap_throw_input_resource.gd create mode 100644 scripts/resources/tap_throw_input_resource.gd.uid create mode 100644 scripts/resources/throw_input_resource.gd create mode 100644 scripts/resources/throw_input_resource.gd.uid diff --git a/objects/entities/brick.tscn b/objects/entities/brick.tscn index af57a9c..b4f4c36 100644 --- a/objects/entities/brick.tscn +++ b/objects/entities/brick.tscn @@ -1,9 +1,12 @@ -[gd_scene load_steps=6 format=3 uid="uid://bymro4t7angv5"] +[gd_scene load_steps=9 format=3 uid="uid://bymro4t7angv5"] [ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_1c3jb"] [ext_resource type="Script" uid="uid://cdnwrn8v05qhi" path="res://scripts/components/bullet_component.gd" id="2_i6t5k"] [ext_resource type="Script" uid="uid://dkmxhjtmu5xlb" path="res://scripts/components/damage_component.gd" id="3_8xipx"] [ext_resource type="Script" uid="uid://1tnr46o1ib4u" path="res://scripts/components/out_of_screen_component.gd" id="4_rdtjq"] +[ext_resource type="Script" uid="uid://bgty7040ams6s" path="res://scripts/components/projectile_init_component.gd" id="5_2vqt8"] +[ext_resource type="Script" uid="uid://873un8agkyja" path="res://scripts/components/launch_component.gd" id="6_d0tcd"] +[ext_resource type="Script" uid="uid://cvcnfrr1udco5" path="res://scripts/components/straight_motion_component.gd" id="7_r41xl"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_ar0xf"] size = Vector2(16, 10) @@ -21,13 +24,10 @@ hframes = 12 vframes = 12 frame = 80 -[node name="BulletComponent" type="Node" parent="." node_paths=PackedStringArray("root", "area2d", "timer")] +[node name="BulletComponent" type="Node" parent="." node_paths=PackedStringArray("root", "area2d")] script = ExtResource("2_i6t5k") root = NodePath("..") -speed = 320.0 area2d = NodePath("..") -life_time = 2.0 -timer = NodePath("../Timer") [node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."] position = Vector2(0, 2.38419e-07) @@ -43,3 +43,20 @@ area2d = NodePath("..") script = ExtResource("4_rdtjq") visibility_notifier = NodePath("../VisibleOnScreenNotifier2D") root = NodePath("..") + +[node name="ProjectileInitComponent" type="Node" parent="." node_paths=PackedStringArray("launch_component")] +script = ExtResource("5_2vqt8") +launch_component = NodePath("../LaunchComponent") +metadata/_custom_type_script = "uid://bgty7040ams6s" + +[node name="LaunchComponent" type="Node2D" parent="." node_paths=PackedStringArray("root")] +script = ExtResource("6_d0tcd") +root = NodePath(".") +speed = 180.0 +metadata/_custom_type_script = "uid://873un8agkyja" + +[node name="StraightMotionComponent" type="Node" parent="." node_paths=PackedStringArray("root", "launch_component")] +script = ExtResource("7_r41xl") +root = NodePath("..") +launch_component = NodePath("../LaunchComponent") +metadata/_custom_type_script = "uid://cvcnfrr1udco5" diff --git a/objects/entities/brick_player.tscn b/objects/entities/brick_player.tscn index 9e847c1..0bdf233 100644 --- a/objects/entities/brick_player.tscn +++ b/objects/entities/brick_player.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=32 format=3 uid="uid://bqi5s710xb1ju"] +[gd_scene load_steps=31 format=3 uid="uid://bqi5s710xb1ju"] [ext_resource type="Script" uid="uid://ccuddyoakg04u" path="res://scripts/player.gd" id="1_8j4h4"] [ext_resource type="Texture2D" uid="uid://b7gp0gqvkv8j4" path="res://sprites/MrBrick_base.png" id="2_bc55y"] @@ -26,7 +26,6 @@ [ext_resource type="Script" uid="uid://bya240e627ti6" path="res://scripts/resources/skill_data.gd" id="21_d0oiv"] [ext_resource type="Resource" uid="uid://d3bjre2etov1n" path="res://resources/skills/magnetic.tres" id="22_vnsgd"] [ext_resource type="Script" uid="uid://bjsyeo1n7bsri" path="res://scripts/components/skill_unlocker_component.gd" id="23_qsv2c"] -[ext_resource type="Script" uid="uid://c6fclevp3peuo" path="res://scripts/components/charge_throw_component.gd" id="27_h8c1m"] [ext_resource type="PackedScene" uid="uid://bg76mtpcmfm2j" path="res://objects/ui/charging_bar_layer.tscn" id="28_3f5nm"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_hdsg1"] @@ -159,16 +158,11 @@ stream = ExtResource("19_7anly") [node name="sfx_heal" type="AudioStreamPlayer2D" parent="."] stream = ExtResource("20_bptj5") -[node name="ChargeThrowComponent" type="Node" parent="."] -script = ExtResource("27_h8c1m") -metadata/_custom_type_script = "uid://c6fclevp3peuo" - -[node name="ChargingBarLayer" parent="." node_paths=PackedStringArray("charge_throw_component") instance=ExtResource("28_3f5nm")] +[node name="ChargingBarLayer" parent="." instance=ExtResource("28_3f5nm")] offset_left = -17.0 offset_top = -30.0 offset_right = 23.0 offset_bottom = -20.0 -charge_throw_component = NodePath("../ChargeThrowComponent") [connection signal="on_death" from="HealthComponent" to="PlayerDeathComponent" method="_on_health_component_on_death"] [connection signal="on_health_change" from="HealthComponent" to="KnockbackComponent" method="_on_health_component_on_health_change"] diff --git a/objects/entities/exploding_brick.tscn b/objects/entities/exploding_brick.tscn index 4b570ee..3e7ee06 100644 --- a/objects/entities/exploding_brick.tscn +++ b/objects/entities/exploding_brick.tscn @@ -7,7 +7,7 @@ [ext_resource type="Script" uid="uid://873un8agkyja" path="res://scripts/components/launch_component.gd" id="7_a2b5x"] [ext_resource type="Script" uid="uid://bvsgg8lu0a8m6" path="res://scripts/components/lifetime_component.gd" id="7_nqeob"] [ext_resource type="Script" uid="uid://c2gbumw4x4t1v" path="res://scripts/components/gravity_motion_component.gd" id="8_4ly8b"] -[ext_resource type="Script" uid="uid://ciowd622nk0i7" path="res://scripts/components/chargable_component.gd" id="9_a2b5x"] +[ext_resource type="Script" uid="uid://bgty7040ams6s" path="res://scripts/components/projectile_init_component.gd" id="8_nqeob"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_ar0xf"] size = Vector2(16, 10) @@ -85,5 +85,7 @@ collision_layer = 16 [node name="CollisionShape2D" type="CollisionShape2D" parent="BulletArea"] shape = SubResource("RectangleShape2D_nqeob") -[node name="ChargableComponent" type="Node" parent="."] -script = ExtResource("9_a2b5x") +[node name="ProjectileInitComponent" type="Node" parent="." node_paths=PackedStringArray("launch_component")] +script = ExtResource("8_nqeob") +launch_component = NodePath("../LaunchComponent") +metadata/_custom_type_script = "uid://bgty7040ams6s" diff --git a/objects/entities/fire_brick.tscn b/objects/entities/fire_brick.tscn index 979b6c5..74fb710 100644 --- a/objects/entities/fire_brick.tscn +++ b/objects/entities/fire_brick.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=8 format=3 uid="uid://daau4j5hbklk0"] +[gd_scene load_steps=11 format=3 uid="uid://daau4j5hbklk0"] [ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_52l28"] [ext_resource type="Script" uid="uid://cdnwrn8v05qhi" path="res://scripts/components/bullet_component.gd" id="2_hjcob"] @@ -6,11 +6,14 @@ [ext_resource type="Resource" uid="uid://obodgnkhxuhe" path="res://resources/status_effect/fire.tres" id="4_xx5l4"] [ext_resource type="Script" uid="uid://d3brcje121krs" path="res://scripts/components/effect_inflictor_component.gd" id="5_ofrqk"] [ext_resource type="Script" uid="uid://1tnr46o1ib4u" path="res://scripts/components/out_of_screen_component.gd" id="6_64yur"] +[ext_resource type="Script" uid="uid://873un8agkyja" path="res://scripts/components/launch_component.gd" id="7_hulun"] +[ext_resource type="Script" uid="uid://cvcnfrr1udco5" path="res://scripts/components/straight_motion_component.gd" id="8_kift8"] +[ext_resource type="Script" uid="uid://bgty7040ams6s" path="res://scripts/components/projectile_init_component.gd" id="9_5ybdf"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_ar0xf"] size = Vector2(16, 10) -[node name="Brick" type="Area2D"] +[node name="FireBrick" type="Area2D"] collision_layer = 16 collision_mask = 9 @@ -23,13 +26,10 @@ hframes = 12 vframes = 12 frame = 80 -[node name="BulletComponent" type="Node" parent="." node_paths=PackedStringArray("root", "area2d", "timer")] +[node name="BulletComponent" type="Node" parent="." node_paths=PackedStringArray("root", "area2d")] script = ExtResource("2_hjcob") root = NodePath("..") -speed = 330.0 area2d = NodePath("..") -life_time = 2.0 -timer = NodePath("../Timer") [node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."] position = Vector2(0, 2.38419e-07) @@ -51,3 +51,20 @@ damage = NodePath("../DamageComponent") script = ExtResource("6_64yur") visibility_notifier = NodePath("../VisibleOnScreenNotifier2D") root = NodePath("..") + +[node name="LaunchComponent" type="Node2D" parent="." node_paths=PackedStringArray("root")] +script = ExtResource("7_hulun") +root = NodePath("..") +speed = 200.0 +metadata/_custom_type_script = "uid://873un8agkyja" + +[node name="StraightMotionComponent" type="Node" parent="." node_paths=PackedStringArray("root", "launch_component")] +script = ExtResource("8_kift8") +root = NodePath("..") +launch_component = NodePath("../LaunchComponent") +metadata/_custom_type_script = "uid://cvcnfrr1udco5" + +[node name="ProjectileInitComponent" type="Node" parent="." node_paths=PackedStringArray("launch_component")] +script = ExtResource("9_5ybdf") +launch_component = NodePath("../LaunchComponent") +metadata/_custom_type_script = "uid://bgty7040ams6s" diff --git a/objects/entities/ice_brick.tscn b/objects/entities/ice_brick.tscn index 486da1c..a4695ec 100644 --- a/objects/entities/ice_brick.tscn +++ b/objects/entities/ice_brick.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=8 format=3 uid="uid://bcmx07k12gcsc"] +[gd_scene load_steps=11 format=3 uid="uid://bcmx07k12gcsc"] [ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_xusxl"] [ext_resource type="Script" uid="uid://cdnwrn8v05qhi" path="res://scripts/components/bullet_component.gd" id="2_ilnf5"] @@ -6,11 +6,14 @@ [ext_resource type="Resource" uid="uid://02l4nbnf2aft" path="res://resources/status_effect/ice.tres" id="4_da7hn"] [ext_resource type="Script" uid="uid://d3brcje121krs" path="res://scripts/components/effect_inflictor_component.gd" id="5_x7vqb"] [ext_resource type="Script" uid="uid://1tnr46o1ib4u" path="res://scripts/components/out_of_screen_component.gd" id="6_7tdxt"] +[ext_resource type="Script" uid="uid://cvcnfrr1udco5" path="res://scripts/components/straight_motion_component.gd" id="7_22hnt"] +[ext_resource type="Script" uid="uid://873un8agkyja" path="res://scripts/components/launch_component.gd" id="8_xvjl0"] +[ext_resource type="Script" uid="uid://bgty7040ams6s" path="res://scripts/components/projectile_init_component.gd" id="9_xvjl0"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_ar0xf"] size = Vector2(16, 10) -[node name="Brick" type="Area2D"] +[node name="IceBrick" type="Area2D"] collision_layer = 16 collision_mask = 9 @@ -23,13 +26,10 @@ hframes = 12 vframes = 12 frame = 80 -[node name="BulletComponent" type="Node" parent="." node_paths=PackedStringArray("root", "area2d", "timer")] +[node name="BulletComponent" type="Node" parent="." node_paths=PackedStringArray("root", "area2d")] script = ExtResource("2_ilnf5") root = NodePath("..") -speed = 250.0 area2d = NodePath("..") -life_time = 2.0 -timer = NodePath("../Timer") [node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."] position = Vector2(0, 2.38419e-07) @@ -51,3 +51,20 @@ damage = NodePath("../DamageComponent") script = ExtResource("6_7tdxt") visibility_notifier = NodePath("../VisibleOnScreenNotifier2D") root = NodePath("..") + +[node name="StraightMotionComponent" type="Node" parent="." node_paths=PackedStringArray("root", "launch_component")] +script = ExtResource("7_22hnt") +root = NodePath("..") +launch_component = NodePath("../LaunchComponent") +metadata/_custom_type_script = "uid://cvcnfrr1udco5" + +[node name="LaunchComponent" type="Node2D" parent="." node_paths=PackedStringArray("root")] +script = ExtResource("8_xvjl0") +root = NodePath("..") +speed = 170.0 +metadata/_custom_type_script = "uid://873un8agkyja" + +[node name="ProjectileInitComponent" type="Node" parent="." node_paths=PackedStringArray("launch_component")] +script = ExtResource("9_xvjl0") +launch_component = NodePath("../LaunchComponent") +metadata/_custom_type_script = "uid://bgty7040ams6s" diff --git a/objects/player_skills/brick_throw_skill.tscn b/objects/player_skills/brick_throw_skill.tscn index 983d777..e8ad897 100644 --- a/objects/player_skills/brick_throw_skill.tscn +++ b/objects/player_skills/brick_throw_skill.tscn @@ -1,9 +1,11 @@ -[gd_scene load_steps=3 format=3 uid="uid://coayig4dxelo2"] +[gd_scene load_steps=4 format=3 uid="uid://coayig4dxelo2"] [ext_resource type="Script" uid="uid://cm06xg1l3xtw5" path="res://scripts/components/brick_throw.gd" id="1_hniwk"] [ext_resource type="PackedScene" uid="uid://bymro4t7angv5" path="res://objects/entities/brick.tscn" id="2_4txoq"] +[ext_resource type="Resource" uid="uid://br84dsfa3ti04" path="res://resources/throw_behaviors/tap_throw_input.tres" id="3_gxahf"] [node name="BrickThrowComponent" type="Node"] script = ExtResource("1_hniwk") brick_scene = ExtResource("2_4txoq") fire_rate = 0.3 +throw_input_behavior = ExtResource("3_gxahf") diff --git a/resources/skills/brick_throw.tres b/resources/skills/brick_throw.tres index a295e1b..61ac617 100644 --- a/resources/skills/brick_throw.tres +++ b/resources/skills/brick_throw.tres @@ -1,7 +1,8 @@ -[gd_resource type="Resource" script_class="SkillData" load_steps=3 format=3 uid="uid://dw5ee2lpeypnb"] +[gd_resource type="Resource" script_class="SkillData" load_steps=4 format=3 uid="uid://dw5ee2lpeypnb"] [ext_resource type="PackedScene" uid="uid://coayig4dxelo2" path="res://objects/player_skills/brick_throw_skill.tscn" id="1_5gnea"] [ext_resource type="Script" uid="uid://bya240e627ti6" path="res://scripts/resources/skill_data.gd" id="1_etxe2"] +[ext_resource type="Resource" uid="uid://br84dsfa3ti04" path="res://resources/throw_behaviors/tap_throw_input.tres" id="1_xwijh"] [resource] script = ExtResource("1_etxe2") @@ -9,8 +10,8 @@ name = "Brick power" description = "Allows you to throw bricks at enemies" node = ExtResource("1_5gnea") config = { -"charge_throw_component": NodePath("ChargeThrowComponent"), "player_controller": NodePath("."), +"throw_input_behavior": ExtResource("1_xwijh"), "timer": NodePath("ThrowTimer") } cost = 50 diff --git a/resources/skills/explosive_brick.tres b/resources/skills/explosive_brick.tres index 6c6a377..8300640 100644 --- a/resources/skills/explosive_brick.tres +++ b/resources/skills/explosive_brick.tres @@ -1,6 +1,7 @@ -[gd_resource type="Resource" script_class="SkillData" load_steps=4 format=3 uid="uid://cdp8sex36vdq2"] +[gd_resource type="Resource" script_class="SkillData" load_steps=5 format=3 uid="uid://cdp8sex36vdq2"] [ext_resource type="PackedScene" uid="uid://5surx230gfw3" path="res://objects/entities/exploding_brick.tscn" id="1_6pfoa"] +[ext_resource type="Resource" uid="uid://diuv6pr6a0dup" path="res://resources/throw_behaviors/charge_throw_input.tres" id="2_87gkt"] [ext_resource type="PackedScene" uid="uid://coayig4dxelo2" path="res://objects/player_skills/brick_throw_skill.tscn" id="2_e0o8w"] [ext_resource type="Script" uid="uid://bya240e627ti6" path="res://scripts/resources/skill_data.gd" id="3_cgsq1"] @@ -11,8 +12,8 @@ description = "Allows you to throw explosive bricks at enemies" node = ExtResource("2_e0o8w") config = { "brick_scene": ExtResource("1_6pfoa"), -"charge_throw_component": NodePath("./ChargeThrowComponent"), "player_controller": NodePath("."), +"throw_input_behavior": ExtResource("2_87gkt"), "timer": NodePath("ThrowTimer") } cost = 180 diff --git a/resources/skills/fire_brick.tres b/resources/skills/fire_brick.tres index 7966566..857a1ca 100644 --- a/resources/skills/fire_brick.tres +++ b/resources/skills/fire_brick.tres @@ -1,8 +1,9 @@ -[gd_resource type="Resource" script_class="SkillData" load_steps=4 format=3 uid="uid://2glvryih82t1"] +[gd_resource type="Resource" script_class="SkillData" load_steps=5 format=3 uid="uid://2glvryih82t1"] [ext_resource type="PackedScene" uid="uid://daau4j5hbklk0" path="res://objects/entities/fire_brick.tscn" id="1_2g43l"] [ext_resource type="Script" uid="uid://bya240e627ti6" path="res://scripts/resources/skill_data.gd" id="1_2j5ko"] [ext_resource type="PackedScene" uid="uid://coayig4dxelo2" path="res://objects/player_skills/brick_throw_skill.tscn" id="1_g53fp"] +[ext_resource type="Resource" uid="uid://br84dsfa3ti04" path="res://resources/throw_behaviors/tap_throw_input.tres" id="2_dm5pj"] [resource] script = ExtResource("1_2j5ko") @@ -12,6 +13,7 @@ node = ExtResource("1_g53fp") config = { "brick_scene": ExtResource("1_2g43l"), "player_controller": NodePath("."), +"throw_input_behavior": ExtResource("2_dm5pj"), "timer": NodePath("ThrowTimer") } cost = 150 diff --git a/resources/skills/ice_brick.tres b/resources/skills/ice_brick.tres index 39e6821..25e48a2 100644 --- a/resources/skills/ice_brick.tres +++ b/resources/skills/ice_brick.tres @@ -1,7 +1,8 @@ -[gd_resource type="Resource" script_class="SkillData" load_steps=4 format=3 uid="uid://cx5fsbexblp60"] +[gd_resource type="Resource" script_class="SkillData" load_steps=5 format=3 uid="uid://cx5fsbexblp60"] [ext_resource type="PackedScene" uid="uid://bcmx07k12gcsc" path="res://objects/entities/ice_brick.tscn" id="1_ci3d1"] [ext_resource type="PackedScene" uid="uid://coayig4dxelo2" path="res://objects/player_skills/brick_throw_skill.tscn" id="1_rflri"] +[ext_resource type="Resource" uid="uid://br84dsfa3ti04" path="res://resources/throw_behaviors/tap_throw_input.tres" id="2_hsgyv"] [ext_resource type="Script" uid="uid://bya240e627ti6" path="res://scripts/resources/skill_data.gd" id="2_pspkt"] [resource] @@ -12,6 +13,7 @@ node = ExtResource("1_rflri") config = { "brick_scene": ExtResource("1_ci3d1"), "player_controller": NodePath("."), +"throw_input_behavior": ExtResource("2_hsgyv"), "timer": NodePath("ThrowTimer") } cost = 150 diff --git a/resources/throw_behaviors/charge_throw_input.tres b/resources/throw_behaviors/charge_throw_input.tres new file mode 100644 index 0000000..7ca6d08 --- /dev/null +++ b/resources/throw_behaviors/charge_throw_input.tres @@ -0,0 +1,11 @@ +[gd_resource type="Resource" script_class="ChargeThrowInputResource" load_steps=2 format=3 uid="uid://diuv6pr6a0dup"] + +[ext_resource type="Script" uid="uid://dl1kpll33o6mv" path="res://scripts/resources/charge_throw_input_resource.gd" id="1_6fb6k"] + +[resource] +script = ExtResource("1_6fb6k") +min_power = 0.5 +max_power = 2.0 +max_charge_time = 1.5 +min_charge_duration = 0.1 +metadata/_custom_type_script = "uid://dl1kpll33o6mv" diff --git a/resources/throw_behaviors/tap_throw_input.tres b/resources/throw_behaviors/tap_throw_input.tres new file mode 100644 index 0000000..7d4d1c7 --- /dev/null +++ b/resources/throw_behaviors/tap_throw_input.tres @@ -0,0 +1,7 @@ +[gd_resource type="Resource" script_class="TapThrowInputResource" load_steps=2 format=3 uid="uid://br84dsfa3ti04"] + +[ext_resource type="Script" uid="uid://blvdnsyi287rf" path="res://scripts/resources/tap_throw_input_resource.gd" id="1_c51dp"] + +[resource] +script = ExtResource("1_c51dp") +metadata/_custom_type_script = "uid://blvdnsyi287rf" diff --git a/scripts/components/brick_throw.gd b/scripts/components/brick_throw.gd index a36365c..4a04f43 100644 --- a/scripts/components/brick_throw.gd +++ b/scripts/components/brick_throw.gd @@ -5,7 +5,7 @@ extends Node @export var fire_rate: float = 1.0 @export var player_controller: PlayerController @export var timer: Timer -@export var charge_throw_component: ChargeThrowComponent +@export var throw_input_behavior: ThrowInputResource var can_throw: bool = true @@ -14,14 +14,18 @@ func _ready() -> void: setup_timer() can_throw = true + if throw_input_behavior: + throw_input_behavior.throw_requested.connect(throw_brick) + func _input(event: InputEvent) -> void: - if event.is_action_pressed("attack") and can_throw and charge_throw_component: - charge_throw_component.start_charging() + if throw_input_behavior: + throw_input_behavior.process_input(event) - if event.is_action_released("attack") and can_throw and charge_throw_component: - var power_multiplier: float = charge_throw_component.stop_charging() - throw_brick(power_multiplier) + +func _process(delta: float) -> void: + if throw_input_behavior: + throw_input_behavior.update(delta) func setup_timer() -> void: @@ -36,18 +40,17 @@ func on_timer_timeout() -> void: func throw_brick(power_multiplier: float = 1.0) -> void: - var brick_instance: Node2D = brick_scene.instantiate() + var instance: Node2D = brick_scene.instantiate() + var init := instance.get_node_or_null("ProjectileInitComponent") as ProjectileInitComponent + if init: + init.initialize({ + "position": player_controller.global_position, + "rotation": player_controller.rotation, + "direction": player_controller.last_direction, + "power_multiplier": power_multiplier + }) - var launch_component := brick_instance.get_node_or_null("LaunchComponent") as LaunchComponent - var chargable_component := brick_instance.get_node_or_null("ChargableComponent") as ChargableComponent - if launch_component: - launch_component.initial_direction = player_controller.last_direction - launch_component.spawn_position = player_controller.global_position - launch_component.spawn_rotation = player_controller.rotation - launch_component.speed *= power_multiplier if chargable_component else 1.0 - - brick_instance.global_position = player_controller.global_position - get_tree().current_scene.add_child(brick_instance) + get_tree().current_scene.add_child(instance) can_throw = false - timer.start() + timer.start() \ No newline at end of file diff --git a/scripts/components/chargable_component.gd b/scripts/components/chargable_component.gd deleted file mode 100644 index 97858f1..0000000 --- a/scripts/components/chargable_component.gd +++ /dev/null @@ -1,2 +0,0 @@ -class_name ChargableComponent -extends Node \ No newline at end of file diff --git a/scripts/components/chargable_component.gd.uid b/scripts/components/chargable_component.gd.uid deleted file mode 100644 index 7e6aa7c..0000000 --- a/scripts/components/chargable_component.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://ciowd622nk0i7 diff --git a/scripts/components/projectile_init_component.gd b/scripts/components/projectile_init_component.gd new file mode 100644 index 0000000..ed1a6e5 --- /dev/null +++ b/scripts/components/projectile_init_component.gd @@ -0,0 +1,20 @@ +class_name ProjectileInitComponent +extends Node + +@export var launch_component: LaunchComponent + + +func initialize(params: Dictionary) -> void: + var position := params.get("position", Vector2.ZERO) as Vector2 + var direction := params.get("direction", Vector2.RIGHT) as Vector2 + var rotation := params.get("rotation", 0.0) as float + var power := params.get("power_multiplier", 1.0) as float + + owner.global_position = position + owner.global_rotation = rotation + + if launch_component: + launch_component.initial_direction = direction + launch_component.spawn_position = position + launch_component.spawn_rotation = rotation + launch_component.speed *= power \ No newline at end of file diff --git a/scripts/components/projectile_init_component.gd.uid b/scripts/components/projectile_init_component.gd.uid new file mode 100644 index 0000000..7a31218 --- /dev/null +++ b/scripts/components/projectile_init_component.gd.uid @@ -0,0 +1 @@ +uid://bgty7040ams6s diff --git a/scripts/resources/charge_throw_input_resource.gd b/scripts/resources/charge_throw_input_resource.gd new file mode 100644 index 0000000..56b8f19 --- /dev/null +++ b/scripts/resources/charge_throw_input_resource.gd @@ -0,0 +1,56 @@ +class_name ChargeThrowInputResource +extends ThrowInputResource + +@export var min_power := 0.5 +@export var max_power := 2.0 +@export var max_charge_time := 1.5 +@export var min_charge_duration := 0.1 + +var is_charging := false +var charge_start_time := 0.0 +signal charge_started +signal charge_updated(charge_ratio: float) +signal charge_stopped + + +func process_input(event: InputEvent) -> void: + if event.is_action_pressed("attack"): + is_charging = true + charge_start_time = Time.get_ticks_msec() / 1000.0 + emit_signal("charge_started") + + if event.is_action_released("attack") and is_charging: + var power := _calculate_power() + is_charging = false + emit_signal("throw_requested", power) + emit_signal("charge_stopped") + + +func _calculate_power() -> float: + var now := Time.get_ticks_msec() / 1000.0 + var held_time := now - charge_start_time + if held_time < min_charge_duration: + return min_power + var t = clamp(held_time / max_charge_time, 0.0, 1.0) + return lerp(min_power, max_power, t) + + +func get_charge_ratio() -> float: + if not is_charging: + return min_power + var now := Time.get_ticks_msec() / 1000.0 + var held := now - charge_start_time + var t = clamp(held / max_charge_time, 0.0, 1.0) + return lerp(min_power, max_power, t) + + +func update(_delta: float) -> void: + if not is_charging: + return + + var t = clamp(get_charge_ratio(), min_power, max_power) + emit_signal("charge_updated", t) + + +func supports_charging() -> bool: + return true \ No newline at end of file diff --git a/scripts/resources/charge_throw_input_resource.gd.uid b/scripts/resources/charge_throw_input_resource.gd.uid new file mode 100644 index 0000000..33a3196 --- /dev/null +++ b/scripts/resources/charge_throw_input_resource.gd.uid @@ -0,0 +1 @@ +uid://dl1kpll33o6mv diff --git a/scripts/resources/tap_throw_input_resource.gd b/scripts/resources/tap_throw_input_resource.gd new file mode 100644 index 0000000..188e8f9 --- /dev/null +++ b/scripts/resources/tap_throw_input_resource.gd @@ -0,0 +1,6 @@ +class_name TapThrowInputResource +extends ThrowInputResource + +func process_input(event: InputEvent) -> void: + if event.is_action_pressed("attack"): + throw_requested.emit(1.0) \ No newline at end of file diff --git a/scripts/resources/tap_throw_input_resource.gd.uid b/scripts/resources/tap_throw_input_resource.gd.uid new file mode 100644 index 0000000..5c761b5 --- /dev/null +++ b/scripts/resources/tap_throw_input_resource.gd.uid @@ -0,0 +1 @@ +uid://blvdnsyi287rf diff --git a/scripts/resources/throw_input_resource.gd b/scripts/resources/throw_input_resource.gd new file mode 100644 index 0000000..4a6d4f8 --- /dev/null +++ b/scripts/resources/throw_input_resource.gd @@ -0,0 +1,16 @@ +class_name ThrowInputResource +extends Resource + +signal throw_requested(power_multiplier: float) + + +func process_input(event: InputEvent) -> void: + pass + + +func update(delta: float) -> void: + pass + + +func supports_charging() -> bool: + return false \ No newline at end of file diff --git a/scripts/resources/throw_input_resource.gd.uid b/scripts/resources/throw_input_resource.gd.uid new file mode 100644 index 0000000..9a36b83 --- /dev/null +++ b/scripts/resources/throw_input_resource.gd.uid @@ -0,0 +1 @@ +uid://cry02xehijy2v diff --git a/scripts/skill_manager.gd b/scripts/skill_manager.gd index bad0083..6933d7b 100644 --- a/scripts/skill_manager.gd +++ b/scripts/skill_manager.gd @@ -32,7 +32,7 @@ func add_skill(skill_data: SkillData) -> void: skill_instance[key] = value - add_child(skill_instance) + owner.add_child(skill_instance) active_components[skill_data.name] = skill_instance diff --git a/scripts/ui/charge_progress_bar.gd b/scripts/ui/charge_progress_bar.gd index e16efbb..20e6da8 100644 --- a/scripts/ui/charge_progress_bar.gd +++ b/scripts/ui/charge_progress_bar.gd @@ -1,22 +1,18 @@ extends Node @export var progress_bar: ProgressBar -@export var charge_throw_component: ChargeThrowComponent +@export var brick_throw_component: BrickThrowComponent + +var throw_input: ChargeThrowInputResource func _ready() -> void: - if not charge_throw_component: - return + owner.child_entered_tree.connect(on_nodes_changed) - if not progress_bar: - return + if progress_bar: + progress_bar.hide() - setup_progress_bar() - progress_bar.hide() - - charge_throw_component.charge_started.connect(on_charge_started) - charge_throw_component.charge_updated.connect(on_charge_updated) - charge_throw_component.charge_stopped.connect(on_charge_stopped) + setup_dependencies() func on_charge_updated(charge_ratio: float) -> void: @@ -45,8 +41,41 @@ func setup_progress_bar() -> void: if not progress_bar: return - progress_bar.min_value = charge_throw_component.min_power - progress_bar.max_value = charge_throw_component.max_power - progress_bar.value = charge_throw_component.min_power + progress_bar.min_value = throw_input.min_power + progress_bar.max_value = throw_input.max_power + progress_bar.value = throw_input.min_power progress_bar.step = 0.01 - progress_bar.show() \ No newline at end of file + progress_bar.hide() + + +func setup_dependencies() -> void: + if not brick_throw_component: + return + + if brick_throw_component.throw_input_behavior is ChargeThrowInputResource: + throw_input = brick_throw_component.throw_input_behavior as ChargeThrowInputResource + else: + throw_input = null + + if not throw_input: + return + + if not progress_bar: + return + + if not throw_input.supports_charging(): + progress_bar.hide() + return + + setup_progress_bar() + + throw_input.charge_started.connect(on_charge_started) + throw_input.charge_updated.connect(on_charge_updated) + throw_input.charge_stopped.connect(on_charge_stopped) + + +func on_nodes_changed(node: Node) -> void: + if node is BrickThrowComponent and brick_throw_component == null: + brick_throw_component = node as BrickThrowComponent + setup_dependencies() + return \ No newline at end of file