GameState.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { _decorator, Component, find, Label } from 'cc';
  2. import { JCMGO } from '../ThirdParty/JCMGO';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('GameState')
  5. export class GameState extends Component {
  6. /**权威状态 */
  7. authGameSystemState: GameSystemState;
  8. /**当前状态 */
  9. gameSystemState: GameSystemState;
  10. /**本地存储的模拟服务器帧(用于本地预测) */
  11. localMoniFrames: JCMGO.Frame[] = [];
  12. /**上一次上传帧输入到服务器的标志 */
  13. lastSign: number = 0;
  14. /**最后一次上传帧输入的时间点 */
  15. lastUploadTime: number = 0;
  16. /**我在房间内的索引位置 */
  17. myPlayerIndex: number = 0;
  18. /**AI标志数组 */
  19. aiFlags: boolean[] = [];
  20. /**房间匹配完成后的玩家信息列表 */
  21. matchPlayerInfos: MatchPlayerInfo[];
  22. /**帧同步是否已经开始 */
  23. isFrameSyncStarted: boolean = false;
  24. onLoad() {
  25. let gameSystemState: GameSystemState = {
  26. time: 0,
  27. playerStates: [],
  28. winPlayerIndex: -1,
  29. readyComplete: false,
  30. gameOver: false,
  31. };
  32. for (let i = 0; i < window.gm.config.maxMembers; i++) {
  33. let playerState: PlayerState = {
  34. index: i,
  35. moveX: 0,
  36. speedX: 0,
  37. lastAccTime: 0,
  38. accCount: 0,
  39. };
  40. gameSystemState.playerStates.push(playerState);
  41. }
  42. this.authGameSystemState = gameSystemState;
  43. this.gameSystemState = JCMGO.ObjectUtils.merge({}, this.authGameSystemState) as GameSystemState;
  44. }
  45. }