补充注释

This commit is contained in:
King Wang 2021-12-06 23:29:49 +08:00
parent 76b688e377
commit f5e35ccd4a
3 changed files with 14 additions and 4 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;