2024-06-13 14:25:37 +02:00
|
|
|
extends Node2D
|
|
|
|
|
2024-06-18 18:58:47 +02:00
|
|
|
# Number of players and current player index
|
|
|
|
var playerAmount = 2
|
|
|
|
var playerIndex = 0
|
|
|
|
|
|
|
|
# Variable to hold the current player's object name
|
2024-06-13 14:25:37 +02:00
|
|
|
var objectName
|
|
|
|
|
2024-06-19 18:27:40 +02:00
|
|
|
# Kick the game off
|
2024-06-13 14:25:37 +02:00
|
|
|
func _ready():
|
2024-06-19 18:27:40 +02:00
|
|
|
# Hide character viewer GUI initially
|
|
|
|
$"../characterViewer".hideGet()
|
|
|
|
# Start cycling through players
|
|
|
|
next()
|
2024-06-13 14:25:37 +02:00
|
|
|
|
2024-06-18 18:58:47 +02:00
|
|
|
# Function to switch to the next player
|
2024-06-13 14:25:37 +02:00
|
|
|
func next():
|
2024-06-19 18:27:40 +02:00
|
|
|
if playerIndex >= playerAmount:
|
|
|
|
playerIndex = 0
|
|
|
|
|
|
|
|
# Construct object name based on player index
|
|
|
|
objectName = "player%d" % playerIndex
|
|
|
|
|
|
|
|
# Start the current player's activity
|
|
|
|
get_node(objectName).start()
|
|
|
|
|
|
|
|
playerIndex += 1 # Move to the next player index
|
2024-06-13 14:25:37 +02:00
|
|
|
|
2024-06-19 18:27:40 +02:00
|
|
|
# Function to display statistics, lots of relative links, may change eventually
|
2024-06-16 19:32:19 +02:00
|
|
|
func stats():
|
2024-06-19 18:27:40 +02:00
|
|
|
visible = false # Hide game area
|
|
|
|
$"../characterViewer".visible = true
|
|
|
|
get_node(objectName).stop()
|
|
|
|
# Activate back button
|
|
|
|
$"../back".disabled = false
|
|
|
|
$"../back".visible = true
|
|
|
|
|
|
|
|
# Update player index display in character viewer
|
|
|
|
$"../characterViewer/ScrollContainer/VBoxContainer".get_child(0).text = str(playerIndex - 1)
|
|
|
|
$"../characterViewer/ScrollContainer/VBoxContainer".get_child(0).editable = false
|
|
|
|
|
|
|
|
# Simulate button press in character viewer (assuming this triggers further actions)
|
|
|
|
$"../characterViewer"._on_button_pressed()
|
2024-06-16 19:32:19 +02:00
|
|
|
|
2024-06-18 18:58:47 +02:00
|
|
|
# Function to restart the node's state
|
2024-06-16 19:32:19 +02:00
|
|
|
func restart():
|
2024-06-19 18:27:40 +02:00
|
|
|
visible = true # Show game area
|
|
|
|
$"../characterViewer".visible = false
|
|
|
|
get_node(objectName).start()
|
|
|
|
# Activate back button
|
|
|
|
$"../back".disabled = true
|
|
|
|
$"../back".visible = false
|
2024-06-16 19:32:19 +02:00
|
|
|
|
2024-06-18 18:58:47 +02:00
|
|
|
# Handler for when the back button is pressed
|
2024-06-16 19:32:19 +02:00
|
|
|
func _on_back_pressed():
|
2024-06-19 18:27:40 +02:00
|
|
|
restart() # Gives control back to the current player character
|