98 lines
2.6 KiB
GDScript
98 lines
2.6 KiB
GDScript
extends Node
|
|
|
|
const _main_menu_path = "res://UI/MainMenu.tscn"
|
|
const _body_build_path = "res://BodyConfig/bodyBuilderMenu.tscn"
|
|
const _fighting_path = "res://Ingame/Testing.tscn"
|
|
const _win_screen_path = "res://UI/WinScreen.tscn"
|
|
|
|
var _main_menu_scene
|
|
var _body_build_scene
|
|
var _fighting_scene
|
|
var _win_screen_scene
|
|
|
|
var _bodies : Array
|
|
var _body_count = 0
|
|
var _body_positions = [Vector3(0, 15, 30), Vector3(0, 15, -30), Vector3(-30, 15, 0), Vector3(30, 15, 0)]
|
|
|
|
func _ready():
|
|
InGameState.player_count = 2
|
|
|
|
_prep_scene("main_menu")
|
|
|
|
_switch_scene(_main_menu_scene, "main_menu")
|
|
|
|
|
|
func _prep_scene(scene_name) -> Node:
|
|
if scene_name == "main_menu":
|
|
_main_menu_scene = preload(_main_menu_path).instance()
|
|
_main_menu_scene.connect("body_build", self, "_switch_to_body_build")
|
|
return _main_menu_scene
|
|
elif scene_name == "body_build":
|
|
_body_build_scene = preload(_body_build_path).instance()
|
|
_body_build_scene.connect("start_fight", self, "_switch_to_fighting")
|
|
return _body_build_scene
|
|
elif scene_name == "fight_scene":
|
|
_fighting_scene = preload(_fighting_path).instance()
|
|
InGameState.connect("player_win", self, "_switch_to_win")
|
|
return _fighting_scene
|
|
elif scene_name == "win_screen":
|
|
_win_screen_scene = preload(_win_screen_path).instance()
|
|
_win_screen_scene.connect("build_body", self, "_switch_to_body_build")
|
|
return _win_screen_scene
|
|
return null
|
|
|
|
|
|
func _switch_scene(scene, scene_name):
|
|
#delete children
|
|
for child in get_children():
|
|
child.queue_free()
|
|
|
|
#append win scene
|
|
var new_scene = _prep_scene(scene_name)
|
|
add_child(new_scene)
|
|
|
|
|
|
func _switch_to_win(player_id):
|
|
print("test win")
|
|
|
|
_switch_scene(_win_screen_scene, "win_screen")
|
|
|
|
#call win message in win scene
|
|
_win_screen_scene.set_win_message(player_id)
|
|
|
|
|
|
func _switch_to_fighting(torso):
|
|
_body_build_scene.remove_child(torso)
|
|
|
|
torso.global_transform.origin = Vector3.ZERO
|
|
torso.translation += _body_positions[_body_count]
|
|
torso.rotation_degrees = Vector3(90, 0, 0)
|
|
|
|
if _body_count == 0:
|
|
torso.rotation_degrees += Vector3(0, 180, 0)
|
|
|
|
_body_count += 1
|
|
if _body_count < InGameState.player_count:
|
|
_bodies.append(torso)
|
|
_switch_scene(_body_build_scene, "body_build")
|
|
|
|
_body_build_scene.done_player_count = _body_count
|
|
_body_build_scene.change_count_ui()
|
|
else:
|
|
_switch_scene(_fighting_scene, "fight_scene")
|
|
|
|
for body in _bodies:
|
|
_fighting_scene.add_child(body)
|
|
body.on_ingame()
|
|
|
|
_fighting_scene.add_child(torso)
|
|
torso.on_ingame()
|
|
|
|
_body_count = 0
|
|
_bodies.clear()
|
|
|
|
|
|
func _switch_to_body_build():
|
|
_switch_scene(_body_build_scene, "body_build")
|
|
_body_build_scene.change_count_ui()
|