This commit is contained in:
TsubakiLoL 2024-10-30 19:54:45 +08:00
parent 097460a1a4
commit 285af6eb6c
17 changed files with 335 additions and 30 deletions

View File

@ -78,3 +78,9 @@ func add_unit_id_save_map(unit_data:Dictionary):
#获取地图中的存储角色数据 #获取地图中的存储角色数据
func get_map_data(map_id:String): func get_map_data(map_id:String):
return map_dictionary[map_id] return map_dictionary[map_id]
var now_player_data:Dictionary={
}

View File

@ -44,6 +44,11 @@ mouse_right={
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":2,"position":Vector2(150, 28),"global_position":Vector2(159, 74),"factor":1.0,"button_index":2,"canceled":false,"pressed":true,"double_click":false,"script":null) "events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":2,"position":Vector2(150, 28),"global_position":Vector2(159, 74),"factor":1.0,"button_index":2,"canceled":false,"pressed":true,"double_click":false,"script":null)
] ]
} }
e={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null)
]
}
[rendering] [rendering]

View File

@ -4,17 +4,10 @@ extends AnimatedSprite2D
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready() -> void: func _ready() -> void:
play("dead")
pass # Replace with function body. pass # Replace with function body.
func _on_animation_finished() -> void: func _on_animation_finished() -> void:
animation_player.play("modulutehide") animation_player.play("free")
queue_free()
pass # Replace with function body.
func _on_animation_player_animation_finished(anim_name: StringName) -> void:
print("dada")
queue_free()
pass # Replace with function body.

View File

@ -18,7 +18,7 @@ tracks/0/keys = {
} }
[sub_resource type="Animation" id="Animation_w6wlf"] [sub_resource type="Animation" id="Animation_w6wlf"]
resource_name = "modulutehide" resource_name = "free"
length = 0.5 length = 0.5
tracks/0/type = "value" tracks/0/type = "value"
tracks/0/imported = false tracks/0/imported = false
@ -32,11 +32,25 @@ tracks/0/keys = {
"update": 0, "update": 0,
"values": [Color(1, 1, 1, 1), Color(1, 1, 1, 0)] "values": [Color(1, 1, 1, 1), Color(1, 1, 1, 0)]
} }
tracks/1/type = "method"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0.5),
"transitions": PackedFloat32Array(1),
"values": [{
"args": [],
"method": &"queue_free"
}]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_a2cak"] [sub_resource type="AnimationLibrary" id="AnimationLibrary_a2cak"]
_data = { _data = {
"RESET": SubResource("Animation_mdkhy"), "RESET": SubResource("Animation_mdkhy"),
"modulutehide": SubResource("Animation_w6wlf") "free": SubResource("Animation_w6wlf")
} }
[node name="DeadScene" type="AnimatedSprite2D"] [node name="DeadScene" type="AnimatedSprite2D"]
@ -48,4 +62,3 @@ libraries = {
} }
[connection signal="animation_finished" from="." to="." method="_on_animation_finished"] [connection signal="animation_finished" from="." to="." method="_on_animation_finished"]
[connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_animation_player_animation_finished"]

3
scene/class/born_mark.gd Normal file
View File

@ -0,0 +1,3 @@
extends Marker2D
class_name BornMark

View File

@ -1 +1,7 @@
extends Node extends Area2D
class_name Door
@export var map_id:String
@export var map_born_pos:int=0

View File

@ -1,7 +1,7 @@
extends Node2D extends Node2D
class_name map class_name map
@export var map_id:String="" @export var map_id:String=""
@export var map_born_mark:Array[BornMark]
var pre_character_data:Array=[] var pre_character_data:Array=[]
func _ready() -> void: func _ready() -> void:
Global.now_map_id=map_id Global.now_map_id=map_id
@ -15,3 +15,14 @@ func _ready() -> void:
} }
pre_character_data.append(new_dic) pre_character_data.append(new_dic)
i.queue_free() i.queue_free()
#获取第ind个门的位置
func get_mark_postion(ind:int):
if ind<map_born_mark.size() and ind>=0:
var mark=map_born_mark[ind]
if mark is Node2D:
return mark.global_position
pass
pass

View File

