GameMode.js 2.7 KB

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