40 lines
944 B
GDScript
40 lines
944 B
GDScript
extends Node
|
|
|
|
|
|
var max_health = 100.0
|
|
var player_healths = []
|
|
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):
|
|
assert(new_player_count <= 4)
|
|
|
|
player_count = new_player_count
|
|
player_healths = []
|
|
|
|
for i in range(0, player_count):
|
|
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] = 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])
|