@ -1,8 +1,11 @@
[gd_scene load_steps=7 format=4 uid="uid://bt05onvfl6ael"] [gd_scene load_steps=11 format=4 uid="uid://bt05onvfl6ael"]
[ext_resource type="Script" path="res://scene/map/map_test_0.gd" id="1_mkv6t"] [ext_resource type="Script" path="res://scene/map/map_test_0.gd" id="1_mkv6t"]
[ext_resource type="Texture2D" uid="uid://dxtu12mw7fsq8" path="res://res/image/test/tile.png" id="2_k3cp7"] [ext_resource type="Texture2D" uid="uid://dxtu12mw7fsq8" path="res://res/image/test/tile.png" id="2_k3cp7"]
[ext_resource type="PackedScene" uid="uid://b6jyxox72yxjc" path="res://scene/mark/character_marker_2d.tscn" id="3_v1al5"] [ext_resource type="PackedScene" uid="uid://b6jyxox72yxjc" path="res://scene/mark/character_marker_2d.tscn" id="3_v1al5"]
[ext_resource type="Script" path="res://scene/class/door.gd" id="4_61dsd"]
[ext_resource type="Texture2D" uid="uid://csk8u15wepd1w" path="res://icon.svg" id="5_b01gw"]
[ext_resource type="Script" path="res://scene/class/born_mark.gd" id="6_qu6gr"]
[sub_resource type="NavigationPolygon" id="NavigationPolygon_tjudi"] [sub_resource type="NavigationPolygon" id="NavigationPolygon_tjudi"]
vertices = PackedVector2Array(32, 32, -32, 32, -32, -32, 32, -32) vertices = PackedVector2Array(32, 32, -32, 32, -32, -32, 32, -32)
@ -24,8 +27,12 @@ physics_layer_0/collision_layer = 1
navigation_layer_0/layers = 1 navigation_layer_0/layers = 1
sources/0 = SubResource("TileSetAtlasSource_j4j8n") sources/0 = SubResource("TileSetAtlasSource_j4j8n")
[node name="map_test_0" type="Node2D"] [sub_resource type="CircleShape2D" id="CircleShape2D_1hdps"]
radius = 76.99
[node name="map_test_0" type="Node2D" node_paths=PackedStringArray("map_born_mark")]
script = ExtResource("1_mkv6t") script = ExtResource("1_mkv6t")
map_born_mark = [NodePath("BornMark")]
[node name="navigation" type="TileMapLayer" parent="."] [node name="navigation" type="TileMapLayer" parent="."]
unique_name_in_owner = true unique_name_in_owner = true
@ -49,3 +56,18 @@ unit_data_from_id = "test_character_base"
position = Vector2(359, -417) position = Vector2(359, -417)
unit_id = "test3" unit_id = "test3"
unit_data_from_id = "test_character_base" unit_data_from_id = "test_character_base"
[node name="Door" type="Area2D" parent="."]
position = Vector2(1079, 609)
script = ExtResource("4_61dsd")
map_id = "map_1"
[node name="Sprite2D" type="Sprite2D" parent="Door"]
texture = ExtResource("5_b01gw")
[node name="CollisionShape2D" type="CollisionShape2D" parent="Door"]
shape = SubResource("CircleShape2D_1hdps")
[node name="BornMark" type="Marker2D" parent="."]
position = Vector2(-1043, -488)
script = ExtResource("6_qu6gr")

View File

