Player health UI is bound to singleton
This commit is contained in:
1 parent
c8acaf0988
commit
a773e5900d
6 files changed
+65
-6
No files matched your search
+10
-2
@@ -7,6 +7,7 @@ var player_count: int
|
||||
|
||||
signal player_win(player_id)
|
||||
signal player_count_updated(new_player_count)
|
||||
signal player_health_updated(player_id, new_player_health)
|
||||
|
||||
|
||||
func set_player_count(new_player_count: int):
|
||||
@@ -16,16 +17,23 @@ func set_player_count(new_player_count: int):
|
||||
player_healths = []
|
||||
|
||||
for i in range(0, player_count):
|
||||
player_healths.append(max_health)
|
||||
player_healths.append(0.0)
|
||||
set_player_health(i, max_health)
|
||||
|
||||
emit_signal("player_count_updated", new_player_count)
|
||||
|
||||
|
||||
func subtract_player_health(player_id, subtractor):
|
||||
set_player_health(player_id, player_healths[player_id] - subtractor)
|
||||
|
||||
|
||||
func set_player_health(player_id, new_value):
|
||||
assert(player_id < player_count)
|
||||
assert(player_id >= 0)
|
||||
|
||||
player_healths[player_id] -= subtractor
|
||||
player_healths[player_id] = new_value
|
||||
|
||||
if player_healths[player_id] < 0.0:
|
||||
emit_signal("player_win", player_id)
|
||||
else:
|
||||
emit_signal("player_health_updated", player_id, player_healths[player_id])
|
||||
Reference in new issue
Block a user