feat: Introduce core game managers and main scene, implementing player UI for board, actions, and power-ups.
This commit is contained in:
@@ -4,8 +4,8 @@ extends Node
|
||||
# Also handles global match timer that ends the game
|
||||
|
||||
const CYCLE_DURATION: float = 30.0
|
||||
const BASE_SCORE: int = 100
|
||||
const TIME_BONUS_MULTIPLIER: float = 2.0
|
||||
const BASE_SCORE: int = 1000
|
||||
const TIME_BONUS_MULTIPLIER: float = 0.0 # User implied flat 1000, setting bonus to 0 effectively or I can just ignore it in calc.
|
||||
|
||||
# Cycle timer state (30-second cycles)
|
||||
var current_cycle_timer: float = 0.0
|
||||
@@ -18,6 +18,7 @@ var is_match_active: bool = false
|
||||
|
||||
# Score tracking: peer_id -> score
|
||||
var player_scores: Dictionary = {}
|
||||
var player_goal_counts: Dictionary = {} # peer_id -> count
|
||||
|
||||
# Reference to main scene
|
||||
var main_scene: Node = null
|
||||
@@ -26,6 +27,7 @@ signal cycle_started()
|
||||
signal cycle_ended()
|
||||
signal timer_updated(time_remaining: float)
|
||||
signal score_updated(peer_id: int, new_score: int)
|
||||
signal goal_count_updated(peer_id: int, count: int)
|
||||
signal leaderboard_updated(sorted_scores: Array)
|
||||
|
||||
# Global match signals
|
||||
@@ -225,11 +227,18 @@ func on_goal_completed(player: Node, time_remaining: float):
|
||||
player_scores[peer_id] = 0
|
||||
player_scores[peer_id] += score_earned
|
||||
|
||||
# Update goal count
|
||||
if not player_goal_counts.has(peer_id):
|
||||
player_goal_counts[peer_id] = 0
|
||||
player_goal_counts[peer_id] += 1
|
||||
|
||||
emit_signal("score_updated", peer_id, player_scores[peer_id])
|
||||
emit_signal("goal_count_updated", peer_id, player_goal_counts[peer_id])
|
||||
_update_leaderboard()
|
||||
|
||||
# Sync score to all clients
|
||||
rpc("sync_player_score", peer_id, player_scores[peer_id])
|
||||
rpc("sync_goal_count", peer_id, player_goal_counts[peer_id])
|
||||
|
||||
# Clear playerboard tiles (they convert to powerup bar reward)
|
||||
player.playerboard.fill(-1)
|
||||
@@ -251,6 +260,38 @@ func sync_player_score(peer_id: int, total_score: int):
|
||||
emit_signal("score_updated", peer_id, total_score)
|
||||
_update_leaderboard()
|
||||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
func sync_goal_count(peer_id: int, count: int):
|
||||
player_goal_counts[peer_id] = count
|
||||
emit_signal("goal_count_updated", peer_id, count)
|
||||
|
||||
@rpc("any_peer", "call_local", "reliable")
|
||||
func request_add_score(amount: int):
|
||||
"""RPC for clients to request score addition (trusted)."""
|
||||
if not multiplayer.is_server():
|
||||
return
|
||||
|
||||
var sender_id = multiplayer.get_remote_sender_id()
|
||||
# If called locally by server, sender_id might be 0 or 1.
|
||||
if sender_id == 0: sender_id = 1
|
||||
|
||||
add_score(sender_id, amount)
|
||||
|
||||
func add_score(peer_id: int, amount: int):
|
||||
"""Add points to a specific player (Server only)."""
|
||||
if not multiplayer.is_server():
|
||||
return
|
||||
|
||||
if not player_scores.has(peer_id):
|
||||
player_scores[peer_id] = 0
|
||||
|
||||
player_scores[peer_id] += amount
|
||||
|
||||
# Sync
|
||||
rpc("sync_player_score", peer_id, player_scores[peer_id])
|
||||
print("[GoalsCycle] Added %d points to Player %d. Total: %d" % [amount, peer_id, player_scores[peer_id]])
|
||||
|
||||
|
||||
func _update_leaderboard():
|
||||
# Sort players by score (descending)
|
||||
var sorted_scores = []
|
||||
|
||||
Reference in New Issue
Block a user