PlayerController.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. cc.Class({
  2. extends: require("BasePlayerController"),
  3. properties: {
  4. TouchNode: cc.Node,
  5. charactor: cc.Node,
  6. },
  7. onLoad() {
  8. this._super();
  9. this._Statepassivity = this.Statepassivity;
  10. this._RightJayShow = this.RightJayShow; //出右拳
  11. this._LeftJayShow = this.LeftJayShow; //出左拳
  12. this._RightDodge = this.RightDodge; //右躲闪
  13. this._LeftDodg = this.LeftDodg; //左躲闪
  14. this._Defence = this.Defence; //防御
  15. this._Hurt = this.Hurt;
  16. this._CriticalStrike = this.CriticalStrike; //暴击
  17. this._DoubleHit = this.DoubleHit; //连击
  18. this._BeCriticalStrike = this.BeCriticalStrike; //被暴击
  19. this._BeDoubleHit = this.BeDoubleHit; //被连击
  20. //注册回调事件
  21. let Self = this;
  22. this.TouchNode.on('gesture', function(event) {
  23. console.log(event.name);
  24. Self.Gesture(event.name);
  25. });
  26. },
  27. start() {
  28. this.init();
  29. },
  30. init() {
  31. //角色脚本
  32. this.ctorScp = this.charactor.getComponent('BaseCharactor');
  33. this.statesScp = this.charactor.getComponent('PlayerStates');
  34. },
  35. Gesture(name) {
  36. var randomnum_1 = parseInt(Math.round(Math.random() * 98 + 1)); //(0-100]
  37. var randomnum_2 = parseInt(Math.round(Math.random() + 1)); //[1-2]
  38. console.log(randomnum_1, randomnum_2);
  39. if (name == 'right_top') {
  40. if (randomnum_1 >= 1 && randomnum_1 <= 10) {
  41. //出现暴击或者连击
  42. if (randomnum_2 == 1) {
  43. //暴击
  44. this._CriticalStrike = true;
  45. this.ctorScp.attack(2);
  46. }
  47. if (randomnum_2 == 2) {
  48. //连击
  49. this._DoubleHit = true;
  50. this.ctorScp.attack(3);
  51. }
  52. } else { //普攻状态 普攻动作
  53. this._RightJayShow = true;
  54. this.ctorScp.attack(1);
  55. }
  56. } else if (name == 'left_top') {
  57. if (randomnum_1 >= 1 && randomnum_1 <= 10) {
  58. //出现暴击或者连击
  59. if (randomnum_2 == 1) {
  60. //暴击
  61. this._CriticalStrike = true;
  62. this.ctorScp.attack(2);
  63. }
  64. if (randomnum_2 == 2) {
  65. //连击
  66. this._DoubleHit = true;
  67. this.ctorScp.attack(3);
  68. }
  69. } else { //普攻状态 普攻动作
  70. this._LeftJayShow = true;
  71. this.ctorScp.attack(0);
  72. }
  73. } else if (name == 'right_down') {
  74. this._RightDodge = true;
  75. this.ctorScp.dodge(0);
  76. } else if (name == 'left_down') {
  77. this._LeftDodg = true;
  78. this.ctorScp.dodge(1);
  79. } else if (name == 'down') {
  80. this._Defence = true;
  81. this.ctorScp.block();
  82. }
  83. },
  84. // update (dt) {},
  85. });