DrawStarLayer.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { _decorator, Component, Node, tween } from 'cc';
  2. import platformSystem from '../platform/platformSystem';
  3. import BasePanel from '../core/component/BasePanel';
  4. import { audioMgr } from '../core/manager/AudioManager';
  5. import WindowManager from '../core/manager/WindowManager';
  6. import { LevelClearLayer } from './LevelClearLayer';
  7. import { GameConst } from '../core/common/GameConst';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('DrawStarLayer')
  10. export class DrawStarLayer extends BasePanel {
  11. indicator: Node = null;
  12. start() {
  13. this.indicator = this.GetGameObject("star-gamification-indicator");
  14. audioMgr.playOneShot(GameConst.audios.pass);
  15. }
  16. star = 0;
  17. setStar(s) {
  18. this.star = s;
  19. this.SetText("lbl_star", s + "");
  20. }
  21. dir = 1;
  22. beisu = 1;
  23. update() {
  24. if (this.pause) return;
  25. let pos = this.indicator.getPosition();
  26. pos.x += this.dir * 10;
  27. if (pos.x > 190) this.dir = -1;
  28. if (pos.x < -190) this.dir = 1;
  29. this.indicator.setPosition(pos);
  30. let x = this.indicator.getPosition().x;
  31. if (x >= -190 && x < -145) {
  32. this.beisu = 2;
  33. }
  34. else if (x >= -145 && x < -98) {
  35. this.beisu = 3;
  36. }
  37. else if (x >= -98 && x < -36) {
  38. this.beisu = 4;
  39. }
  40. else if (x >= -36 && x < 36) {
  41. this.beisu = 5;
  42. }
  43. else if (x >= 36 && x < 98) {
  44. this.beisu = 4;
  45. }
  46. else if (x >= 98 && x < 145) {
  47. this.beisu = 3;
  48. }
  49. else if (x >= 145 && x <= 190) {
  50. this.beisu = 2;
  51. }
  52. this.SetText("lbl_beisu", "x" + this.beisu);
  53. }
  54. pause = false;
  55. onBtnClicked(event, customEventData) {
  56. audioMgr.playOneShot(GameConst.audios.btnclick);
  57. var btnName = event.target.name;
  58. switch (btnName) {
  59. case "btn_get":
  60. this.pause = true;
  61. WindowManager.ins.open("LevelClearLayer").then((com: LevelClearLayer) => {
  62. com.setAddStar(this.star);
  63. })
  64. this.close();
  65. break;
  66. case "btn_ad":
  67. this.pause = true;
  68. tween(this.node).delay(1).call(() => {
  69. platformSystem.platform.showRewardVideo((b) => {
  70. if (b) {
  71. WindowManager.ins.open("LevelClearLayer").then((com: LevelClearLayer) => {
  72. com.setAddStar(this.star * this.beisu);
  73. })
  74. this.close();
  75. }
  76. })
  77. }).start()
  78. break;
  79. }
  80. }
  81. }