补充注释
This commit is contained in:
parent
76b688e377
commit
f5e35ccd4a
@ -13,9 +13,12 @@ export interface GameSystemState {
|
||||
nextArrowId: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 前后端复用的状态计算模块
|
||||
*/
|
||||
export class GameSystem {
|
||||
|
||||
// State (Render Pull)
|
||||
// 当前状态
|
||||
private _state: GameSystemState = {
|
||||
now: 0,
|
||||
players: [],
|
||||
@ -26,11 +29,12 @@ export class GameSystem {
|
||||
return this._state
|
||||
}
|
||||
|
||||
// 重设状态
|
||||
reset(state: GameSystemState) {
|
||||
this._state = Object.merge({}, state);
|
||||
}
|
||||
|
||||
// Input
|
||||
// 应用输入,计算状态变更
|
||||
applyInput(input: GameSystemInput) {
|
||||
if (input.type === 'PlayerMove') {
|
||||
let player = this._state.players.find(v => v.id === input.playerId);
|
||||
|
@ -159,12 +159,13 @@ export class GameScene extends Component {
|
||||
let sceneOffset = playerNode.forward.clone().normalize().multiplyScalar(gameConfig.arrowDistance);
|
||||
// 攻击落点(逻辑层坐标)
|
||||
let targetPos = new Vec2(playerState.pos.x, playerState.pos.y).add2f(sceneOffset.x, -sceneOffset.z);
|
||||
// 发送输入
|
||||
this.gameManager.sendClientInput({
|
||||
type: 'PlayerAttack',
|
||||
// 显示坐标 —> 逻辑坐标
|
||||
targetPos: { x: targetPos.x, y: targetPos.y },
|
||||
targetTime: this.gameManager.state.now + gameConfig.arrowFlyTime
|
||||
} as any)
|
||||
})
|
||||
|
||||
// 冷却时间 1 秒
|
||||
this.btnAttack.getComponent(Button)!.interactable = false;
|
||||
|
@ -4,11 +4,16 @@ import { ClientInput, MsgClientInput } from "../shared/protocols/client/MsgClien
|
||||
import { MsgFrame } from "../shared/protocols/server/MsgFrame";
|
||||
import { serviceProto, ServiceType } from "../shared/protocols/serviceProto";
|
||||
|
||||
/**
|
||||
* 前端游戏状态管理
|
||||
* 主要用于实现前端的预测和和解
|
||||
*/
|
||||
export class GameManager {
|
||||
|
||||
client: WsClient<ServiceType>;
|
||||
|
||||
|
||||
gameSystem = new GameSystem();
|
||||
|
||||
lastServerState: GameSystemState = this.gameSystem.state;
|
||||
lastRecvSetverStateTime = 0;
|
||||
selfPlayerId: number = -1;
|
||||
|
Loading…
Reference in New Issue
Block a user