1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-05-28 06:51:54 +08:00
Files
Dog-Lynx-And-HCN/scripts/Tools/Managers/MultiplayerState.gd
T
fallingshrimp 8ed0837c9d feat(多人游戏): 实现多人游戏状态同步和单机/多人模式切换
添加多人游戏状态管理,包括连接状态和玩家名称同步
修改WorldManager和EntityBase以支持多人游戏逻辑
在Starter面板中实现单机和多人游戏启动功能
2025-11-13 22:23:39 +08:00

43 lines
1.3 KiB
GDScript

@tool
class_name MultiplayerState
enum ConnectionState {
DISCONNECTED,
CONNECTING,
CONNECTED_HOST,
CONNECTED_CLIENT,
}
static var stateTextMap = {
ConnectionState.DISCONNECTED: "未连接到服务器。",
ConnectionState.CONNECTING: "正在连接到服务器...",
ConnectionState.CONNECTED_HOST: "服务器启动成功!",
ConnectionState.CONNECTED_CLIENT: "已连接到服务器!",
}
static var stateColorMap = {
ConnectionState.DISCONNECTED: Color.RED,
ConnectionState.CONNECTING: Color.YELLOW,
ConnectionState.CONNECTED_HOST: Color.GREEN,
ConnectionState.CONNECTED_CLIENT: Color.GREEN,
}
static var isMultiplayer: bool = false
static var state: ConnectionState = ConnectionState.DISCONNECTED
static var playerName: String
static var connection: ENetMultiplayerPeer
static var maxPlayer: int = 10
static func isConnected():
return [ConnectionState.CONNECTED_HOST, ConnectionState.CONNECTED_CLIENT].has(state)
static func launchServer(port: int) -> ENetMultiplayerPeer:
var peer = ENetMultiplayerPeer.new()
peer.create_server(port, maxPlayer)
state = ConnectionState.CONNECTED_HOST
return peer
static func connectClient(host: String, port: int) -> ENetMultiplayerPeer:
var peer = ENetMultiplayerPeer.new()
peer.create_client(host, port)
state = ConnectionState.CONNECTED_CLIENT
return peer