32 lines
657 B
GDScript
32 lines
657 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)
|
|
|
|
|
|
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(max_health)
|
|
|
|
emit_signal("player_count_updated", new_player_count)
|
|
|
|
|
|
func subtract_player_health(player_id, subtractor):
|
|
assert(player_id < player_count)
|
|
assert(player_id >= 0)
|
|
|
|
player_healths[player_id] -= subtractor
|
|
|
|
if player_healths[player_id] < 0.0:
|
|
emit_signal("player_win", player_id)
|