Rewriting ships: Added some player interface and started rewriting star system

This commit is contained in:
2ndbeam 2024-04-30 16:22:55 +03:00
commit 4172b336c1
20 changed files with 300 additions and 139 deletions

View file

@ -2,8 +2,6 @@ extends Node2D
class_name Ship
# TODO: add weapons
## Emits when hull hp reaches zero.
signal destroyed
@ -15,24 +13,28 @@ signal destroyed
@onready var shield: Shield = $Shield
## Reference to weapons node
@onready var weapons: Node2D = $Weapons
## Node beginning position
@onready var spawn_position: Vector2 = global_position
## Faction which this ship belongs to
var faction : Game.Faction = Game.Faction.Player
func _ready() -> void:
hull.global_position += global_position
hull.global_position = global_position
destroyed.connect(destroy)
## Reset all required variables
func destroy() -> void:
hull.hp = hull.max_hp
hull.global_position = spawn_position
shield.capacity = shield.max_capacity
## Swaps old hull with the new one
func change_hull(new_hull_id: String) -> void:
var hull_holder: Node = hull.get_parent()
var new_hull: Hull = Game.get_module(new_hull_id, 'hull').instantiate()
var old_hull: Hull = hull
add_child(new_hull)
hull_holder.add_child(new_hull)
hull = new_hull
hull.hp = old_hull.hp
get_tree().create_timer(0.05).timeout.connect(old_hull.queue_free)