1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-05-28 06:51:54 +08:00

feat(多人游戏): 添加多人游戏生成器功能

- 在World场景中添加MultiplayerSpawner节点
- 在WorldManager中实现spawn方法处理本地和多人游戏生成逻辑
- 移除EntityBase中不再需要的多人游戏同步代码
This commit is contained in:
2025-11-14 06:45:54 +08:00
parent 12191f4233
commit 9e0b713ef7
3 changed files with 14 additions and 11 deletions
+4
View File
@@ -72,6 +72,10 @@ texture_filter = 1
script = ExtResource("1_lxsxj")
metadata/_edit_vertical_guides_ = [-1.0, 57.0]
[node name="spawner" type="MultiplayerSpawner" parent="."]
unique_name_in_owner = true
spawn_path = NodePath("..")
[node name="UI" parent="." instance=ExtResource("2_04cdd")]
[node name="camera" type="Camera2D" parent="."]
-11
View File
@@ -105,7 +105,6 @@ var currentStage: int = 0
var spawnTime: float = 0
func _ready():
multiplayer.multiplayer_peer = MultiplayerState.connection
if useStatic:
texture = texture.get_node("staticAnimation")
spawnTime = WorldManager.getTime()
@@ -181,13 +180,6 @@ func _physics_process(_delta: float) -> void:
storeEnergy(randf_range(0.01, 0.05 + fields.get(FieldStore.Entity.ENERGY_REGENERATION) - 1), true)
trailParticle.emitting = trailing
# 同步状态
@rpc("any_peer")
func syncPosition(player: String, newPosition: Vector2, newVelocity: Vector2):
if player != displayName: return
position = newPosition
velocity = newVelocity
# 通用方法
func rebuildWeaponIcons():
if isPlayer():
@@ -224,9 +216,6 @@ func move(direction: Vector2, isSprinting: bool = false):
var currentDirection = sign(direction.x)
if currentDirection != 0:
lastDirection = currentDirection
if MultiplayerState.isMultiplayer:
print("test")
syncPosition.rpc(displayName, position, velocity)
func getSprintInitialDisplace():
return displace(velocity) * sprintMultiplier
func getSprintProgress():
+10
View File
@@ -5,10 +5,12 @@ static var rootNode: WorldManager
static var tree: SceneTree
static var runningTime: int = 0
static var peer: ENetMultiplayerPeer
static var spawner: MultiplayerSpawner
func _ready():
tree = get_tree()
rootNode = self
spawner = $%spawner
ComponentManager.init()
func _physics_process(delta):
runningTime += delta * 1000
@@ -24,6 +26,14 @@ func spawnWave():
nextWave(waves)
if MultiplayerState.isMultiplayer and multiplayer.is_server():
nextWave.rpc(waves)
func spawn(node: Node):
if MultiplayerState.isMultiplayer:
if multiplayer.is_server():
spawner.spawn(node)
else:
add_child(node)
static func getTime():
return runningTime
static func spawnNode(node: Node):
rootNode.spawn(node)