Skip to content

Commit

Permalink
Untarget ship when destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
jspahrsummers committed Jun 25, 2024
1 parent 0e5a075 commit aa50a96
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions ships/ship.gd
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func damage(dmg: Dictionary) -> void:
CombatSystem.notify_ship_hull_changed(self)

if self.hull < CombatSystem.MIN_HULL_VALUE:
CombatSystem.notify_ship_destroyed(self)
self.queue_free()

func fire() -> void:
Expand Down
7 changes: 7 additions & 0 deletions systems/combat_system.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var targeted_ship: Ship = null

signal ship_hull_changed(ship: Ship)
signal ship_shield_changed(ship: Ship)
signal ship_destroyed(ship: Ship)
signal targeted_ship_changed()

const MIN_SHIELD_VALUE = 0.001
Expand All @@ -21,6 +22,12 @@ func notify_ship_hull_changed(ship: Ship) -> void:
func notify_ship_shield_changed(ship: Ship) -> void:
self.emit_signal("ship_shield_changed", ship)

func notify_ship_destroyed(ship: Ship) -> void:
if ship == self.targeted_ship:
self.set_targeted_ship(null)

self.emit_signal("ship_destroyed", ship)

func set_targeted_ship(ship: Ship) -> void:
if ship == self.targeted_ship:
return
Expand Down

0 comments on commit aa50a96

Please sign in to comment.