17func configure(player_ids:Array = [
"left",
"right"], score_to_win:int = 5) -> void:
21 var player_id = str(id)
22 players.append(player_id)
24 target_score = max(1, score_to_win)
33 if players.is_empty():
45func tick(delta:float) -> void:
47 elapsed += max(0.0, delta)
51func add_score(player_id:String, amount:int = 1) -> bool:
52 if not scores.has(player_id):
54 scores[player_id] =
int(scores[player_id]) + amount
55 if int(scores[player_id]) >= target_score:
63func next_round() -> void:
69func get_score(player_id:String) -> int:
70 return int(scores.get(player_id, 0))
74func get_state() -> Dictionary:
76 "players": players.duplicate(true),
77 "scores": scores.duplicate(true),
78 "target_score": target_score,
87func apply_state(state:Dictionary) -> void:
88 players = state.get(
"players", []).duplicate(true)
89 scores = state.get(
"scores", {}).duplicate(true)
90 target_score =
int(state.get(
"target_score", 5))
91 round =
int(state.get(
"round", 1))
92 elapsed = float(state.get(
"elapsed", 0.0))
93 active = bool(state.get(
"active", false))
94 winner = str(state.get(
"winner",
""))
int
Award points and return true if the match is now complete.