const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey; const GameModule = require('../utils/GameModule'); const TapTapTool = require("../utils/TapTapTool"); cc.Class({ extends: cc.Component, properties: { moneyCatSkeleton: sp.Skeleton, moneyCatNode: cc.Node, clickAddMoney: cc.Prefab, clickAddMoneyCoin: cc.Prefab, // onceCoin: cc.Node, // twiceCoin: cc.Node, isHided: false, }, // LIFE-CYCLE CALLBACKS: onLoad () { this.isPlaying = false; this._isTouch = false; this.showNewCoin = true; this.node.on('touchend', () => { this.clickCat(false); }, this); this.addMoneyPool = new cc.NodePool(); this.addMoneyCoinPool = new cc.NodePool(); this.addMoneyAutoCoinPool = new cc.NodePool(); GameEvent.on(GameNotificationKey.AutoClickGold, this, this.autoClickCat); GameEvent.on(GameNotificationKey.ClickAddMoney, this, this.clickCat); GameModule.homeGuide.on('Fire_state5', this.stopCat, this); GameModule.homeGuide.on('Fire_state6', this.clickCat, this); if (GameModule.homeGuide.getComponent('HomeGuide').isPassGuideState('state5')) { if (!GameModule.homeGuide.getComponent('HomeGuide').isPassGuideState('state6')) { GameModule.homeGuide.getComponent('HomeGuide').handleState('state6'); this.stopCat(); } } GameEvent.on('just_cat_hit', this, this.catHit); if (Global.isLongPressClick) { this.addLongTap(); } }, stopCat() { this.moneyCatSkeleton.setAnimation(0, 'stand', false); this.moneyCatSkeleton.timeScale = 0; }, addLongTap() { this.node.on(cc.Node.EventType.TOUCH_START, (event) => { //// 如果有购买商品 一秒钟点击十次 // console.log('开始点击'); if (!this._isTouch) { if (Global.isLongPressClick === true) { /// 最起码要按住1秒 this._addClick = false; this._timeCount = 0; this.schedule(this.timeAction, 1); this._isTouch = true; } } }); this.node.on(cc.Node.EventType.TOUCH_END, (event) => { // console.log("点击结束"); if (this._isTouch) { if (Global.isLongPressClick === true && this._addClick) { let clickCount = 1 / GameModule.userInfo.secondClick; clickCount -= 10; GameModule.userInfo.secondClick = 1 / clickCount; this._addClick = false; } else { this._addClick = true; } this._isTouch = false; this.unschedule(this.timeAction, this); } }, this); this.node.on(cc.Node.EventType.TOUCH_MOVE, (event) => { let x = event.getLocationX(); let y = event.getLocationY(); let startLocation = event.getStartLocation(); // console.log('移动'); if (this._isTouch && ( Math.abs(x - startLocation.x) > 10 || Math.abs(y - startLocation.y) > 10)) { if (Global.isLongPressClick === true && this._addClick) { let clickCount = 1 / GameModule.userInfo.secondClick; clickCount -= 10; GameModule.userInfo.secondClick = 1 / clickCount; this._addClick = false; } else { this._addClick = true; } this.unschedule(this.timeAction, this); this._isTouch = false; } }, this); }, timeAction() { this._timeCount += 1; if (this._timeCount == 1) { if (!this._addClick) { /// 一秒钟点击的次数 let clickCount = 0; if (GameModule.userInfo.secondClick == 0) { clickCount = 10; } else { clickCount = 1 / GameModule.userInfo.secondClick; clickCount += 10; } GameModule.userInfo.secondClick = 1 / clickCount; this._addClick = true; } /// 否则每秒钟添加 10次点击 } else { GameModule.userInfo.clickCount += 10; } }, clickCat(isAuto = false) { if (!isAuto && this.isHided) { GameEvent.fire(GameNotificationKey.TabbarClickCat); return; } //自动点击时候并且收起招财猫将不播放动画 if (isAuto && this.isHided) { GameModule.userInfo.gold = TapTapTool.add(GameModule.userInfo.gold, GameModule.userInfo.coinTap); return; } if (isAuto) { //自动点击金币出现动画 if (this.showNewCoin) { let coinItem = null; if (this.addMoneyAutoCoinPool.size() > 0) { coinItem = this.addMoneyAutoCoinPool.get(); } else { coinItem = cc.instantiate(this.clickAddMoneyCoin); } this.node.addChild(coinItem); coinItem.x = 0; coinItem.y = 190; coinItem.active = true; this.showNewCoin = false; let coinManager = coinItem.getComponent('ClickAddMoneyCoin'); coinManager.showAutoCoin( () => { this.showNewCoin = true; }, () => { this.addMoneyAutoCoinPool.put(coinItem); }); } } else { GameModule.audioMng.playClickCat(); let coinItem = null; if (this.addMoneyCoinPool.size() > 0) { coinItem = this.addMoneyCoinPool.get(); } else { coinItem = cc.instantiate(this.clickAddMoneyCoin); } this.node.addChild(coinItem); coinItem.x = 0; coinItem.y = 190; coinItem.active = true; let coinManager = coinItem.getComponent('ClickAddMoneyCoin'); coinManager.showCoin( () => { this.addMoneyCoinPool.put(coinItem); }); } let item = null; if (this.addMoneyPool.size() > 0) { item = this.addMoneyPool.get(); } else { item = cc.instantiate(this.clickAddMoney); } this.node.addChild(item); item.x = 0; item.y = 230; item.active = true; let itemManager = item.getComponent('ClickAddMoney'); itemManager.showAddMoney( () => { this.addMoneyPool.put(item); }, isAuto); //招财猫的动画 if (this.isPlaying) { return } this.isPlaying = true; this.moneyCatSkeleton.timeScale = 1; this.moneyCatSkeleton.setAnimation(0, 'hit', false); this.moneyCatSkeleton.setCompleteListener(() => { this.isPlaying = false; this.moneyCatSkeleton.setAnimation(0, 'stand', true); }); }, catHit() { //招财猫的动画 this.isPlaying = true; this.moneyCatSkeleton.timeScale = 1; this.moneyCatSkeleton.setAnimation(0, 'hit', false); this.moneyCatSkeleton.setCompleteListener(() => { this.isPlaying = false; this.moneyCatSkeleton.setAnimation(0, 'stand', true); }); }, autoClickCat() { this.clickCat(true); }, start () { }, // update (dt) { // if (this._isTouch && this._addClick) { // } // }, });