fuzzyworld

godot-shooter / meteor / files / Bullet.gd

Branch meteor · default branch · all branches

Bullet.gd

Blame: the commit that last changed each line · file · history

b856550a 2023-10-30 Pavel Safronov1extends Area2D
f398dcb9 2023-11-02 Pavel Safronov2class_name Bullet
b856550a 2023-10-30 Pavel Safronov3
236d1677 2023-11-01 Pavel Safronov4const Utils = preload("res://Utils.gd")
5const SmallExplosion = preload("res://SmallExplosion.tscn")
f398dcb9 2023-11-02 Pavel Safronov6export var lifetime_seconds = .75
c727f3b0 2023-10-31 Pavel Safronov7export var speed = 300
614e7fb1 2023-10-31 Pavel Safronov8
9func _ready() -> void:
10 $Timer.wait_time = lifetime_seconds
11 $Timer.start()
b856550a 2023-10-30 Pavel Safronov12
13func _physics_process(delta: float) -> void:
14 position += transform.y * speed * delta
614e7fb1 2023-10-31 Pavel Safronov15
16func on_expiration():
17 queue_free()
b856550a 2023-10-30 Pavel Safronov18
19func on_bullet_body_entered(body):
20 var tree = get_tree()
21 var players = tree.get_nodes_in_group("player")
22 var player = players[0]
23 if body.has_method("hurt") && body != player:
24 body.hurt()
236d1677 2023-11-01 Pavel Safronov25 var se = SmallExplosion.instance()
26 get_parent().add_child(se)
27 se.transform = transform
b856550a 2023-10-30 Pavel Safronov28 queue_free()