godot-shooter / files / weapons / Rocket.gd
Rocket.gd
| 1 | extends Area2D |
| 2 | class_name Rocket |
| 3 | |
| 4 | const Utils = preload("res://utils/Utils.gd") |
| 5 | const SmallExplosion = preload("res://effects/SmallExplosion.tscn") |
| 6 | const Constants = preload("res://utils/Constants.gd") |
| 7 | |
| 8 | export var lifetime_seconds = 5 |
| 9 | export var speed = Constants.SPEED * 3 |
| 10 | export var arm_secs = 1 |
| 11 | export var damage_amount = 2 |
| 12 | export var shooter_rid = 0 |
| 13 | var is_dead = false |
| 14 | |
| 15 | func _ready() -> void: |
| 16 | pass |
| 17 | |
| 18 | func _physics_process(delta: float) -> void: |
| 19 | if !is_dead: |
| 20 | position += transform.y * speed * delta |
| 21 | |
| 22 | func 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 | |
| 35 | func _on_LifeTimer_timeout() -> void: |
| 36 | var se = SmallExplosion.instance() |
| 37 | get_parent().add_child(se) |
| 38 | se.transform = transform |
| 39 | queue_free() |