Compare commits
3 Commits
9259865e72
...
6a3823ad16
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a3823ad16 | |||
| 4bfe49d5b1 | |||
| 1d3f580560 |
@@ -36,6 +36,7 @@ signal scene_change_started(scene_name: String)
|
||||
# 场景状态
|
||||
var current_scene_name: String = "" # 当前场景名称
|
||||
var is_changing_scene: bool = false # 是否正在切换场景
|
||||
var _next_scene_position: Variant = null # 下一个场景的初始位置 (Vector2 or null)
|
||||
|
||||
# 场景路径映射表
|
||||
# 将场景名称映射到实际的文件路径
|
||||
@@ -47,7 +48,9 @@ var scene_paths: Dictionary = {
|
||||
"battle": "res://scenes/maps/battle_scene.tscn", # 战斗场景 - 战斗系统
|
||||
"inventory": "res://scenes/ui/InventoryWindow.tscn", # 背包界面
|
||||
"shop": "res://scenes/ui/ShopWindow.tscn", # 商店界面
|
||||
"settings": "res://scenes/ui/SettingsWindow.tscn" # 设置界面
|
||||
"settings": "res://scenes/ui/SettingsWindow.tscn", # 设置界面
|
||||
"room": "res://scenes/Maps/room.tscn", # 房间场景
|
||||
"square": "res://scenes/Maps/square.tscn" # 广场场景
|
||||
}
|
||||
|
||||
# ============ 生命周期方法 ============
|
||||
@@ -134,6 +137,17 @@ func change_scene(scene_name: String, use_transition: bool = true):
|
||||
func get_current_scene_name() -> String:
|
||||
return current_scene_name
|
||||
|
||||
# 设置下一个场景的初始位置
|
||||
func set_next_scene_position(pos: Vector2) -> void:
|
||||
_next_scene_position = pos
|
||||
|
||||
# 获取并清除下一个场景的初始位置
|
||||
func get_next_scene_position() -> Variant:
|
||||
var pos = _next_scene_position
|
||||
_next_scene_position = null
|
||||
return pos
|
||||
|
||||
|
||||
# ============ 场景注册方法 ============
|
||||
|
||||
# 注册新场景
|
||||
|
||||
BIN
assets/sprites/environment/community.png
Normal file
BIN
assets/sprites/environment/community.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.6 MiB |
40
assets/sprites/environment/community.png.import
Normal file
40
assets/sprites/environment/community.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://7j3n0nhg8atb"
|
||||
path="res://.godot/imported/community.png-a8c4bd53b7eaad8a751801ba0eb4ea69.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/sprites/environment/community.png"
|
||||
dest_files=["res://.godot/imported/community.png-a8c4bd53b7eaad8a751801ba0eb4ea69.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/sprites/environment/community_512_512.png
Normal file
BIN
assets/sprites/environment/community_512_512.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 458 KiB |
40
assets/sprites/environment/community_512_512.png.import
Normal file
40
assets/sprites/environment/community_512_512.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://cle66our01dq1"
|
||||
path="res://.godot/imported/community_512_512.png-fa162180b6884ce89074ec9b8b445a11.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/sprites/environment/community_512_512.png"
|
||||
dest_files=["res://.godot/imported/community_512_512.png-fa162180b6884ce89074ec9b8b445a11.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/sprites/environment/fountain_256_192.png
Normal file
BIN
assets/sprites/environment/fountain_256_192.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 78 KiB |
40
assets/sprites/environment/fountain_256_192.png.import
Normal file
40
assets/sprites/environment/fountain_256_192.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://dujutnr03apoj"
|
||||
path="res://.godot/imported/fountain_256_192.png-6fb4e69b74642a426b29631ef7156f53.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/sprites/environment/fountain_256_192.png"
|
||||
dest_files=["res://.godot/imported/fountain_256_192.png-6fb4e69b74642a426b29631ef7156f53.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/sprites/environment/room_512_384.png
Normal file
BIN
assets/sprites/environment/room_512_384.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 255 KiB |
40
assets/sprites/environment/room_512_384.png.import
Normal file
40
assets/sprites/environment/room_512_384.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bjcij2ncikeyw"
|
||||
path="res://.godot/imported/room_512_384.png-339d4ab4d8dc5972ef1c8a09d0380694.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/sprites/environment/room_512_384.png"
|
||||
dest_files=["res://.godot/imported/room_512_384.png-339d4ab4d8dc5972ef1c8a09d0380694.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
32
scenes/Maps/door_teleport.gd
Normal file
32
scenes/Maps/door_teleport.gd
Normal file
@@ -0,0 +1,32 @@
|
||||
extends Area2D
|
||||
|
||||
# 场景名称
|
||||
@export var target_scene_name: String = "room"
|
||||
@export var target_position: Vector2 = Vector2.ZERO # 目标场景的生成位置 (Vector2.ZERO 表示使用默认位置/不设置)
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
# 连接 body_entered 信号
|
||||
body_entered.connect(_on_body_entered)
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
# 检查进入的物体是否为玩家
|
||||
# 我们可以通过多种方式检查:
|
||||
# 1. 检查是否在 "player" 组中 (推荐,但需要设置)
|
||||
# 2. 检查是否有特定方法 (如 _handle_movement)
|
||||
# 3. 检查类名 (如果 scripts/characters/player.gd 有 class_name)
|
||||
|
||||
# 这里使用方法检查作为一种鲁棒的方式,或者检查是否为 CharacterBody2D 且父节点层级符合预期
|
||||
# 最简单直接的方式是检查是否有 _handle_movement 方法,这是 player.gd 特有的
|
||||
if body.has_method("_handle_movement"):
|
||||
print("玩家进入传送门,正在切换到场景: ", target_scene_name)
|
||||
_teleport_player()
|
||||
|
||||
func _teleport_player() -> void:
|
||||
# 如果设置了目标位置,则传递给 SceneManager
|
||||
if target_position != Vector2.ZERO:
|
||||
SceneManager.set_next_scene_position(target_position)
|
||||
|
||||
# 使用 SceneManager 切换场景
|
||||
# 确保 SceneManager 已经注册了相关场景路径
|
||||
SceneManager.change_scene(target_scene_name)
|
||||
1
scenes/Maps/door_teleport.gd.uid
Normal file
1
scenes/Maps/door_teleport.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://3wghcufucve5
|
||||
690
scenes/Maps/room.tscn
Normal file
690
scenes/Maps/room.tscn
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -13,9 +13,17 @@ const MOVE_SPEED = 200.0
|
||||
var last_direction := "down"
|
||||
|
||||
func _ready() -> void:
|
||||
# 检查是否有初始位置设置
|
||||
call_deferred("_check_spawn_position")
|
||||
|
||||
# 播放初始动画
|
||||
if animation_player.has_animation("idle"):
|
||||
animation_player.play("idle")
|
||||
|
||||
func _check_spawn_position() -> void:
|
||||
var spawn_pos = SceneManager.get_next_scene_position()
|
||||
if spawn_pos != null:
|
||||
global_position = spawn_pos
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
_handle_movement(delta)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
[gd_scene load_steps=13 format=3 uid="uid://b2f8e24plwqgj"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://btka26hrcvgen" path="res://Scenes/characters/player.gd" id="1_script"]
|
||||
[ext_resource type="Texture2D" uid="uid://dpym0k5vurobw" path="res://assets/characters/player_spritesheet.png" id="2_texture"]
|
||||
[ext_resource type="Texture2D" uid="uid://cghab1hkx5lg5" path="res://assets/characters/player_spritesheet.png" id="2_texture"]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_1"]
|
||||
radius = 16.0
|
||||
radius = 21.0
|
||||
height = 48.0
|
||||
|
||||
[sub_resource type="Animation" id="Animation_idle_down"]
|
||||
@@ -145,14 +145,14 @@ tracks/0/keys = {
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_1"]
|
||||
_data = {
|
||||
"idle_down": SubResource("Animation_idle_down"),
|
||||
"idle_left": SubResource("Animation_idle_left"),
|
||||
"idle_right": SubResource("Animation_idle_right"),
|
||||
"idle_up": SubResource("Animation_idle_up"),
|
||||
"walk_down": SubResource("Animation_walk_down"),
|
||||
"walk_left": SubResource("Animation_walk_left"),
|
||||
"walk_right": SubResource("Animation_walk_right"),
|
||||
"walk_up": SubResource("Animation_walk_up")
|
||||
&"idle_down": SubResource("Animation_idle_down"),
|
||||
&"idle_left": SubResource("Animation_idle_left"),
|
||||
&"idle_right": SubResource("Animation_idle_right"),
|
||||
&"idle_up": SubResource("Animation_idle_up"),
|
||||
&"walk_down": SubResource("Animation_walk_down"),
|
||||
&"walk_left": SubResource("Animation_walk_left"),
|
||||
&"walk_right": SubResource("Animation_walk_right"),
|
||||
&"walk_up": SubResource("Animation_walk_up")
|
||||
}
|
||||
|
||||
[node name="Player" type="CharacterBody2D"]
|
||||
@@ -160,18 +160,17 @@ script = ExtResource("1_script")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
position = Vector2(1.5000005, -24.5)
|
||||
scale = Vector2(1, 1)
|
||||
texture = ExtResource("2_texture")
|
||||
hframes = 4
|
||||
vframes = 4
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, -24)
|
||||
position = Vector2(2, -24)
|
||||
shape = SubResource("CapsuleShape2D_1")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_1")
|
||||
&"": SubResource("AnimationLibrary_1")
|
||||
}
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
|
||||
Reference in New Issue
Block a user