地图尺寸改小,同步位置放大1000倍取整
This commit is contained in:
@@ -3,6 +3,7 @@ import { playerManager } from "../managers/PlayerManager";
|
||||
import { MsgPlayerMove } from "../shared/protocols/MsgPlayerMove";
|
||||
import { MsgReqMove } from "../shared/protocols/MsgReqMove";
|
||||
import { broadcastToAll } from "../utils/broadcast";
|
||||
import { clientToGamePosition, gameToClientPosition } from "../utils/coordinate";
|
||||
|
||||
/**
|
||||
* 移动消息处理器
|
||||
@@ -60,9 +61,12 @@ export default async function (call: MsgCall<MsgReqMove>) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 将客户端坐标(放大1000倍)转换为游戏内坐标
|
||||
const gamePosition = clientToGamePosition({ x, y });
|
||||
|
||||
try {
|
||||
// 尝试更新玩家位置
|
||||
const success = playerManager.updatePlayerPosition(playerId, x, y);
|
||||
// 尝试更新玩家位置(使用游戏内坐标)
|
||||
const success = playerManager.updatePlayerPosition(playerId, gamePosition.x, gamePosition.y);
|
||||
|
||||
if (!success) {
|
||||
call.conn.sendMsg('ResMove', {
|
||||
@@ -72,10 +76,9 @@ export default async function (call: MsgCall<MsgReqMove>) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取更新后的位置
|
||||
const newPosition = { x, y };
|
||||
|
||||
// 广播移动消息给所有其他玩家
|
||||
// 获取更新后的位置(转换为客户端坐标)
|
||||
const newPosition = gameToClientPosition(gamePosition);
|
||||
// 广播移动消息给所有其他玩家(使用客户端坐标)
|
||||
const moveMsg: MsgPlayerMove = {
|
||||
playerId: player.id,
|
||||
playerName: player.name,
|
||||
@@ -92,7 +95,7 @@ export default async function (call: MsgCall<MsgReqMove>) {
|
||||
position: newPosition
|
||||
});
|
||||
|
||||
console.log(`玩家 ${player.name} 移动到 (${x}, ${y})`);
|
||||
console.log(`玩家 ${player.name} 移动到游戏内坐标 (${gamePosition.x}, ${gamePosition.y}),客户端坐标 (${newPosition.x}, ${newPosition.y})`);
|
||||
|
||||
} catch (error) {
|
||||
console.error('移动失败:', error);
|
||||
|
||||
Reference in New Issue
Block a user