LevelHomeAward.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. const HomeApi = require("../net/HomeApi");
  2. const GameNotificationKey = require("../utils/GameEnum").GameNotificationKey;
  3. const GameModule = require("../utils/GameModule");
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. },
  8. // LIFE-CYCLE CALLBACKS:
  9. onLoad () {
  10. this.isGetting = false;
  11. this.isPlaying = false;
  12. let self = this;
  13. this.node.on(cc.Node.EventType.TOUCH_END, () => {
  14. self.getAward();
  15. });
  16. GameModule.homeGuide.on('Fire_state26', this.getAward, this);
  17. },
  18. start () {
  19. },
  20. init(roomId, pickupCallback) {
  21. this.roomId = roomId;
  22. this.pickupCallback = pickupCallback;
  23. },
  24. getAward() {
  25. if (this.isGetting || this.isPlaying) { return }
  26. this.isGetting = true;
  27. HomeApi.getRoomAward(this.roomId, (responseData) => {
  28. this.isGetting = false;
  29. GameModule.audioMng.playGetAward();
  30. this.pickupCallback(responseData.awardCount);
  31. GameEvent.fire(GameNotificationKey.GetRoomAward,responseData);
  32. let roomName = Global.BuildingManager.getRoomName(this.roomId);
  33. GameEvent.fire(GameNotificationKey.GameShowAdditionTips,roomName,1);
  34. },(errCode, errMsg) => {
  35. this.isGetting = false;
  36. Global.commonAlert.showCommonErrorAlert("领取奖励失败");
  37. });
  38. if (!GameModule.homeGuide.getComponent('HomeGuide').isPassGuideState('state27')) {
  39. GameModule.homeGuide.getComponent('HomeGuide').handleGuideStateNext('state26', 'state27');
  40. }
  41. },
  42. showAnimation() {
  43. if (this.isPlaying) { return; }
  44. this.node.stopAllActions();
  45. this.node.active = true;
  46. this.isPlaying = true;
  47. let jumpHeight = 100;
  48. let duration = 0.3;
  49. let animationArray = [];
  50. let moveAction1 = cc.moveBy(duration, 0, jumpHeight).easing(cc.easeCubicActionOut());
  51. let moveAction2 = cc.moveBy(duration, 0, -110).easing(cc.easeCubicActionIn());
  52. animationArray.push(moveAction1);
  53. animationArray.push(moveAction2);
  54. while(jumpHeight > 0.1) {
  55. jumpHeight = jumpHeight - (jumpHeight / 3);
  56. duration = duration - (duration / 3);
  57. let upAction = cc.moveBy(duration, 0, jumpHeight).easing(cc.easeCubicActionOut());
  58. let downAction = cc.moveBy(duration, 0, -jumpHeight).easing(cc.easeCubicActionIn());
  59. animationArray.push(upAction);
  60. animationArray.push(downAction);
  61. }
  62. let callback = cc.callFunc(() => {
  63. this.isPlaying = false;
  64. GameModule.homeGuide.getComponent('HomeGuide').handleGuideStateNext('state24', 'state26');
  65. });
  66. animationArray.push(callback);
  67. this.node.runAction(cc.sequence(animationArray));
  68. },
  69. updateAnimation() {
  70. if (this.isPlaying) { return; }
  71. this.node.active = true;
  72. this.node.stopAllActions();
  73. this.isPlaying = true;
  74. let jumpHeight = 100;
  75. let duration = 0.3;
  76. let animationArray = [];
  77. let moveAction1 = cc.moveBy(duration, 0, jumpHeight).easing(cc.easeCubicActionOut());
  78. let moveAction2 = cc.moveBy(duration, 0, -100).easing(cc.easeCubicActionIn());
  79. animationArray.push(moveAction1);
  80. animationArray.push(moveAction2);
  81. while(jumpHeight > 0.1) {
  82. jumpHeight = jumpHeight - (jumpHeight / 3);
  83. duration = duration - (duration / 3);
  84. let upAction = cc.moveBy(duration, 0, jumpHeight).easing(cc.easeCubicActionOut());
  85. let downAction = cc.moveBy(duration, 0, -jumpHeight).easing(cc.easeCubicActionIn());
  86. animationArray.push(upAction);
  87. animationArray.push(downAction);
  88. }
  89. let callback = cc.callFunc(() => {
  90. this.isPlaying = false;
  91. });
  92. animationArray.push(callback);
  93. this.node.runAction(cc.sequence(animationArray));
  94. },
  95. // update (dt) {},
  96. });