fuzzyworld

godot-shooter / asteroids / files / weapons / Rocket.gd

Branch asteroids · default branch · all branches

Rocket.gd

1.0 KB · history · blame

1extends Area2D
2class_name Rocket
3
4const Utils = preload("res://utils/Utils.gd")
5const SmallExplosion = preload("res://effects/SmallExplosion.tscn")
6const Constants = preload("res://utils/Constants.gd")
7
8export var lifetime_seconds = 5
9export var speed = Constants.SPEED * 3
10export var arm_secs = 1
11export var damage_amount = 2
12export var shooter_rid = 0
13var is_dead = false
14
15func _ready() -> void:
16 pass
17
18func _physics_process(delta: float) -> void:
19 if !is_dead:
20 position += transform.y * speed * delta
21
22func on_bullet_body_entered(body):
23 var body_id = (body as Node2D).get_instance_id()
24 var body_is_shooter = shooter_rid != 0 and shooter_rid == body_id
25 if body_is_shooter:
26 return
27 if body.has_method("hurt"):
28 body.hurt(damage_amount)
29 var se = SmallExplosion.instance()
30 get_parent().add_child(se)
31 se.transform = transform
32 self.is_dead = true
33 $AnimationPlayer.play("fade_out")
34
35func _on_LifeTimer_timeout() -> void:
36 var se = SmallExplosion.instance()
37 get_parent().add_child(se)
38 se.transform = transform
39 queue_free()