fishingAction.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * 鱼游动动作
  3. */
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. },
  8. onLoad () {
  9. this.windowSize=cc.view.getVisibleSize();
  10. this.leve = this.getComponent(cc.BoxCollider).tag;
  11. this.flag = true;
  12. if (this.leve >= 21 ) {
  13. this.node.getChildByName("light").runAction(cc.repeatForever(cc.sequence(cc.delayTime(0) , cc.rotateBy(7, 360))));
  14. }
  15. },
  16. start () {
  17. this.node.x = window.Utils.random(-10, this.windowSize.width + 10);
  18. this.bathingCourse(window.Utils.random(1,2));
  19. },
  20. /**
  21. * 鱼游动路线
  22. *@param {*} value 动作类型值
  23. */
  24. bathingCourse : function (value) {
  25. var b = this.node.x < this.windowSize.width / 2;
  26. if (value == 1) {
  27. this.course1(b);
  28. } else if (value == 2) {
  29. this.course2(b);
  30. }
  31. // this.course3();
  32. },
  33. /**
  34. * 循环左右游
  35. * @param {*} b 方向
  36. */
  37. course1: function(b) {
  38. var x = 0;
  39. if (b) {
  40. x = this.windowSize.width + 50;
  41. this.node.scaleX = 1;
  42. } else {
  43. x = -50;
  44. this.node.scaleX = -1;
  45. }
  46. var dl = parseFloat(Math.abs(x - this.node.x) / 1000);
  47. var speed = window.Utils.random(2,6);
  48. var move = cc.moveTo(dl * (speed + 0.5), cc.v2(x, this.node.y));
  49. this.node.runAction(cc.sequence(move , cc.callFunc(function() {
  50. this.course1(this.node.x < this.windowSize.width / 2);
  51. }.bind(this))));
  52. },
  53. /**
  54. * 循环斜着游
  55. * @param {*} b 方向
  56. */
  57. course2: function(b) {
  58. var x = 0, y = 0;
  59. if (b) {
  60. x = this.windowSize.width + 50;
  61. y = this.node.y + 200;
  62. this.node.scaleX = 1;
  63. } else {
  64. x = -50;
  65. y = this.node.y - 200;
  66. this.node.scaleX = -1;
  67. }
  68. var dl = parseFloat(Math.abs(x - this.node.x) / 1000);
  69. var move = cc.moveTo(dl * 3, cc.v2(x, y));
  70. this.node.runAction(cc.sequence(move , cc.callFunc(function() {
  71. this.course2(this.node.x < this.windowSize.width / 2);
  72. }.bind(this))));
  73. },
  74. /**
  75. * 看到鱼钩快速靠近
  76. * @param {*} pos
  77. */
  78. course3: function(pos) {
  79. console.log("--course3---");
  80. // this.node.stopAllActions();
  81. var bezier = [cc.v2(0,0), cc.v2(50,100), cc.v2(100,0)];
  82. var bezierBy = cc.bezierBy(0.8, bezier);
  83. var fc = cc.callFunc(function(){
  84. // sp.destroy();
  85. },this);
  86. this.node.runAction(cc.sequence(bezierBy, fc));
  87. },
  88. /**
  89. * 看到鱼钩快速躲闪
  90. * @param {*} pos
  91. */
  92. course4: function() {
  93. },
  94. course5: function() {
  95. },
  96. course6: function() {
  97. },
  98. course7: function() {
  99. },
  100. update (dt) {
  101. return;
  102. },
  103. });