GameMode.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. let aGameInstance = require('GameInstance');
  2. let aWebView = require("WebView");
  3. let aLib = require("Library");
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. GameStates: {
  8. default: null,
  9. type: cc.Node,
  10. serializable: true,
  11. },
  12. PlayerControllerNode: {
  13. default: null,
  14. type: cc.Node,
  15. serializable: true,
  16. },
  17. TimeLabelNode: {
  18. default: null,
  19. type: cc.Node,
  20. serializable: true,
  21. },
  22. StartButtonNode: {
  23. default: null,
  24. type: cc.Node,
  25. serializable: true,
  26. },
  27. TenSecondChallengeBG: {
  28. default: null,
  29. type: cc.Node,
  30. serializable: true,
  31. },
  32. ReadyGo: {
  33. default: null,
  34. type: cc.Node,
  35. serializable: true,
  36. },
  37. },
  38. onLoad () {
  39. this.GameStatesScp = this.GameStates.getComponent('GameStates');
  40. this.PlayerControllerScp = this.PlayerControllerNode.getComponent('PlayerController');
  41. this.TimeLabelScp = this.TimeLabelNode.getComponent('CountDown');
  42. this.ReadyGoScp = this.ReadyGo.getComponent('ReadyGo');
  43. this.bStart = false;
  44. },
  45. start()
  46. {
  47. //是否在pC
  48. if(!aLib.isMobile()) return;
  49. let self = this;
  50. aWebView.init(self.node, ()=>{
  51. aWebView.onBindHitBoxingPost();
  52. self.node.on('onBoxingPostHit',self.onBoxingPostHit,self);
  53. });
  54. },
  55. onBoxingPostHit(data)
  56. {
  57. if(!this.GameStatesScp.bStart)
  58. {
  59. this.StarGame();
  60. }
  61. else
  62. {
  63. this.PlayerControllerScp.Run();
  64. }
  65. },
  66. //页面退出回调
  67. onQuit(data)
  68. {
  69. console.log('onQuit=',data);
  70. },
  71. //弹出框回调
  72. onQuitModal(res)
  73. {
  74. if (res.data.confirm) {
  75. console.log("退出");
  76. }else if(res.data.cancel){
  77. console.log("取消退出");
  78. }
  79. },
  80. StarGame(target,param)
  81. {
  82. this.PlayerControllerScp.Reset();
  83. if(!this.ReadyGo.active)
  84. {
  85. this.ReadyGo.active = true;
  86. }
  87. this.ReadyGoScp.Play(function(){
  88. this.GameStatesScp.bStart = true;
  89. this.TimeLabelScp.CountDown({'second':10,'millisecond':0},function(){
  90. this.GameStatesScp.bStart = false;
  91. this.GameStatesScp.PunchTimes = 0;
  92. this.StartButtonNode.active = true;
  93. this.TenSecondChallengeBG.active = true;
  94. }.bind(this));
  95. }.bind(this));
  96. this.StartButtonNode.active = false;
  97. this.TenSecondChallengeBG.active = false;
  98. }
  99. });