freettrpg/scripts/mapscript.gd

58 lines
1.6 KiB
GDScript3
Raw Normal View History

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
var objectName
# Kick the game off
func _ready():
# Hide character viewer GUI initially
$"../characterViewer".hideGet()
# Start cycling through players
next()
2024-06-18 18:58:47 +02:00
# Function to switch to the next player
func next():
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
# Function to display statistics, lots of relative links, may change eventually
func stats():
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-18 18:58:47 +02:00
# Function to restart the node's state
func restart():
visible = true # Show game area
$"../characterViewer".visible = false
get_node(objectName).start()
# Activate back button
$"../back".disabled = true
$"../back".visible = false
2024-06-18 18:58:47 +02:00
# Handler for when the back button is pressed
func _on_back_pressed():
restart() # Gives control back to the current player character