Finished with the bunny. As far as I know there are no bugs with it.

This commit is contained in:
2026-06-21 19:22:36 -06:00
parent 2b7f22f4ce
commit 847cafe8d7
4 changed files with 120 additions and 13 deletions
+24 -2
View File
@@ -4,18 +4,26 @@ extends Node2D
@onready var wait_timer: Timer = $WaitTimer
@onready var collision_shape_2d: CollisionShape2D = $Area2D/CollisionShape2D
@onready var death_collision_box: CollisionShape2D = $DeathBox/DeathCollisionBox
@onready var hit_box_wait: Timer = $HitBoxWait
@onready var animation_timer: Timer = $AnimationTimer
@onready var death_sound: AudioStreamPlayer2D = $DeathSound
var direction :float = 1.0
const SPEED = 150
signal player_died
var wait :bool = false
var alive :bool = true
func _process(delta: float) -> void:
if !alive:
return
if !wait:
position.x += direction * SPEED * delta
func _on_area_2d_body_entered(body: Node2D) -> void:
if !alive:
return
if body.name == "player":
emit_signal("player_died", body)
else:
@@ -24,11 +32,14 @@ func _on_area_2d_body_entered(body: Node2D) -> void:
animated_sprite_2d.animation = "idle"
animated_sprite_2d.flip_h = !animated_sprite_2d.flip_h
wait_timer.start()
print(body)
func _on_wait_timer_timeout() -> void:
if !alive:
return
animated_sprite_2d.animation = "run"
_death_box_disabled()
hit_box_wait.start()
wait = false
direction *= -1
@@ -41,4 +52,15 @@ func _death_box_disabled() -> void:
death_collision_box.set_deferred("disabled", true)
func _on_death_box_body_entered(body: Node2D) -> void:
print("Dead")
if body.name == "player":
alive = false
animated_sprite_2d.animation = "die"
death_sound.play()
animation_timer.start()
func _on_hit_box_wait_timeout() -> void:
_death_box_disabled()
func _on_animation_timer_timeout() -> void:
queue_free()