bodypartfighter/Controllers/GameStateController.gd

98 lines
2.6 KiB
GDScript3
Raw Normal View History

2020-02-01 15:09:11 +01:00
extends Node
2020-02-02 11:15:30 +01:00
const _main_menu_path = "res://UI/MainMenu.tscn"
2020-02-01 18:36:42 +01:00
const _body_build_path = "res://BodyConfig/bodyBuilderMenu.tscn"
const _fighting_path = "res://Ingame/Testing.tscn"
const _win_screen_path = "res://UI/WinScreen.tscn"
2020-02-02 11:15:30 +01:00
var _main_menu_scene
2020-02-01 16:54:53 +01:00
var _body_build_scene
2020-02-01 18:36:42 +01:00
var _fighting_scene
var _win_screen_scene
2020-02-02 11:15:30 +01:00
2020-02-01 22:35:36 +01:00
var _bodies : Array
var _body_count = 0
2020-02-02 14:01:17 +01:00
var _body_positions = [Vector3(0, 15, 30), Vector3(0, 15, -30), Vector3(-30, 15, 0), Vector3(30, 15, 0)]
2020-02-01 18:36:42 +01:00
2020-02-01 15:09:11 +01:00
func _ready():
InGameState.player_count = 2
2020-02-01 22:35:36 +01:00
2020-02-02 11:15:30 +01:00
_prep_scene("main_menu")
2020-02-01 15:09:11 +01:00
2020-02-02 11:15:30 +01:00
_switch_scene(_main_menu_scene, "main_menu")
2020-02-01 18:36:42 +01:00
func _prep_scene(scene_name) -> Node:
2020-02-02 11:15:30 +01:00
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":
2020-02-01 18:36:42 +01:00
_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
2020-02-01 15:09:11 +01:00
2020-02-01 23:08:48 +01:00
2020-02-01 18:36:42 +01:00
func _switch_scene(scene, scene_name):
2020-02-01 15:09:11 +01:00
#delete children
for child in get_children():
child.queue_free()
#append win scene
2020-02-01 18:36:42 +01:00
var new_scene = _prep_scene(scene_name)
add_child(new_scene)
2020-02-01 15:09:11 +01:00
func _switch_to_win(player_id):
2020-02-01 18:36:42 +01:00
print("test win")
_switch_scene(_win_screen_scene, "win_screen")
2020-02-01 15:09:11 +01:00
#call win message in win scene
_win_screen_scene.set_win_message(player_id)
2020-02-01 20:30:27 +01:00
func _switch_to_fighting(torso):
_body_build_scene.remove_child(torso)
torso.global_transform.origin = Vector3.ZERO
2020-02-02 10:21:50 +01:00
torso.translation += _body_positions[_body_count]
torso.rotation_degrees = Vector3(90, 0, 0)
2020-02-02 14:01:17 +01:00
if _body_count == 0:
torso.rotation_degrees += Vector3(0, 180, 0)
2020-02-01 20:30:27 +01:00
2020-02-01 22:35:36 +01:00
_body_count += 1
if _body_count < InGameState.player_count:
_bodies.append(torso)
_switch_scene(_body_build_scene, "body_build")
2020-02-01 23:08:48 +01:00
_body_build_scene.done_player_count = _body_count
_body_build_scene.change_count_ui()
2020-02-01 22:35:36 +01:00
else:
_switch_scene(_fighting_scene, "fight_scene")
for body in _bodies:
_fighting_scene.add_child(body)
body.on_ingame()
2020-02-01 22:35:36 +01:00
_fighting_scene.add_child(torso)
torso.on_ingame()
2020-02-02 12:46:54 +01:00
_body_count = 0
_bodies.clear()
2020-02-01 16:54:53 +01:00
func _switch_to_body_build():
2020-02-01 18:36:42 +01:00
_switch_scene(_body_build_scene, "body_build")
2020-02-02 11:15:30 +01:00
_body_build_scene.change_count_ui()