extends Area2D # Mirrors Projectile.gd, but travels the other direction: fired by an enemy # component (see EnemyRangedWeaponComponent, #45) and damages player_ships. # This is the half of ranged combat that never existed before #44 - enemies # could previously only hurt the fleet by physical contact. @export var speed: float = 260.0 @export var lifetime: float = 3.0 @export var damage: int = 1 @export var bolt_length: float = 20.0 @export var color: Color = Color(1.0, 0.4, 0.35) var velocity: Vector2 = Vector2.ZERO var age: float = 0.0 func _ready() -> void: add_to_group("enemy_projectiles") area_entered.connect(_on_area_entered) queue_redraw() func launch(direction: Vector2) -> void: velocity = direction.normalized() * speed rotation = direction.angle() + PI / 2.0 func _physics_process(delta: float) -> void: position += velocity * delta age += delta if age >= lifetime: queue_free() func _on_area_entered(area: Area2D) -> void: if area.is_in_group("player_ships"): area.take_damage(damage) queue_free() return # #101: structures are targets too. The hitbox is a child Area2D of the # Building, which is a plain Node2D and could not be hit otherwise. if area.is_in_group("player_buildings"): area.take_damage(damage) queue_free() func _draw() -> void: var tip: Vector2 = Vector2(0, -bolt_length * 0.6) var tail: Vector2 = Vector2(0, bolt_length * 0.4) NeonDraw.draw_glowing_line(self, tail, tip, color, 1.0, 0.5)