@ -1,8 +1,11 @@
[gd_scene load_steps=7 format=4 uid="uid://cgbmwgp5kxn43"] [gd_scene load_steps=11 format=4 uid="uid://cgbmwgp5kxn43"]
[ext_resource type="Script" path="res://scene/map/map_test_0.gd" id="1_476af"] [ext_resource type="Script" path="res://scene/map/map_test_0.gd" id="1_476af"]
[ext_resource type="Texture2D" uid="uid://dxtu12mw7fsq8" path="res://res/image/test/tile.png" id="2_3qa44"] [ext_resource type="Texture2D" uid="uid://dxtu12mw7fsq8" path="res://res/image/test/tile.png" id="2_3qa44"]
[ext_resource type="PackedScene" uid="uid://b6jyxox72yxjc" path="res://scene/mark/character_marker_2d.tscn" id="3_yk4q8"] [ext_resource type="PackedScene" uid="uid://b6jyxox72yxjc" path="res://scene/mark/character_marker_2d.tscn" id="3_yk4q8"]
[ext_resource type="Script" path="res://scene/class/door.gd" id="4_fof6u"]
[ext_resource type="Texture2D" uid="uid://csk8u15wepd1w" path="res://icon.svg" id="5_cp4uj"]
[ext_resource type="Script" path="res://scene/class/born_mark.gd" id="6_jfam2"]
[sub_resource type="NavigationPolygon" id="NavigationPolygon_tjudi"] [sub_resource type="NavigationPolygon" id="NavigationPolygon_tjudi"]
vertices = PackedVector2Array(32, 32, -32, 32, -32, -32, 32, -32) vertices = PackedVector2Array(32, 32, -32, 32, -32, -32, 32, -32)
@ -24,8 +27,12 @@ physics_layer_0/collision_layer = 1
navigation_layer_0/layers = 1 navigation_layer_0/layers = 1
sources/0 = SubResource("TileSetAtlasSource_j4j8n") sources/0 = SubResource("TileSetAtlasSource_j4j8n")
[node name="map_test_1" type="Node2D"] [sub_resource type="CircleShape2D" id="CircleShape2D_jekr0"]
radius = 76.99
[node name="map_test_1" type="Node2D" node_paths=PackedStringArray("map_born_mark")]
script = ExtResource("1_476af") script = ExtResource("1_476af")
map_born_mark = [NodePath("BornMark")]
[node name="navigation" type="TileMapLayer" parent="."] [node name="navigation" type="TileMapLayer" parent="."]
unique_name_in_owner = true unique_name_in_owner = true
@ -44,3 +51,18 @@ unit_data_from_id = "test_character_base"
position = Vector2(842, 32) position = Vector2(842, 32)
unit_id = "test2" unit_id = "test2"
unit_data_from_id = "test_character_base" unit_data_from_id = "test_character_base"
[node name="Door" type="Area2D" parent="."]
position = Vector2(1079, 609)
script = ExtResource("4_fof6u")
map_id = "map_0"
[node name="Sprite2D" type="Sprite2D" parent="Door"]
texture = ExtResource("5_cp4uj")
[node name="CollisionShape2D" type="CollisionShape2D" parent="Door"]
shape = SubResource("CircleShape2D_jekr0")
[node name="BornMark" type="Marker2D" parent="."]
position = Vector2(-1043, -488)
script = ExtResource("6_jfam2")

View File

@ -11,6 +11,7 @@ outline_color = Color(0, 0, 0, 1)
script = ExtResource("1_6325c") script = ExtResource("1_6325c")
unit_id = "测试2" unit_id = "测试2"
unit_type = "default" unit_type = "default"
metadata/_edit_horizontal_guides_ = [-141.0]
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
position = Vector2(-2, -88) position = Vector2(-2, -88)

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=16 format=3 uid="uid://cf2g2urxaukxb"] [gd_scene load_steps=18 format=3 uid="uid://cf2g2urxaukxb"]
[ext_resource type="Script" path="res://scene/test/self_character.gd" id="1_d0trv"] [ext_resource type="Script" path="res://scene/test/self_character.gd" id="1_d0trv"]
[ext_resource type="Script" path="res://scene/test/state_machine.gd" id="2_v5m4x"] [ext_resource type="Script" path="res://scene/test/state_machine.gd" id="2_v5m4x"]
@ -61,11 +61,22 @@ colors = PackedColorArray(0, 1, 0, 1, 0, 1, 0, 1)
[sub_resource type="GradientTexture1D" id="GradientTexture1D_jp0r7"] [sub_resource type="GradientTexture1D" id="GradientTexture1D_jp0r7"]
gradient = SubResource("Gradient_vdy2i") gradient = SubResource("Gradient_vdy2i")
[node name="CharacterBody2D" type="CharacterBody2D" node_paths=PackedStringArray("agent", "state_machine", "rotate", "attack_area")] [sub_resource type="LabelSettings" id="LabelSettings_50aib"]
outline_size = 5
outline_color = Color(0, 0, 0, 1)
[sub_resource type="CircleShape2D" id="CircleShape2D_rhh7a"]
radius = 104.12
[node name="CharacterBody2D" type="CharacterBody2D" node_paths=PackedStringArray("agent", "state_machine", "rotate", "touch_area", "attack_area")]
script = ExtResource("1_d0trv") script = ExtResource("1_d0trv")
unit_id = "player"
unit_type = "player"
unit_data_from_id = "test_character_base"
agent = NodePath("agent") agent = NodePath("agent")
state_machine = NodePath("state_machine") state_machine = NodePath("state_machine")
rotate = NodePath("rotate") rotate = NodePath("rotate")
touch_area = NodePath("touch_area")
attack_area = NodePath("rotate/attack_area") attack_area = NodePath("rotate/attack_area")
[node name="agent" type="NavigationAgent2D" parent="."] [node name="agent" type="NavigationAgent2D" parent="."]
@ -137,4 +148,22 @@ nine_patch_stretch = true
texture_under = SubResource("GradientTexture1D_akajp") texture_under = SubResource("GradientTexture1D_akajp")
texture_progress = SubResource("GradientTexture1D_jp0r7") texture_progress = SubResource("GradientTexture1D_jp0r7")
[node name="door" type="Label" parent="."]
unique_name_in_owner = true
visible = false
offset_left = -13.0
offset_top = -133.0
offset_right = 27.0
offset_bottom = -110.0
text = "按e传送"
label_settings = SubResource("LabelSettings_50aib")
[node name="touch_area" type="Area2D" parent="."]
unique_name_in_owner = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="touch_area"]
shape = SubResource("CircleShape2D_rhh7a")
[connection signal="state_value_changed" from="." to="." method="_on_state_value_changed"] [connection signal="state_value_changed" from="." to="." method="_on_state_value_changed"]
[connection signal="area_entered" from="touch_area" to="." method="_on_touch_area_area_entered"]
[connection signal="area_exited" from="touch_area" to="." method="_on_touch_area_area_exited"]

