extends Node2D

var G: Node2D
var L: Node2D
var P: CharacterBody2D

var curr_lives: int  = PDash.STARTING_LIVES
var curr_lvl: int = 1

func load_lvl( lvl_index: int ):
	var lvl_path = PDash.lvl_paths[ lvl_index-1 ]
	var lvl: Node = load( lvl_path ).instantiate()
	G.add_child( lvl )
	L = $Game/Level
	init_lvl()
	
func load_plyr():
	var plyr = load("res://scenes/Player.tscn").instantiate()
	G.add_child( plyr )
	P = $Game/Player
	init_plyr()
	
func init_lvl():
	#connect signals
	var switches = $Game/Level/Switches.get_children()
	for s in switches:
		s.body_entered.connect( _on_switch_body_entered.bind(s.type))
#	$player.combat_trigger.connect(start_combat)
	
	pass
	
func init_plyr():
	#P.init()
	P.set_direction( L.ini_dir )
	P.set_gravity_vector( L.ini_grav_vec )
	P.position = L.get_node("SpawnPoint").position
	
# Called when the node enters the scene tree for the first time.
func _ready():
	G = $Game
	
	PDash.fade( "in" , 1 )
	
	load_lvl(curr_lvl)
	load_plyr()
	
func _on_switch_body_entered(body,type):
	if type == 0: #end switch
		pass
	elif type == 1: #abyss switch
		P.fall()
	elif type == 2: #gravity switch
		pass

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	pass
