Fix brick throwing, add enemy death

This commit is contained in:
2025-01-05 06:41:53 +01:00
parent 5b558f9c3b
commit 697a9b7deb
44 changed files with 1061 additions and 7 deletions

View File

@@ -32,7 +32,7 @@ func throw_brick() -> void:
var brick_instance: Node2D = brick_scene.instantiate()
var brick: BulletComponent = brick_instance.get_node("BulletComponent")
brick_instance.position = player_controller.position
brick.direction = Vector2.RIGHT if player_controller.velocity.x >= 0.0 else Vector2.LEFT
brick.direction = player_controller.last_direction
get_tree().current_scene.add_child(brick_instance)
can_throw = false

View File

@@ -14,6 +14,7 @@ func _ready() -> void:
root = get_parent()
visibility_notifier.screen_exited.connect(_on_screen_exited)
area2d.body_entered.connect(on_area2d_body_entered)
area2d.area_entered.connect(on_area2d_area_entered)
timer.wait_time = life_time
timer.timeout.connect(on_timer_timeout)
@@ -31,5 +32,9 @@ func on_area2d_body_entered(_body: Node2D) -> void:
root.queue_free()
func on_area2d_area_entered(_area: Area2D) -> void:
root.queue_free()
func on_timer_timeout() -> void:
root.queue_free()

View File

@@ -0,0 +1,28 @@
class_name EnemyDeathComponent
extends Node
@export var root: Node2D
@export var tween_duration: float = 0.5
@export var collision_shape_2d: CollisionShape2D
@export var health_component: HealthComponent
func _ready() -> void:
if not collision_shape_2d:
printerr("No CollisionShape2D assigned!")
return
if not health_component:
printerr("No HealthComponent assigned!")
return
health_component.on_death.connect(_on_health_component_on_death)
func _on_health_component_on_death() -> void:
call_deferred("die")
func die() -> void:
collision_shape_2d.disabled = true
var tween := create_tween()
tween.tween_property(root, "scale", Vector2(0, 0), tween_duration)
await (tween.finished)
root.queue_free()

View File

@@ -6,7 +6,7 @@ extends Node2D
@export var player_controller: PlayerController
func _process(_delta: float) -> void:
var velocity = player_controller.velocity
var velocity := player_controller.last_direction
if velocity.x < 0:
eye_left.frame = 1
eye_right.frame = 1