2025-10-07 00:57:11 +00:00
|
|
|
class_name Grenade
|
|
|
|
|
extends RigidBody2D
|
|
|
|
|
|
|
|
|
|
var timer = Timer.new()
|
|
|
|
|
|
2025-10-25 01:57:19 +00:00
|
|
|
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
|
|
|
|
|
@onready var sprite_2d: Sprite2D = $Sprite2D
|
|
|
|
|
|
2025-10-07 00:57:11 +00:00
|
|
|
func _ready() -> void:
|
|
|
|
|
add_child(timer)
|
|
|
|
|
timer.wait_time = 2.0
|
|
|
|
|
timer.one_shot = true
|
|
|
|
|
timer.connect("timeout", explode)
|
|
|
|
|
timer.start()
|
|
|
|
|
|
|
|
|
|
func explode() -> void:
|
|
|
|
|
print("kaboom!")
|
2025-10-25 01:57:19 +00:00
|
|
|
sprite_2d.visible = false
|
|
|
|
|
animated_sprite_2d.play("explode")
|
|
|
|
|
await animated_sprite_2d.animation_finished
|
2025-10-07 00:57:11 +00:00
|
|
|
self.queue_free()
|
|
|
|
|
|
|
|
|
|
func _on_body_entered(body: Node) -> void:
|
|
|
|
|
print("grenade hit something")
|
|
|
|
|
if body.is_in_group("explodable"):
|
|
|
|
|
body.queue_free()
|
|
|
|
|
explode()
|