2021-11-18 15:00:15 +00:00
|
|
|
extends Control
|
2021-11-08 13:40:11 +00:00
|
|
|
|
2021-11-14 08:50:39 +00:00
|
|
|
var light_theme = load("res://light_theme.tres")
|
|
|
|
var dark_theme = load("res://dark_theme.tres")
|
|
|
|
|
2021-11-13 10:34:39 +00:00
|
|
|
|
2021-11-11 20:38:10 +00:00
|
|
|
# Path to Player class, for instantiating new Players in code
|
2021-11-23 04:04:21 +00:00
|
|
|
var Player = preload("res://scenes/Game/Player.tscn")
|
2021-11-11 20:38:10 +00:00
|
|
|
|
2021-11-23 04:04:21 +00:00
|
|
|
var Victory = preload("res://scenes/Game/Victory.tscn")
|
2021-11-14 06:34:51 +00:00
|
|
|
|
2021-11-13 10:34:39 +00:00
|
|
|
|
2021-11-11 21:38:50 +00:00
|
|
|
# Array of instances of the Player class; stores the Players
|
2021-11-23 04:04:21 +00:00
|
|
|
var players = [] # = player1, player2, ...
|
2021-11-18 15:00:15 +00:00
|
|
|
var players_ready = []
|
2021-11-11 21:38:50 +00:00
|
|
|
# turn counter
|
|
|
|
var turn = 0
|
2021-11-18 15:00:15 +00:00
|
|
|
# winner
|
|
|
|
var winner = 0
|
2021-11-08 13:40:11 +00:00
|
|
|
|
2021-11-18 15:00:15 +00:00
|
|
|
# Every game is a multiplayer game, even the ones that aren't.
|
|
|
|
# We're taking the Minecraft approach, baby
|
|
|
|
var network_id
|
2021-11-14 08:50:39 +00:00
|
|
|
|
2021-11-08 13:40:11 +00:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
2021-11-15 05:50:23 +00:00
|
|
|
|
2021-11-14 05:32:19 +00:00
|
|
|
get_node("ConfirmationDialog").get_ok().text = "Yes"
|
|
|
|
get_node("ConfirmationDialog").get_cancel().text = "No"
|
2021-11-14 08:50:39 +00:00
|
|
|
get_node("ConfirmationDialog").get_ok().rect_min_size.x = 100
|
|
|
|
get_node("ConfirmationDialog").get_cancel().rect_min_size.x = 100
|
|
|
|
|
2021-11-18 15:00:15 +00:00
|
|
|
if multiplayer:
|
|
|
|
# TODO: Spawn a lobby where people can either connect to a peer or create a server
|
|
|
|
pass
|
|
|
|
|
|
|
|
game_setup()
|
2021-11-13 10:34:39 +00:00
|
|
|
|
2021-11-18 15:00:15 +00:00
|
|
|
# Function used to keep track of which players are ready
|
2021-11-23 04:04:21 +00:00
|
|
|
func player_ready():
|
2021-11-18 15:50:17 +00:00
|
|
|
var who = get_tree().get_rpc_sender_id()
|
2021-11-23 04:04:21 +00:00
|
|
|
if get_tree().is_network_server() and who in Net.peer_info and not who in players_ready:
|
2021-11-18 15:50:17 +00:00
|
|
|
print ("ASSERT SUCCESS")
|
|
|
|
players_ready.append(who)
|
2021-11-18 15:00:15 +00:00
|
|
|
|
2021-11-23 04:04:21 +00:00
|
|
|
if players_ready.size() == Net.peer_info.size():
|
2021-11-18 15:00:15 +00:00
|
|
|
rpc("game_start")
|
2021-11-08 13:40:11 +00:00
|
|
|
|
2021-11-11 21:38:50 +00:00
|
|
|
# Member functions:
|
|
|
|
# game_start: starts the game
|
2021-11-23 04:04:21 +00:00
|
|
|
sync func game_setup():
|
2021-11-18 15:00:15 +00:00
|
|
|
# If there's no server connected, create one
|
2021-11-23 04:04:21 +00:00
|
|
|
if not Net.connected:
|
2021-11-18 15:00:15 +00:00
|
|
|
# TODO: Create a fake peer who we can automate, for single-player mode
|
2021-11-23 04:04:21 +00:00
|
|
|
Net.start_host()
|
|
|
|
network_id = Net.get_network_id()
|
|
|
|
# Create players for every player in Net.peer_info
|
|
|
|
for k in Net.peer_info.keys():
|
2021-11-18 15:00:15 +00:00
|
|
|
# Create a new player
|
|
|
|
var player = Player.instance()
|
|
|
|
# Give the player a recognizable name, like "1", instead of "@@97"
|
|
|
|
player.name = str(k)
|
|
|
|
# The player controls themselves
|
|
|
|
player.set_network_master(k)
|
|
|
|
# Add the player to the list of players
|
2021-11-23 04:04:21 +00:00
|
|
|
players.append(player)
|
2021-11-18 15:00:15 +00:00
|
|
|
# Add the player to the scene tree
|
|
|
|
add_child(player)
|
2021-11-08 13:40:11 +00:00
|
|
|
pass
|
2021-11-18 15:00:15 +00:00
|
|
|
|
2021-11-23 04:04:21 +00:00
|
|
|
func game_start():
|
2021-11-18 15:00:15 +00:00
|
|
|
# Make sure we're the server
|
2021-11-23 04:04:21 +00:00
|
|
|
pass
|
2021-11-18 15:00:15 +00:00
|
|
|
|
2021-11-18 15:50:17 +00:00
|
|
|
func _on_player_ready():
|
2021-11-18 15:00:15 +00:00
|
|
|
print ("_on_player_ready")
|
2021-11-18 15:50:17 +00:00
|
|
|
rpc_id(1, "player_ready")
|
2021-11-11 21:38:50 +00:00
|
|
|
|
|
|
|
# victory_screen: display the victory screen
|
|
|
|
func victory_screen():
|
2021-11-14 04:46:24 +00:00
|
|
|
# TODO: Create the victory screen, fill it with knowledge
|
2021-11-08 13:40:11 +00:00
|
|
|
pass
|
2021-11-11 21:38:50 +00:00
|
|
|
|
|
|
|
# display_turn(): display which turn it is on the screen
|
|
|
|
func display_turn():
|
2021-11-14 04:46:24 +00:00
|
|
|
# TODO: Update the turn display, if there is one?
|
2021-11-08 13:40:11 +00:00
|
|
|
pass
|
2021-11-13 10:34:39 +00:00
|
|
|
|
|
|
|
func _on_Forfeit_pressed():
|
|
|
|
AudioBus.emit_signal("button_clicked")
|
2021-11-14 06:08:16 +00:00
|
|
|
get_node("ConfirmationDialog").popup()
|
2021-11-13 10:34:39 +00:00
|
|
|
|
|
|
|
func end():
|
|
|
|
queue_free()
|
2021-11-14 06:34:51 +00:00
|
|
|
|
|
|
|
func _on_Button_button_down():
|
|
|
|
AudioBus.emit_signal("button_clicked")
|
|
|
|
var victory = Victory.instance()
|
|
|
|
add_child(victory)
|
|
|
|
victory.connect("exit_main", self, "end")
|
2021-11-14 06:39:02 +00:00
|
|
|
|
2021-11-14 06:08:16 +00:00
|
|
|
func _on_ConfirmationDialog_confirmed():
|
|
|
|
end()
|
2021-11-14 08:50:39 +00:00
|
|
|
|