* Replace `valid_end` with `is_foul` for invalid ball sinks * Rename and centralize ball state tracking * Add ball finalization and win-condition hooks * Update turn switching to retain the player after valid sinks * Apply negative points to reaped balls * Add active-player indicator to the camera UI * Emit active-player updates when the turn changes
80 lines
2.3 KiB
GDScript
80 lines
2.3 KiB
GDScript
class_name BaseMode extends Node
|
|
# NOTE: The ball's queue_free is called higher up and after game mode handles
|
|
# the ball. Never call it in a given game mode. A game mode should handle
|
|
# these signals to handle game related rules regarding ball sinks.
|
|
|
|
|
|
var turn_count: int = 1
|
|
var player_1_points: int = 0
|
|
var player_2_points: int = 0
|
|
|
|
# NOTE: Kinda a super tracker of balls. Not all entries
|
|
# generated are used depending on the game type.
|
|
var ball_states: Dictionary = {}
|
|
|
|
# NOTE: Used to track handoff logic and is cleared after eah switch accordingly.
|
|
var balls_sunk: Array = []
|
|
var balls_reaped: Array = []
|
|
|
|
# NOTE: Kinda a super tracker of the state of a ball.
|
|
# Not all entries are used depending on the game type.
|
|
var BALL_STATE: Dictionary = {
|
|
"turn": 0,
|
|
"player": "",
|
|
"sunk": false,
|
|
"reaped": false,
|
|
"is_foul": false,
|
|
"points": 0,
|
|
}
|
|
|
|
|
|
func _init() -> void:
|
|
pass
|
|
|
|
func generate_ball_states() -> Dictionary:
|
|
var state := {}
|
|
|
|
for i: int in range(1, 16):
|
|
var ball_name = "%02d_ball" % i
|
|
state[ball_name] = BALL_STATE.duplicate_deep()
|
|
state[ball_name]["points"] = i
|
|
|
|
return state
|
|
|
|
func ball_states_finalized() -> bool:
|
|
for ball_state in ball_states.values():
|
|
if ball_state["reaped"] or ball_state["sunk"]:
|
|
continue
|
|
|
|
return false
|
|
|
|
return true
|
|
|
|
func process_win_condition() -> void:
|
|
assert(false, "This method needs to be overridden...")
|
|
|
|
func get_player() -> String:
|
|
return \
|
|
"Player 1" \
|
|
if \
|
|
Globals.game_data.client1 == Globals.multiplayer_data.current_turn_player_id \
|
|
else \
|
|
"Player 2"
|
|
|
|
func reap_ball(ball: Node3D) -> void:
|
|
balls_reaped.append(ball.name)
|
|
|
|
ball_states[ball.name]["turn"] = turn_count
|
|
ball_states[ball.name]["player"] = get_player()
|
|
ball_states[ball.name]["reaped"] = true
|
|
|
|
func process_ball(ball: Node3D) -> void:
|
|
balls_sunk.append(ball.name)
|
|
|
|
ball_states[ball.name]["turn"] = turn_count
|
|
ball_states[ball.name]["player"] = get_player()
|
|
ball_states[ball.name]["sunk"] = true
|
|
|
|
func handle_switch_user() -> void:
|
|
assert(false, "This method needs to be overridden...")
|