feat(game): refactor ball state and turn handling
* 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
This commit is contained in:
@@ -4,34 +4,34 @@ class_name BaseMode extends Node
|
||||
# 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
|
||||
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_state: Dictionary = {}
|
||||
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 = []
|
||||
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,
|
||||
"valid_end": true,
|
||||
"points": 0,
|
||||
var BALL_STATE: Dictionary = {
|
||||
"turn": 0,
|
||||
"player": "",
|
||||
"sunk": false,
|
||||
"reaped": false,
|
||||
"is_foul": false,
|
||||
"points": 0,
|
||||
}
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
pass
|
||||
|
||||
func generate_ball_state() -> Dictionary:
|
||||
func generate_ball_states() -> Dictionary:
|
||||
var state := {}
|
||||
|
||||
for i: int in range(1, 16):
|
||||
@@ -41,8 +41,19 @@ func generate_ball_state() -> Dictionary:
|
||||
|
||||
return state
|
||||
|
||||
func ball_states_finalized() -> bool:
|
||||
for ball_state in ball_states.values():
|
||||
if ball_state["reaped"] or ball_state["sunk"]:
|
||||
continue
|
||||
|
||||
func which_player() -> String:
|
||||
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 \
|
||||
@@ -53,16 +64,16 @@ func which_player() -> String:
|
||||
func reap_ball(ball: Node3D) -> void:
|
||||
balls_reaped.append(ball.name)
|
||||
|
||||
ball_state[ball.name]["turn"] = turn_count
|
||||
ball_state[ball.name]["player"] = which_player()
|
||||
ball_state[ball.name]["reaped"] = not ball_state[ball.name]["reaped"]
|
||||
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_state[ball.name]["turn"] = turn_count
|
||||
ball_state[ball.name]["player"] = which_player()
|
||||
ball_state[ball.name]["sunk"] = not ball_state[ball.name]["sunk"]
|
||||
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...")
|
||||
|
||||
Reference in New Issue
Block a user