super_space_game/scripts/laser.gd

34 lines
670 B
GDScript3
Raw Permalink Normal View History

2025-12-02 17:57:09 +00:00
extends RigidBody2D
2025-12-02 18:40:18 +00:00
var creator = null
2025-12-02 17:57:09 +00:00
var lifetime = 0
var has_collided = false
2025-12-02 19:01:24 +00:00
func _ready() -> void:
if creator.get_name() == "Player":
$Hitbox/Small.free()
else:
$Hitbox/Large.free()
2025-12-02 17:57:09 +00:00
func _process(delta: float) -> void:
if has_collided: return
2025-12-02 18:40:18 +00:00
linear_velocity = transform.y * -1 * 2048
2025-12-02 17:57:09 +00:00
func _on_hitbox_body_shape_entered(body_rid: RID, body: Node2D, body_shape_index: int, local_shape_index: int) -> void:
2025-12-02 18:40:18 +00:00
if body != creator:
2025-12-02 17:57:09 +00:00
has_collided = true
linear_velocity = Vector2()
$Sprite.visible = false
$Trail.visible = false
if "health" in body:
2025-12-02 19:01:24 +00:00
body.health -= 75
2025-12-02 17:57:09 +00:00
await get_tree().create_timer(1.0).timeout
queue_free()