View File

@ -138,7 +138,7 @@ texture_under = SubResource("GradientTexture1D_ioncu")
texture_progress = SubResource("GradientTexture1D_6t72h") texture_progress = SubResource("GradientTexture1D_6t72h")
[node name="BeehaveTree" parent="." node_paths=PackedStringArray("blackboard", "actor") instance=ExtResource("3_5u10o")] [node name="BeehaveTree" parent="." node_paths=PackedStringArray("blackboard", "actor") instance=ExtResource("3_5u10o")]
blackboard = NodePath("@Node@223301") blackboard = NodePath("@Node@17289")
actor = NodePath("..") actor = NodePath("..")
[connection signal="state_value_changed" from="." to="." method="_on_state_value_changed"] [connection signal="state_value_changed" from="." to="." method="_on_state_value_changed"]

View File

@ -1,5 +1,5 @@
extends Unit extends Unit
class_name SelfUnit
func _ready() -> void: func _ready() -> void:
unit_data=Database.get_unit_data(unit_data_from_id,unit_id) unit_data=Database.get_unit_data(unit_data_from_id,unit_id)
super._ready() super._ready()
@ -13,3 +13,26 @@ func _on_state_value_changed(state_value_name: String, value: Variant) -> void:
"hp_max": "hp_max":
%hp.max_value=value %hp.max_value=value
pass # Replace with function body. pass # Replace with function body.
var door_area:Door
func _on_touch_area_area_entered(area: Area2D) -> void:
if area is Door:
door_area=area
%door.show()
pass # Replace with function body.
func _on_touch_area_area_exited(area: Area2D) -> void:
if area is Door:
door_area=null
%door.hide()
pass # Replace with function body.
func is_door_availible():
return door_area!=null
func get_door():
return door_area

80
scene/test/tes9069.tmp Normal file
View File

