Add charge throw mechanics; refactor bullet and brick components

This commit is contained in:
2025-05-12 23:08:54 +02:00
parent b09bee9fb6
commit 59c309409c
34 changed files with 422 additions and 96 deletions

View File

@@ -5,35 +5,50 @@ extends Node
@export var fire_rate: float = 1.0
@export var player_controller: PlayerController
@export var timer: Timer
@export var charge_throw_component: ChargeThrowComponent
var can_throw: bool = true
func _ready() -> void:
setup_timer()
can_throw = true
func _input(event: InputEvent) -> void:
if event.is_action_pressed("attack") and can_throw:
throw_brick()
if event.is_action_pressed("attack") and can_throw and charge_throw_component:
charge_throw_component.start_charging()
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)
func setup_timer() -> void:
timer.wait_time = fire_rate
timer.one_shot = false
timer.autostart = false
timer.timeout.connect(on_timer_timeout)
func on_timer_timeout() -> void:
can_throw = true
func throw_brick() -> void:
func throw_brick(power_multiplier: float = 1.0) -> void:
var brick_instance: Node2D = brick_scene.instantiate()
var brick: BulletComponent = brick_instance.get_node("BulletComponent")
brick_instance.position = player_controller.position
brick.direction = player_controller.last_direction
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)
can_throw = false
timer.start()