1
0
Fork 0
space-capture/scenes/ships_fleet/ships_fleet.gd

38 lines
701 B
GDScript3
Raw Normal View History

2024-08-06 22:46:05 +02:00
extends Node2D
2024-08-15 11:18:54 +02:00
class_name ShipFleet
2024-08-06 22:46:05 +02:00
2024-08-15 11:18:54 +02:00
@export var departed_at: int
2024-08-06 22:46:05 +02:00
2024-08-15 11:18:54 +02:00
@export var arrives_at: int
@export var from: Vector2
@export var to: Vector2
2024-08-06 22:46:05 +02:00
@export var count: int :
set(value):
count = value
2024-08-15 11:18:54 +02:00
_update_instances_count()
#region Graphics
var instances: Array[Node2D] = []
@export var ship_template: PackedScene
func _update_instances_count() -> void :
var diff = count - instances.size()
2024-08-06 22:46:05 +02:00
2024-08-15 11:18:54 +02:00
for i in range(diff):
var j = float(1 + instances.size())
var ship := ship_template.instantiate()
add_child(ship)
ship.position = Vector2.from_angle(j) * j * 2.
instances.push_back(ship)
2024-08-06 22:46:05 +02:00
2024-08-15 11:18:54 +02:00
for i in range(-diff):
var ship: Node2D = instances.pop_back()
remove_child(ship)
2024-08-06 22:46:05 +02:00
2024-08-15 11:18:54 +02:00
#endregion