ActionPlay.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. speed:0,
  5. playerControllerScp:null,
  6. gameStatesScp:null,
  7. nameIndex:0
  8. },
  9. onLoad () {
  10. this.bMoving = true;
  11. this.bHightLight = false;
  12. this.bHit = false;
  13. //注册Touch事件 TOUCH_START TOUCH_END TOUCH_MOVE
  14. this.node.on(cc.Node.EventType.TOUCH_START,this.touchBegin,this);
  15. this.node.on(cc.Node.EventType.TOUCH_MOVE,this.touchBegin,this);
  16. this.node.on(cc.Node.EventType.TOUCH_END,this.touchBegin,this);
  17. this.actionBarWidth = 720;
  18. },
  19. touchBegin:function(event) {
  20. this.hit();
  21. },
  22. update (dt) {
  23. if(this.bMoving)
  24. {
  25. this.node.x+=this.speed * dt * 30;
  26. if(this.node.x>this.actionBarWidth)
  27. // if(this.node.x>400)
  28. {
  29. this.bMoving = false;
  30. this.node.destroy();
  31. return;
  32. }
  33. if(this.node.x >= -100 && this.node.x <= +100)
  34. // if(this.node.x >= -100 && this.node.x <= 100)
  35. {
  36. if(!this.bHightLight)
  37. {
  38. this.node.getChildByName('1').active = false;
  39. this.node.getChildByName('2').active = true;
  40. this.node.getChildByName('3').active = false;
  41. this.gameStatesScp.hightLightActionArr.push(this);
  42. this.bHightLight = true;
  43. }
  44. }
  45. if(this.node.x > 100)
  46. {
  47. if(this.bHightLight)
  48. {
  49. this.node.getChildByName('1').active = false;
  50. this.node.getChildByName('2').active = false;
  51. this.node.getChildByName('3').active = true;
  52. if(!this.bHit){
  53. //如果没有打击,判断miss
  54. this.gameStatesScp.missCount ++;
  55. }
  56. for(let i=0;i<this.gameStatesScp.hightLightActionArr.length;i++)
  57. {
  58. if(this.gameStatesScp.hightLightActionArr[i] == this)
  59. {
  60. this.gameStatesScp.hightLightActionArr.splice(i,1);
  61. break;
  62. }
  63. }
  64. this.bHightLight = false;
  65. }
  66. }
  67. }
  68. },
  69. hit()
  70. {
  71. if(this.bHightLight && !this.bHit)
  72. {
  73. this.bHit =true;
  74. this.node.getChildByName('explosion').active = true;
  75. this.node.getChildByName('1').active = false;
  76. this.node.getChildByName('2').active = false;
  77. this.node.getChildByName('3').active = false;
  78. this.playerControllerScp.triggleCombo(this.playerControllerScp);
  79. this.gameStatesScp.hitCount++;
  80. this.bMoving = false;
  81. this.scheduleOnce(function () {
  82. this.node.destroy();
  83. },1);
  84. }
  85. }
  86. });