fuzzyworld

godot-shooter / files / weapons / Bullet.gd

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
16938031 2023-11-17 Pavel Safronov4const Utils = preload("res://utils/Utils.gd")
5const SmallExplosion = preload("res://effects/SmallExplosion.tscn")
ee6296b3 2023-11-17 Pavel Safronov6const Constants = preload("res://utils/Constants.gd")
7
969fd5af 2023-11-06 Pavel Safronov8export var lifetime_seconds = 1.5
ee6296b3 2023-11-17 Pavel Safronov9export var speed = Constants.SPEED * 5
3fcb817e 2023-11-10 Pavel Safronov10export var damage_amount = 1
636e5224 2023-12-01 Pavel Safronov11export var shooter_rid = 0
614e7fb1 2023-10-31 Pavel Safronov12
13func _ready() -> void:
14 $Timer.wait_time = lifetime_seconds
15 $Timer.start()
b856550a 2023-10-30 Pavel Safronov16
17func _physics_process(delta: float) -> void:
18 position += transform.y * speed * delta
614e7fb1 2023-10-31 Pavel Safronov19
20func on_expiration():
21 queue_free()
b856550a 2023-10-30 Pavel Safronov22
23func on_bullet_body_entered(body):
636e5224 2023-12-01 Pavel Safronov24 var body_id = (body as Node2D).get_instance_id()
25 var body_is_shooter = shooter_rid != 0 and shooter_rid == body_id
26 if body_is_shooter:
0f8974b8 2023-12-01 Pavel Safronov27 return
28 if body.has_method("hurt"):
3fcb817e 2023-11-10 Pavel Safronov29 body.hurt(damage_amount)
236d1677 2023-11-01 Pavel Safronov30 var se = SmallExplosion.instance()
31 get_parent().add_child(se)
32 se.transform = transform
b856550a 2023-10-30 Pavel Safronov33 queue_free()