PlayerController.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. let gameConfig = require("GameConfig");
  2. let webView = require("../WebView");
  3. cc.Class({
  4. extends: require("BasePlayerController"),
  5. properties: {
  6. hitAudio: {
  7. default: null,
  8. type: cc.AudioClip,
  9. serializable: true,
  10. },
  11. missAudio: {
  12. default: null,
  13. type: cc.AudioClip,
  14. serializable: true,
  15. },
  16. bloodFlash: {
  17. default: null,
  18. type: cc.Node,
  19. serializable: true,
  20. },
  21. },
  22. start()
  23. {
  24. this._super();
  25. if(cc.sys.isMobile)
  26. {
  27. this.avatar.spriteFrame = webView.avatarSpriteFrame;
  28. this.avatar.node.width = 80;
  29. this.avatar.node.height = 80;
  30. this.playerName.string = webView.userName;
  31. this.gender.string = webView.gender;
  32. webView.onBindHitBoxingPost();
  33. webView.onAddQuitModalListener();//添加退出事件
  34. this.node.on('onBoxingPostHit',this.onBoxingPostHit,this);
  35. this.node.on('onQuit',this.onQuit,this);
  36. this.node.on('onQuitModal',this.onQuitModal,this);
  37. }
  38. //注册Touch事件
  39. this.topHole.on(cc.Node.EventType.TOUCH_START,this.top,this);
  40. this.leftHole.on(cc.Node.EventType.TOUCH_START,this.left,this);
  41. this.rightHole.on(cc.Node.EventType.TOUCH_START,this.right,this);
  42. this.flashScp = this.bloodFlash.getComponent('BloodyFlash');
  43. this.gStatesScp.playerStatesArr.unshift(this.pStatesScp);
  44. },
  45. hit()
  46. {
  47. this.pStatesScp.hit++;
  48. this.score.string = this.pStatesScp.hit.toString();
  49. cc.audioEngine.play(this.hitAudio, false, 1);
  50. },
  51. wrong()
  52. {
  53. if(!this.pStatesScp.bPlayDirection) return;
  54. this._super();
  55. this.flashScp.flash();
  56. cc.audioEngine.play(this.missAudio, false, 1);
  57. },
  58. onBoxingPostHit(data)
  59. {
  60. if(this.bCd) return;
  61. this.bCd = true;
  62. let self = this;
  63. this.scheduleOnce(function () {
  64. self.bCd = false;
  65. },0.1);
  66. if(this.gStatesScp.curretState == this.gStatesScp.finished) return;
  67. console.log('data.ename='+data.ename);
  68. if(data.direction == 'straightPunch')
  69. {
  70. this.top();
  71. }
  72. if(data.direction == 'leftPunch')
  73. {
  74. this.left();
  75. }
  76. if(data.direction == 'rightPunch')
  77. {
  78. this.right();
  79. }
  80. // else if(data.ename == 'hit')
  81. // {
  82. // this.noDirectionPunch();
  83. // }
  84. },
  85. //页面退出回调
  86. onQuit(data)
  87. {
  88. // console.log('onQuit=',data);
  89. },
  90. //弹出框回调
  91. onQuitModal(res)
  92. {
  93. if (res.data.confirm) {
  94. // let kCal = this.gStatesScp.hitCount*webView.caloriUnit+this.gStatesScp.currentTime*300/3600;
  95. let kCal = this.pStatesScp.hit*webView.kCalUnit;
  96. // console.log('webView.kCalUnit=',webView.kCalUnit);
  97. // console.log('this.pStatesScp0.hit=',this.pStatesScp.hit);
  98. webView.uploadInfo(0,this.gStatesScp.currentTime, kCal);
  99. webView.closeGame();
  100. }else if(res.data.cancel){
  101. console.log("取消");
  102. }
  103. }
  104. });