AniControl.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. import { InterFullAdType, VideoAdType } from "../data/GameData";
  2. const { ccclass, property } = cc._decorator;
  3. @ccclass
  4. export default class AniControl extends cc.Component {
  5. @property({ displayName: 'bird_1', type: cc.Animation })
  6. private flyBird_1: cc.Animation = null;
  7. @property({ displayName: 'bird_2', type: cc.Animation })
  8. private flyBird_2: cc.Animation = null;
  9. @property({ displayName: 'star_1', type: cc.Animation })
  10. private star_1: cc.Animation = null;
  11. @property({ displayName: 'star_2', type: cc.Animation })
  12. private star_2: cc.Animation = null;
  13. @property({ displayName: 'star_3', type: cc.Animation })
  14. private star_3: cc.Animation = null;
  15. @property({ displayName: 'dog', type: cc.Animation })
  16. private dogMove: cc.Animation = null;
  17. @property({ displayName: 'duck', type: cc.Animation })
  18. private moveDuck: cc.Animation = null;
  19. @property({ displayName: 'moveSheep', type: cc.Animation })
  20. private moveSheep: cc.Animation = null;
  21. @property({ displayName: 'sheep', type: cc.Animation })
  22. private sheep: cc.Animation = null;
  23. @property({ displayName: '红包按钮', type: cc.Node })
  24. private hb_btn: cc.Node = null;
  25. private starPos_1: cc.Vec2 = cc.Vec2.ZERO;
  26. private starPos_2: cc.Vec2 = cc.Vec2.ZERO;
  27. private starPos_3: cc.Vec2 = cc.Vec2.ZERO;
  28. private time_1: number = 8;
  29. private time_2: number = 16;
  30. private time_3: number = 22;
  31. private isShow_1: boolean = false;
  32. private isShow_2: boolean = false;
  33. private isShow_3: boolean = false;
  34. private sheepMoveEnd: boolean = false;
  35. start() {
  36. this.doFlyBirdLogic();
  37. //this.doStarLogic();
  38. this.doDogMoveLogic();
  39. //this.doDuckMoveLogic();
  40. let data = gData.gameData.funOpenData;
  41. if(data[9] == '1')
  42. {
  43. this.doSheepMoveLogic();
  44. }
  45. }
  46. private doFlyBirdLogic() {
  47. let time = mk.math.random(5, 15);
  48. cc.tween(this.flyBird_1.node).delay(time).call(() => {
  49. this.flyBird_1.node.active = true;
  50. }).start();
  51. this.flyBird_1.on('finished', this.flyBirdFinished_1, this);
  52. time = mk.math.random(5, 15);
  53. cc.tween(this.flyBird_2.node).delay(time).call(() => {
  54. this.flyBird_2.node.active = true;
  55. }).start();
  56. this.flyBird_2.on('finished', this.flyBirdFinished_2, this)
  57. }
  58. private flyBirdFinished_1() {
  59. let time = mk.math.random(5, 15);
  60. this.flyBird_1.node.active = false;
  61. cc.Tween.stopAllByTarget(this.flyBird_1.node);
  62. cc.tween(this.flyBird_1.node).delay(time).call(() => {
  63. this.flyBird_1.node.active = true;
  64. this.flyBird_1.play();
  65. }).start();
  66. }
  67. private flyBirdFinished_2() {
  68. let time = mk.math.random(5, 15);
  69. this.flyBird_2.node.active = false;
  70. cc.Tween.stopAllByTarget(this.flyBird_2.node);
  71. cc.tween(this.flyBird_2.node).delay(time).call(() => {
  72. this.flyBird_2.node.active = true;
  73. this.flyBird_2.play();
  74. }).start();
  75. }
  76. private doStarLogic() {
  77. this.starPos_1 = this.star_1.node.getPosition();
  78. this.starPos_2 = this.star_2.node.getPosition();
  79. this.starPos_3 = this.star_3.node.getPosition();
  80. }
  81. private doDogMoveLogic() {
  82. let time = mk.math.random(5, 8);
  83. cc.tween(this.dogMove.node).delay(time).call(() => {
  84. this.dogMove.node.active = true;
  85. this.dogMove.play();
  86. }).start();
  87. this.dogMove.on('finished', this.moveDogFinished, this);
  88. }
  89. private moveDogFinished() {
  90. let time = mk.math.random(5, 8);
  91. this.dogMove.node.active = false;
  92. this.dogMove.node.scaleX = 1;
  93. cc.Tween.stopAllByTarget(this.dogMove.node);
  94. cc.tween(this.dogMove.node).delay(time).call(() => {
  95. this.dogMove.node.active = true;
  96. this.dogMove.play();
  97. }).start();
  98. }
  99. private doDuckMoveLogic() {
  100. let time = mk.math.random(5, 8);
  101. cc.tween(this.moveDuck.node).delay(time).call(() => {
  102. this.moveDuck.node.active = true;
  103. this.moveDuck.play();
  104. }).start();
  105. this.moveDuck.on('finished', this.moveDuckFinished, this);
  106. }
  107. private moveDuckFinished(event) {
  108. let time = mk.math.random(5, 8);
  109. cc.tween(this.moveDuck.node).delay(time).call(() => {
  110. this.moveDuck.play();
  111. }).start();
  112. }
  113. private doSheepMoveLogic() {
  114. this.sheepMoveEnd = false;
  115. let time = mk.math.random(5, 8);
  116. cc.tween(this.moveSheep.node).delay(time).call(() => {
  117. this.moveSheep.node.active = true;
  118. this.sheep.play('sheepMove');
  119. this.moveSheep.play();
  120. }).start();
  121. this.moveSheep.on('finished', this.moveSheepFinished, this);
  122. }
  123. private moveSheepFinished(event) {
  124. this.sheepMoveEnd = true;
  125. // let time = mk.math.random(5, 8);
  126. // cc.tween(this.moveSheep.node).delay(time).call(()=>{
  127. // this.moveSheep.play();
  128. // }).start();
  129. }
  130. private clickSheepBtn() {
  131. if (this.sheepMoveEnd) {
  132. mk.audio.playEffect("button");
  133. mk.ad.videoAdType = VideoAdType.video_init_10;
  134. mk.ui.openPanel('module/newOpenRedBag/newOpenRedBag');
  135. this.sheepMoveEnd = false;
  136. this.hb_btn.active = false;
  137. this.moveSheep.node.active = false;
  138. let time = mk.math.random(5, 8);
  139. cc.tween(this.moveSheep.node).delay(time).call(() => {
  140. this.moveSheep.node.active = true;
  141. this.sheep.play('sheepMove');
  142. this.moveSheep.play();
  143. }).start();
  144. }
  145. }
  146. // update(dt)
  147. // {
  148. // if(this.time_1 <= 0)
  149. // {
  150. // if(!this.isShow_1)
  151. // {
  152. // this.isShow_1 = true;
  153. // this.time_1 = 8;
  154. // this.star_1.stop();
  155. // cc.tween(this.star_1.node).to(0.2, {opacity: 0}).start();
  156. // }else{
  157. // this.isShow_1 = false;
  158. // this.time_1 = 8;
  159. // this.star_1.play();
  160. // let p = mk.math.random(5, 40);
  161. // this.star_1.node.setPosition(this.starPos_1.subtract(cc.v2(p, p)));
  162. // cc.tween(this.star_1.node).to(0.2, {opacity: 255}).start();
  163. // }
  164. // }else{
  165. // this.time_1 = this.time_1-dt;
  166. // }
  167. // if(this.time_2 <= 0)
  168. // {
  169. // if(!this.isShow_2)
  170. // {
  171. // this.isShow_2 = true;
  172. // this.time_2 = 16;
  173. // this.star_2.stop();
  174. // cc.tween(this.star_2.node).to(0.2, {opacity: 0}).start();
  175. // }else{
  176. // this.isShow_2 = false;
  177. // this.time_2 = 16;
  178. // this.star_2.play();
  179. // let p = mk.math.random(5, 40);
  180. // this.star_2.node.setPosition(this.starPos_2.subtract(cc.v2(p, p)));
  181. // cc.tween(this.star_2.node).to(0.2, {opacity: 255}).start();
  182. // }
  183. // }else{
  184. // this.time_2 = this.time_2-dt;
  185. // }
  186. // if(this.time_3 <= 0)
  187. // {
  188. // if(!this.isShow_3)
  189. // {
  190. // this.isShow_3 = true;
  191. // this.time_3 = 22;
  192. // this.star_3.stop();
  193. // cc.tween(this.star_3.node).to(0.2, {opacity: 0}).start();
  194. // }else{
  195. // this.isShow_3 = false;
  196. // this.time_3 = 22;
  197. // this.star_3.play();
  198. // let p = mk.math.random(5, 40);
  199. // this.star_3.node.setPosition(this.starPos_3.subtract(cc.v2(p, p)));
  200. // cc.tween(this.star_3.node).to(0.2, {opacity: 255}).start();
  201. // }
  202. // }else{
  203. // this.time_3 = this.time_3-dt;
  204. // }
  205. // }
  206. private clickAnimalIconBtn(event, customEvenData) {
  207. mk.audio.playEffect("button");
  208. if (customEvenData == 'bird_1') {
  209. this.flyBirdFinished_1();
  210. this.getRewardByHttp("bird_1");
  211. } else if (customEvenData == 'bird_2') {
  212. this.flyBirdFinished_2();
  213. this.getRewardByHttp("bird_2");
  214. //mk.fly.PlayCoinAnim(1, 5, this.flyBird_2.node, '', null, -1, 2);
  215. } else if (customEvenData == 'dog') {
  216. this.moveDogFinished();
  217. this.getRewardByHttp("dog");
  218. // mk.fly.PlayCoinAnim(1, 5, this.dogMove.node, '', null, -1, 2);
  219. }
  220. gData.adData.checkShowFullInter(1, InterFullAdType.interstitial2_init_3);
  221. }
  222. private async getRewardByHttp(type: string) {
  223. let data = { animalType: 1 };
  224. let response = await mk.http.sendData('redMoney/addRedMoneyByAnimal', data);
  225. if (response.errcode != 0) {
  226. return;
  227. }
  228. let add = response.data.redMoneyAddition;
  229. console.log('addCoin===============>', add);
  230. if (add > 0) {
  231. const several = 3;
  232. let intV = Math.floor(add / several);
  233. let r = add % several;
  234. mk.audio.playEffect('redmoney');
  235. if (type == 'bird_1') {
  236. if (intV > 0) {
  237. for (let i = 0; i != several; ++i) {
  238. mk.fly.PlayCoinAnim(1, 1, this.flyBird_1.node, '', null, -1, intV);
  239. }
  240. }
  241. if (r > 0) {
  242. mk.fly.PlayCoinAnim(1, 1, this.flyBird_1.node, '', null, -1, r);
  243. }
  244. } else if (type == 'bird_2') {
  245. if (intV > 0) {
  246. for (let i = 0; i != several; ++i) {
  247. mk.fly.PlayCoinAnim(1, 1, this.flyBird_2.node, '', null, -1, intV);
  248. }
  249. }
  250. if (r > 0) {
  251. mk.fly.PlayCoinAnim(1, 1, this.flyBird_2.node, '', null, -1, r);
  252. }
  253. } else if (type == 'dog') {
  254. if(intV > 0)
  255. {
  256. for (let i = 0; i != several; ++i) {
  257. mk.fly.PlayCoinAnim(1, 1, this.dogMove.node, '', null, -1, intV);
  258. }
  259. }
  260. if (r > 0) {
  261. mk.fly.PlayCoinAnim(1, 1, this.dogMove.node, '', null, -1, r);
  262. }
  263. }
  264. }
  265. }
  266. }