22 lines
408 B
GDScript3
22 lines
408 B
GDScript3
|
class_name Grenade
|
||
|
extends RigidBody2D
|
||
|
|
||
|
var timer = Timer.new()
|
||
|
|
||
|
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!")
|
||
|
self.queue_free()
|
||
|
|
||
|
func _on_body_entered(body: Node) -> void:
|
||
|
print("grenade hit something")
|
||
|
if body.is_in_group("explodable"):
|
||
|
body.queue_free()
|
||
|
explode()
|