123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- import AudioManager from "../../../src/audioUitls/AudioManager";
- import Tools from "../../../src/common/Tools";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class DownCount extends cc.Component {
- @property({ tooltip: '星星', type: cc.Node })
- nodeCoin: cc.Node = null;
- @property({ tooltip: 'process container', type: cc.ProgressBar })
- nodeProgress: cc.ProgressBar = null;
- /** 星星数 */
- starCount: number = 0;
- /** 星星数 */
- starTotal: number = 3
- /** 计时时间 */
- timeCount: number = 0;
- /** 总计时时间 */
- timeTotal: number = 180;
- /** 计时单位 */
- timeDelay = 0.3;
- /** 错误次数 */
- errorCount: number = 0;
- arrCoin: cc.Node[] = [];
- protected onDisable(): void {
- this.unscheduleAllCallbacks();
- }
- protected start(): void {
- this.arrCoin = Tools.getArrByNode(this.nodeCoin, 'item');
- this.arrCoin.forEach((item)=>{
- item.active = true;
- item.getChildByName('gray').active = false;
- item.getChildByName('icon').active = true;
- });
- }
- /** 倒计时 */
- downCountInit(): void {
- this.node.active = true;
- this.timeCount = 0;
- this.errorCount = 0;
- const progressBar = this.nodeProgress.getComponent(cc.ProgressBar);
- progressBar.progress = 1;
- };
- /** 倒计时-启动 */
- downCountLunch(): void {
- AudioManager.getInstance().playEffect('audio/clock');
- const progressBar = this.nodeProgress.getComponent(cc.ProgressBar);
- this.schedule(() => {
- this.timeCount += this.timeDelay;
- this.timeCount = this.timeCount > this.timeTotal ? this.timeTotal : this.timeCount;
- progressBar.progress = (this.timeTotal - this.timeCount) / 180;
- this.starCount = this.getStarCount();
- this.arrCoin.forEach((item, index)=>{
- if (index > this.starCount - 1) {
- let icon = item.getChildByName('icon');
- if (icon.active) {
- icon.active = false;
- item.getChildByName('gray').active = true;
- AudioManager.getInstance().playEffect('audio/star_hide');
- }
- }
- });
- if (progressBar.progress <= 0) {
- this.unscheduleAllCallbacks();
- }
- }, this.timeDelay);
- }
- /** 倒计时-停止 */
- downCountStop(): void {
- this.unscheduleAllCallbacks();
- }
- errorAdd(){
- this.errorCount++;
- this.timeCount += 20;
- }
- /** 获取题卡获得的星星 用在过关后的弹窗 */
- getStarCount(): number {
- this.starCount = this.starTotal;
- if (this.timeCount > 60) {
- this.starCount--;
- }
- if (this.timeCount > 120) {
- this.starCount--;
- }
- return this.starCount < 1 ? 1 : this.starCount
- }
- }
|