BasePlayerController.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. let webView = require("../../WebView");
  2. let library = require("../../Library");
  3. let gameConfig = require("../GameConfig");
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. gameStates: {
  8. default: null,
  9. type: cc.Node,
  10. serializable: true,
  11. },
  12. gameMode: {
  13. default: null,
  14. type: cc.Node,
  15. serializable: true,
  16. },
  17. topHole: {
  18. default: null,
  19. type: cc.Node,
  20. serializable: true,
  21. },
  22. leftHole: {
  23. default: null,
  24. type: cc.Node,
  25. serializable: true,
  26. },
  27. rightHole: {
  28. default: null,
  29. type: cc.Node,
  30. serializable: true,
  31. },
  32. avatar: {
  33. default: null,
  34. type: cc.Sprite,
  35. serializable: true,
  36. },
  37. playerName: {
  38. default: null,
  39. type: cc.Label,
  40. serializable: true,
  41. },
  42. score: {
  43. default: null,
  44. type: cc.Label,
  45. serializable: true,
  46. },
  47. gender: {
  48. default: null,
  49. type: cc.Node,
  50. serializable: true,
  51. },
  52. hp: {
  53. default: null,
  54. type: cc.Node,
  55. serializable: true,
  56. },
  57. bAi:true,
  58. id:0,
  59. },
  60. onLoad () {
  61. this.init();
  62. if(cc.sys.isMobile)
  63. {
  64. webView.register(this.node);
  65. }
  66. },
  67. init()
  68. {
  69. this.topHoleScp = this.topHole.getComponent('Actor');
  70. this.leftHoleScp = this.leftHole.getComponent('Actor');
  71. this.rightHoleScp = this.rightHole.getComponent('Actor');
  72. this.gStatesScp = this.gameStates.getComponent('GameStates');
  73. this.gameModeScp = this.gameMode.getComponent('GameMode');
  74. this.pStatesScp = this.node.getComponent('BasePlayerStates');
  75. this.hpScp = this.hp.getComponent('MaskedProgressBar');
  76. this.bCd = false;
  77. },
  78. start()
  79. {
  80. this.score.string = this.pStatesScp.hit.toString();
  81. },
  82. left()
  83. {
  84. if(this.gStatesScp.curretState == this.gStatesScp.finished) return;
  85. if(!this.leftHoleScp.bBeat)
  86. {
  87. this.wrong();
  88. return;
  89. }
  90. this.leftHoleScp.punch(this.bAi);
  91. this.hit();
  92. },
  93. top()
  94. {
  95. if(this.gStatesScp.curretState == this.gStatesScp.finished) return;
  96. if(!this.topHoleScp.bBeat)
  97. {
  98. this.wrong();
  99. return;
  100. }
  101. this.topHoleScp.punch(this.bAi);
  102. this.hit();
  103. },
  104. right()
  105. {
  106. if(this.gStatesScp.curretState == this.gStatesScp.finished) return;
  107. if(!this.rightHoleScp.bBeat)
  108. {
  109. this.wrong();
  110. return;
  111. }
  112. this.rightHoleScp.punch(this.bAi);
  113. this.hit();
  114. },
  115. noDirectionPunch()
  116. {
  117. if(this.gStatesScp.curretState == this.gStatesScp.finished) return;
  118. let arr = this.gStatesScp.appearMouseArr;
  119. for(let i=0;i<arr.length;i++)
  120. {
  121. let obj = arr[i].getComponent('Actor');
  122. if(!obj.bBeat) return;
  123. obj.punch(this.bAi);
  124. this.hit();
  125. }
  126. },
  127. wrong()
  128. {
  129. if(!this.pStatesScp.bPlayDirection) return;
  130. //if miss u will be damaged
  131. let damage = gameConfig.damage;
  132. this.pStatesScp.hp-=damage;
  133. this.hpScp.damage(damage);
  134. this.pStatesScp.miss++;
  135. //if hp = 0 game over
  136. if(this.pStatesScp.hp == 0)
  137. {
  138. this.gameModeScp.gameOver();
  139. }
  140. },
  141. actorComeOut(nameIndex,appearDur){},//for ai playerController
  142. });