123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- 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.addMoneyAutoCoinPool = new cc.NodePool();
- this.addMoneyCoinPool = new cc.NodePool();
- for (let i = 0; i < 5; i++) {
- let coinItem = cc.instantiate(this.clickAddMoneyCoin);
- this.addMoneyCoinPool.put(coinItem);
- }
- 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) {
- let coinItem = this.addMoneyCoinPool.get();
- this.node.addChild(coinItem);
- coinItem.x = 0;
- coinItem.y = 190;
- coinItem.active = true;
- let coinManager = coinItem.getComponent('ClickAddMoneyCoin');
- coinManager.showCoin( () => {
- this.addMoneyCoinPool.put(coinItem);
- });
- }
- // else {
- // coinItem = cc.instantiate(this.clickAddMoneyCoin);
- // }
- // 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) {
- // }
- // },
- });
|