mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-28 06:51:54 +08:00
feat(多人游戏): 实现多人游戏状态同步和单机/多人模式切换
添加多人游戏状态管理,包括连接状态和玩家名称同步 修改WorldManager和EntityBase以支持多人游戏逻辑 在Starter面板中实现单机和多人游戏启动功能
This commit is contained in:
@@ -105,6 +105,7 @@ 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()
|
||||
@@ -170,7 +171,7 @@ func _physics_process(_delta: float) -> void:
|
||||
velocity = Vector2.ZERO
|
||||
if (isPlayer() or is_instance_valid(currentFocusedBoss)) and not charginup and canRunAi:
|
||||
if isPlayer():
|
||||
if MultiplayerState.playerName == displayName:
|
||||
if MultiplayerState.playerName == displayName or not MultiplayerState.isMultiplayer:
|
||||
ai()
|
||||
else:
|
||||
ai()
|
||||
@@ -180,6 +181,13 @@ 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():
|
||||
@@ -216,6 +224,9 @@ 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():
|
||||
@@ -437,6 +448,7 @@ func kill():
|
||||
static func generatePlayer(playerName: String):
|
||||
var player = generate(ComponentManager.getCharacter("Rooster"), Vector2.ZERO, false, false, true)
|
||||
player.displayName = playerName
|
||||
player.name = "Player_%s" % playerName
|
||||
return player
|
||||
static func generate(
|
||||
entity: PackedScene,
|
||||
|
||||
Reference in New Issue
Block a user