Refactor charge throw component; add minimum charge duration and improve charge handling
This commit is contained in:
@@ -80,7 +80,7 @@ health_component = NodePath("../HealthComponent")
|
||||
|
||||
[node name="Hitbox" type="Area2D" parent="."]
|
||||
collision_layer = 8
|
||||
collision_mask = 20
|
||||
collision_mask = 4
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
|
||||
position = Vector2(-2, 0.5)
|
||||
|
@@ -1,10 +1,9 @@
|
||||
[gd_scene load_steps=13 format=3 uid="uid://5surx230gfw3"]
|
||||
[gd_scene load_steps=12 format=3 uid="uid://5surx230gfw3"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_rcgxf"]
|
||||
[ext_resource type="Script" uid="uid://dkmxhjtmu5xlb" path="res://scripts/components/damage_component.gd" id="3_y0uai"]
|
||||
[ext_resource type="Script" uid="uid://beg4dk7d5pvhp" path="res://scripts/components/explosive_component.gd" id="4_8lw0n"]
|
||||
[ext_resource type="PackedScene" uid="uid://dyp4i4ru2j2jh" path="res://objects/fxs/explosion_fx.tscn" id="5_6oopj"]
|
||||
[ext_resource type="Script" uid="uid://1tnr46o1ib4u" path="res://scripts/components/out_of_screen_component.gd" id="6_5jrjx"]
|
||||
[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"]
|
||||
@@ -63,14 +62,10 @@ debug_color = Color(0.919034, 6.36289e-05, 0.69998, 0.42)
|
||||
[node name="ExplosionFX" parent="." instance=ExtResource("5_6oopj")]
|
||||
randomness = 0.24
|
||||
|
||||
[node name="OutOfScreenComponent" type="Node" parent="." node_paths=PackedStringArray("visibility_notifier", "root")]
|
||||
script = ExtResource("6_5jrjx")
|
||||
visibility_notifier = NodePath("../VisibleOnScreenNotifier2D")
|
||||
root = NodePath("..")
|
||||
|
||||
[node name="LifetimeComponent" type="Node" parent="." node_paths=PackedStringArray("root", "timer")]
|
||||
script = ExtResource("7_nqeob")
|
||||
root = NodePath("..")
|
||||
life_time = 30.0
|
||||
timer = NodePath("../Timer")
|
||||
|
||||
[node name="LaunchComponent" type="Node2D" parent="." node_paths=PackedStringArray("root")]
|
||||
|
@@ -21,7 +21,6 @@ func _input(event: InputEvent) -> void:
|
||||
|
||||
if event.is_action_released("attack") and can_throw and charge_throw_component:
|
||||
var power_multiplier: float = charge_throw_component.stop_charging()
|
||||
print("Power Multiplier: ", power_multiplier)
|
||||
throw_brick(power_multiplier)
|
||||
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
class_name ChargeThrowComponent
|
||||
extends Node
|
||||
|
||||
@export var min_charge_duration: float = 0.1
|
||||
@export var min_power: float = 0.5
|
||||
@export var max_power: float = 2.0
|
||||
@export var max_charge_time: float = 1.5
|
||||
@@ -23,7 +24,7 @@ func _process(_delta: float) -> void:
|
||||
func start_charging() -> void:
|
||||
is_charging = true
|
||||
charge_start_time = Time.get_ticks_msec() / 1000.0
|
||||
charge_started.emit()
|
||||
call_deferred("emit_charge_started")
|
||||
|
||||
|
||||
func get_charge_ratio() -> float:
|
||||
@@ -37,9 +38,22 @@ func get_charge_ratio() -> float:
|
||||
|
||||
|
||||
func stop_charging() -> float:
|
||||
is_charging = false
|
||||
if not is_charging:
|
||||
return min_power
|
||||
|
||||
var held_time := (Time.get_ticks_msec() / 1000.0) - charge_start_time
|
||||
var t = clamp(held_time / max_charge_time, 0.0, 1.0)
|
||||
is_charging = false
|
||||
charge_start_time = 0.0
|
||||
charge_stopped.emit()
|
||||
|
||||
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 emit_charge_started() -> void:
|
||||
if not is_charging:
|
||||
return
|
||||
charge_started.emit()
|
Reference in New Issue
Block a user