创建新工程
This commit is contained in:
81
scripts/TestGameplay.gd
Normal file
81
scripts/TestGameplay.gd
Normal file
@@ -0,0 +1,81 @@
|
||||
extends Node
|
||||
## 临时测试场景脚本
|
||||
## 用于在没有服务器的情况下测试游戏玩法
|
||||
|
||||
@onready var office = $DatawhaleOffice
|
||||
@onready var player = $DatawhaleOffice/Characters/PlayerCharacter
|
||||
|
||||
var input_handler: Node = null
|
||||
|
||||
func _ready():
|
||||
print("=== Test Gameplay Scene ===")
|
||||
print("Controls:")
|
||||
print(" WASD / Arrow Keys - Move player")
|
||||
print(" E - Interact")
|
||||
print(" ESC - Quit")
|
||||
print("========================")
|
||||
|
||||
# 初始化玩家
|
||||
_setup_player()
|
||||
|
||||
# 创建输入处理器
|
||||
_setup_input()
|
||||
|
||||
# 设置相机跟随
|
||||
if office.has_method("set_camera_target"):
|
||||
office.set_camera_target(player)
|
||||
print("Camera following player")
|
||||
|
||||
func _setup_player():
|
||||
"""设置玩家角色"""
|
||||
if player:
|
||||
# 设置玩家数据
|
||||
var player_data = {
|
||||
"id": "test_player",
|
||||
"name": "Test Player",
|
||||
"position": {"x": 1000, "y": 750},
|
||||
"is_online": true
|
||||
}
|
||||
player.initialize(player_data)
|
||||
|
||||
# 设置随机颜色
|
||||
var sprite = player.get_node_or_null("CharacterSprite")
|
||||
if sprite and sprite.has_method("set_character_color"):
|
||||
var random_color = CharacterSprite.generate_random_color()
|
||||
sprite.set_character_color(random_color)
|
||||
|
||||
print("Player initialized at position: ", player.global_position)
|
||||
|
||||
func _setup_input():
|
||||
"""设置输入处理"""
|
||||
input_handler = preload("res://scripts/InputHandler.gd").new()
|
||||
input_handler.name = "InputHandler"
|
||||
add_child(input_handler)
|
||||
|
||||
# 连接输入信号
|
||||
input_handler.move_input.connect(_on_move_input)
|
||||
input_handler.interact_input.connect(_on_interact_input)
|
||||
|
||||
print("Input handler ready")
|
||||
|
||||
func _on_move_input(direction: Vector2):
|
||||
"""处理移动输入"""
|
||||
if player:
|
||||
player.move_to(direction)
|
||||
|
||||
func _on_interact_input():
|
||||
"""处理交互输入"""
|
||||
print("Interact pressed!")
|
||||
# 可以在这里添加交互逻辑
|
||||
|
||||
func _input(event):
|
||||
"""处理输入事件"""
|
||||
if event.is_action_pressed("ui_cancel"):
|
||||
print("Quitting test scene...")
|
||||
get_tree().quit()
|
||||
|
||||
func _process(_delta):
|
||||
"""每帧更新"""
|
||||
# 显示玩家位置(用于调试)
|
||||
if player and Input.is_action_just_pressed("ui_select"):
|
||||
print("Player position: ", player.global_position)
|
||||
Reference in New Issue
Block a user