51 lines
1.5 KiB
GDScript
51 lines
1.5 KiB
GDScript
extends Node
|
|
|
|
const floor_file_path = "res://scenes/floors/Floor"
|
|
|
|
# 加载指定楼层
|
|
func load_by_floor(f:int) -> Node2D:
|
|
var root = get_tree().get_root().get_node("Main")
|
|
var next_floor = load("%s%s%s" % [floor_file_path,f,".tscn"]).instance() as Node2D
|
|
var used_items = GameArchiveManager.get_used_item(f)
|
|
root.get_node("Floor%s" % GameArchiveManager.player_info.now_floor).free()
|
|
root.add_child(next_floor)
|
|
for used_item in used_items:
|
|
var node = next_floor.get_node(used_item)
|
|
if node != null:
|
|
node.free()
|
|
GameArchiveManager.player_info.now_floor = f
|
|
return next_floor
|
|
|
|
# 加载上一层楼层
|
|
func load_added_floor():
|
|
var f = GameArchiveManager.player_info.now_floor
|
|
if f + 1 > 50:
|
|
return
|
|
var next_floor = load_by_floor(f + 1)
|
|
var stairs = get_tree().get_nodes_in_group("stairs")
|
|
if stairs.empty():
|
|
return
|
|
for s in stairs:
|
|
if s.stairs_type == StairsSprite.StairsType.Down:
|
|
instance_player(s.player_init_position,next_floor)
|
|
return
|
|
|
|
# 加载下一次楼层
|
|
func load_reduced_floor():
|
|
var f = GameArchiveManager.player_info.now_floor
|
|
if f - 1 < 0:
|
|
return
|
|
var next_floor = load_by_floor(f - 1)
|
|
var stairs = get_tree().get_nodes_in_group("stairs")
|
|
if stairs.empty():
|
|
return
|
|
for s in stairs:
|
|
if s.stairs_type == StairsSprite.StairsType.Up:
|
|
instance_player(s.player_init_position,next_floor)
|
|
return
|
|
|
|
func instance_player(position:Vector2,next_floor:Node2D) -> void:
|
|
var player = load("res://scenes/Player.tscn").instance()
|
|
player.position = position
|
|
next_floor.add_child(player)
|