Added rudimentary character select

This commit is contained in:
desktop 2021-02-26 22:17:00 +01:00
parent 3e40b6b107
commit 1b9d5bc781
3 changed files with 34 additions and 17 deletions

View file

@ -1,11 +1,18 @@
extends Control
signal character_selected()
onready var character_select = get_parent().get_parent().get_parent().get_parent()
func set_character(packed_character):
var character = packed_character.instance()
character.show_healthbar = false
$Viewport.add_child(character)
$CharacterDisplay.connect("pressed", self, "select_character")
func select_character():
emit_signal("character_selected")
func _process(delta):
$Viewport.size = rect_size

View file

@ -1,6 +1,7 @@
extends Control
onready var game = get_parent().get_parent()
var selected_character = null
func _ready():
var dir = Directory.new()
@ -21,7 +22,13 @@ func add_character(character_name):
var character_option = preload("res://GUI/CharacterOption.tscn").instance()
$CenterContainer/VBoxContainer/CharacterList.add_child(character_option)
character_option.set_character(packed_character)
character_option.connect("character_selected", self, "character_selected", [character_name, packed_character])
func character_selected(character_name, packed_character):
print(character_name)
game.local_player = packed_character.instance()
func spawn():
game.spawn(get_tree().get_network_unique_id())

35
Game.gd
View file

@ -22,8 +22,27 @@ var local_player = null setget set_local_player
onready var menu_stack = [$MenuContainer/MainMenu]
func set_local_player(player):
if local_player != null:
$Players.remove_child(local_player)
local_player = player
var id = peer.get_unique_id()
player.name = str(id)
player.set_network_master(id)
$Players.add_child(local_player)
player.set_local_player()
var nickname = $MenuContainer/MainMenu/Name.text
set_nickname(nickname)
player.set_nickname(nickname)
on_player_added(player)
var player_data = get_player_data()
rpc("set_player_data", player_data)
player.hide()
# Called when the node enters the scene tree for the first time.
func _ready():
@ -255,26 +274,10 @@ remote func check_players(player_data):
func join_game():
var player = player_scene.instance()
var id = peer.get_unique_id()
player.name = str(id)
player.set_network_master(id)
$Players.add_child(player)
set_local_player(player)
var nickname = $MenuContainer/MainMenu/Name.text
set_nickname(nickname)
player.set_nickname(nickname)
on_player_added(player)
var player_data = get_player_data()
rpc("set_player_data", player_data)
player.hide()
open_menu("CharacterSelectScreen")
sync func spawn(player_id):
var spawning_player = $Players.get_node(str(player_id))