@ -0,0 +1,80 @@
[gd_scene load_steps=4 format=3 uid="uid://1wl1fl3qtxc"]
[ext_resource type="Script" path="res://scene/test/test_main.gd" id="1_aimp4"]
[ext_resource type="PackedScene" uid="uid://cf2g2urxaukxb" path="res://scene/test/character.tscn" id="2_nvm7o"]
[sub_resource type="CircleShape2D" id="CircleShape2D_shajf"]
radius = 38.71
[node name="main" type="Node2D" node_paths=PackedStringArray("player")]
script = ExtResource("1_aimp4")
player = NodePath("CB_add_pos/CharacterBody2D")
[node name="map" type="Node2D" parent="."]
[node name="CanvasLayer" type="CanvasLayer" parent="."]
layer = 2
[node name="Control" type="Control" parent="CanvasLayer"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="HBoxContainer" type="HBoxContainer" parent="CanvasLayer/Control"]
layout_mode = 0
offset_right = 272.0
offset_bottom = 66.0
[node name="type" type="MenuButton" parent="CanvasLayer/Control/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
flat = false
item_count = 2
popup/item_0/text = "test_character_base"
popup/item_1/text = "test_character_ranged"
popup/item_1/id = 1
[node name="put_check" type="CheckBox" parent="CanvasLayer/Control/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
text = "投放"
[node name="LineEdit" type="LineEdit" parent="CanvasLayer/Control/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
placeholder_text = "id"
[node name="num" type="Label" parent="CanvasLayer/Control/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
[node name="cacul_num_number" type="Timer" parent="CanvasLayer/Control/HBoxContainer"]
autostart = true
[node name="change_scene_0" type="Button" parent="CanvasLayer/Control/HBoxContainer"]
layout_mode = 2
text = "切换到场景0"
[node name="change_scene_1" type="Button" parent="CanvasLayer/Control/HBoxContainer"]
layout_mode = 2
text = "切换到场景1"
[node name="mouse_finder" type="Area2D" parent="."]
unique_name_in_owner = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="mouse_finder"]
shape = SubResource("CircleShape2D_shajf")
[node name="CB_add_pos" type="Node2D" parent="."]
unique_name_in_owner = true
y_sort_enabled = true
[node name="CharacterBody2D" parent="CB_add_pos" instance=ExtResource("2_nvm7o")]
[connection signal="gui_input" from="CanvasLayer/Control" to="." method="_on_control_gui_input"]
[connection signal="timeout" from="CanvasLayer/Control/HBoxContainer/cacul_num_number" to="." method="_on_cacul_num_number_timeout"]
[connection signal="pressed" from="CanvasLayer/Control/HBoxContainer/change_scene_0" to="." method="_on_change_scene_0_pressed"]
[connection signal="pressed" from="CanvasLayer/Control/HBoxContainer/change_scene_1" to="." method="_on_change_scene_1_pressed"]

80
scene/test/tesF9B9.tmp Normal file
View File

@ -0,0 +1,80 @@
[gd_scene load_steps=4 format=3 uid="uid://1wl1fl3qtxc"]
[ext_resource type="Script" path="res://scene/test/test_main.gd" id="1_aimp4"]
[ext_resource type="PackedScene" uid="uid://cf2g2urxaukxb" path="res://scene/test/character.tscn" id="2_nvm7o"]
[sub_resource type="CircleShape2D" id="CircleShape2D_shajf"]
radius = 38.71
[node name="main" type="Node2D" node_paths=PackedStringArray("player")]
script = ExtResource("1_aimp4")
player = NodePath("CB_add_pos/CharacterBody2D")
[node name="map" type="Node2D" parent="."]
[node name="CanvasLayer" type="CanvasLayer" parent="."]
layer = 2
[node name="Control" type="Control" parent="CanvasLayer"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="HBoxContainer" type="HBoxContainer" parent="CanvasLayer/Control"]
layout_mode = 0
offset_right = 272.0
offset_bottom = 66.0
[node name="type" type="MenuButton" parent="CanvasLayer/Control/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
flat = false
item_count = 2
popup/item_0/text = "test_character_base"
popup/item_1/text = "test_character_ranged"
popup/item_1/id = 1
[node name="put_check" type="CheckBox" parent="CanvasLayer/Control/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
text = "投放"
[node name="LineEdit" type="LineEdit" parent="CanvasLayer/Control/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
placeholder_text = "id"
[node name="num" type="Label" parent="CanvasLayer/Control/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
[node name="cacul_num_number" type="Timer" parent="CanvasLayer/Control/HBoxContainer"]
autostart = true
[node name="change_scene_0" type="Button" parent="CanvasLayer/Control/HBoxContainer"]
layout_mode = 2
text = "切换到场景0"
[node name="change_scene_1" type="Button" parent="CanvasLayer/Control/HBoxContainer"]
layout_mode = 2
text = "切换到场景1"
[node name="mouse_finder" type="Area2D" parent="."]
unique_name_in_owner = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="mouse_finder"]
shape = SubResource("CircleShape2D_shajf")
[node name="CB_add_pos" type="Node2D" parent="."]
unique_name_in_owner = true
y_sort_enabled = true
[node name="CharacterBody2D" parent="CB_add_pos" instance=ExtResource("2_nvm7o")]
[connection signal="gui_input" from="CanvasLayer/Control" to="." method="_on_control_gui_input"]
[connection signal="timeout" from="CanvasLayer/Control/HBoxContainer/cacul_num_number" to="." method="_on_cacul_num_number_timeout"]
[connection signal="pressed" from="CanvasLayer/Control/HBoxContainer/change_scene_0" to="." method="_on_change_scene_0_pressed"]
[connection signal="pressed" from="CanvasLayer/Control/HBoxContainer/change_scene_1" to="." method="_on_change_scene_1_pressed"]

View File

@ -1,5 +1,5 @@
extends Node2D extends Node2D
@export var player: CharacterBody2D @export var player: SelfUnit
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
%mouse_finder.position=get_global_mouse_position() %mouse_finder.position=get_global_mouse_position()
@ -22,6 +22,7 @@ func _on_control_gui_input(event: InputEvent) -> void:
%CB_add_pos.add_child(new_cb) %CB_add_pos.add_child(new_cb)
new_cb.second_timer_time_out() new_cb.second_timer_time_out()
return return
var arr=%mouse_finder.get_overlapping_bodies() var arr=%mouse_finder.get_overlapping_bodies()
print(arr) print(arr)
if arr.size()==0: if arr.size()==0:
@ -32,9 +33,14 @@ func _on_control_gui_input(event: InputEvent) -> void:
player.sent_message("attack",target) player.sent_message("attack",target)
pass pass
pass # Replace with function body. pass # Replace with function body.
func _input(event: InputEvent) -> void:
print(event)
if event.is_action_pressed("e") and player!=null and player.is_door_availible():
print("检测到切换请求")
var door:Door =player.get_door()
change_map(door.map_id)
func get_closest_node(self_node:Node2D,array:Array,target_class): func get_closest_node(self_node:Node2D,array:Array,target_class):
if array.size()==0: if array.size()==0:
return null return null
@ -71,8 +77,10 @@ func _on_cacul_num_number_timeout() -> void:
%num.text="场上单位数量:"+str(Global.unit_instance_dic.keys().size()) %num.text="场上单位数量:"+str(Global.unit_instance_dic.keys().size())
pass # Replace with function body. pass # Replace with function body.
func change_map(map_id:String): func change_map(map_id:String,ind:int=0):
print("map_changed:"+str(map_id)+",map_ind:"+str(ind))
if now_map!=null: if now_map!=null:
Global.map_dictionary.erase(now_map.map_id)
now_map.queue_free() now_map.queue_free()
for i in %CB_add_pos.get_children(): for i in %CB_add_pos.get_children():
if i is UnitOther: if i is UnitOther:
@ -80,13 +88,19 @@ func change_map(map_id:String):
Global.add_unit_id_save_map(i.unit_data) Global.add_unit_id_save_map(i.unit_data)
i.queue_free() i.queue_free()
var new_map_tscn=Database.get_map_data(map_id) var new_map_tscn=Database.get_map_data(map_id)
if new_map_tscn==null: if new_map_tscn==null:
return return
var new_map=load(new_map_tscn).instantiate() as map var new_map=load(new_map_tscn).instantiate() as map
new_map.map_id=map_id new_map.map_id=map_id
add_child(new_map) add_child(new_map)
var new_player= preload("res://scene/test/character.tscn").instantiate()
if player!=null:
player.queue_free()
player=new_player
new_player.global_position=new_map.get_mark_postion(ind)
%CB_add_pos.add_child(new_player)
new_map.z_index-=1 new_map.z_index-=1
now_map=new_map now_map=new_map
if not Global.is_map_initlized(map_id): if not Global.is_map_initlized(map_id):

View File

@ -73,9 +73,6 @@ unique_name_in_owner = true
y_sort_enabled = true y_sort_enabled = true
[node name="CharacterBody2D" parent="CB_add_pos" instance=ExtResource("2_nvm7o")] [node name="CharacterBody2D" parent="CB_add_pos" instance=ExtResource("2_nvm7o")]
unit_id = "player"
unit_type = "player"
unit_data_from_id = "test_character_base"
[connection signal="gui_input" from="CanvasLayer/Control" to="." method="_on_control_gui_input"] [connection signal="gui_input" from="CanvasLayer/Control" to="." method="_on_control_gui_input"]
[connection signal="timeout" from="CanvasLayer/Control/HBoxContainer/cacul_num_number" to="." method="_on_cacul_num_number_timeout"] [connection signal="timeout" from="CanvasLayer/Control/HBoxContainer/cacul_num_number" to="." method="_on_cacul_num_number_timeout"]