DownCount.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import AudioManager from "../../../src/audioUitls/AudioManager";
  2. import Tools from "../../../src/common/Tools";
  3. const { ccclass, property } = cc._decorator;
  4. @ccclass
  5. export default class DownCount extends cc.Component {
  6. @property({ tooltip: '星星', type: cc.Node })
  7. nodeCoin: cc.Node = null;
  8. @property({ tooltip: 'process container', type: cc.ProgressBar })
  9. nodeProgress: cc.ProgressBar = null;
  10. /** 星星数 */
  11. starCount: number = 0;
  12. /** 星星数 */
  13. starTotal: number = 3
  14. /** 计时时间 */
  15. timeCount: number = 0;
  16. /** 总计时时间 */
  17. timeTotal: number = 180;
  18. /** 计时单位 */
  19. timeDelay = 0.3;
  20. /** 错误次数 */
  21. errorCount: number = 0;
  22. arrCoin: cc.Node[] = [];
  23. protected onDisable(): void {
  24. this.unscheduleAllCallbacks();
  25. }
  26. protected start(): void {
  27. this.arrCoin = Tools.getArrByNode(this.nodeCoin, 'item');
  28. this.arrCoin.forEach((item)=>{
  29. item.active = true;
  30. item.getChildByName('gray').active = false;
  31. item.getChildByName('icon').active = true;
  32. });
  33. }
  34. /** 倒计时 */
  35. downCountInit(): void {
  36. this.node.active = true;
  37. this.timeCount = 0;
  38. this.errorCount = 0;
  39. const progressBar = this.nodeProgress.getComponent(cc.ProgressBar);
  40. progressBar.progress = 1;
  41. };
  42. /** 倒计时-启动 */
  43. downCountLunch(): void {
  44. AudioManager.getInstance().playEffect('audio/clock');
  45. const progressBar = this.nodeProgress.getComponent(cc.ProgressBar);
  46. this.schedule(() => {
  47. this.timeCount += this.timeDelay;
  48. this.timeCount = this.timeCount > this.timeTotal ? this.timeTotal : this.timeCount;
  49. progressBar.progress = (this.timeTotal - this.timeCount) / 180;
  50. this.starCount = this.getStarCount();
  51. this.arrCoin.forEach((item, index)=>{
  52. if (index > this.starCount - 1) {
  53. let icon = item.getChildByName('icon');
  54. if (icon.active) {
  55. icon.active = false;
  56. item.getChildByName('gray').active = true;
  57. AudioManager.getInstance().playEffect('audio/star_hide');
  58. }
  59. }
  60. });
  61. if (progressBar.progress <= 0) {
  62. this.unscheduleAllCallbacks();
  63. }
  64. }, this.timeDelay);
  65. }
  66. /** 倒计时-停止 */
  67. downCountStop(): void {
  68. this.unscheduleAllCallbacks();
  69. }
  70. errorAdd(){
  71. this.errorCount++;
  72. this.timeCount += 20;
  73. }
  74. /** 获取题卡获得的星星 用在过关后的弹窗 */
  75. getStarCount(): number {
  76. this.starCount = this.starTotal;
  77. if (this.timeCount > 60) {
  78. this.starCount--;
  79. }
  80. if (this.timeCount > 120) {
  81. this.starCount--;
  82. }
  83. return this.starCount < 1 ? 1 : this.starCount
  84. }
  85. }