| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596 |
- cc.Class({
- extends: cc.Component,
- properties: {
- touchFlag: false,
- _isEnemy: false,
- },
- init(parents, randomIndex) {
- this.父级 = parents;
- this.添加事件();
- this._name = (randomIndex - 1).toString();
- // console.log("我现在完全露头了 名字是 11111",this._type);
- if (randomIndex == 1)
- this._name = "";
- this.surplusCount = this.击打次数(randomIndex);
- this.clickCount = 0;
- this.reduceBloodCount = 0;
- this.目标父级 = this.父级;
- this.node.position = new cc.Vec2(0, -190);
- //是否允许被击打
- this.canClick = false;
- this.hit = false;
- this.playquan = 0;
- if (!this._isEnemy) {
- // utils.isMobile(function () {
- // manager_android_js.mydishu = this;
- // }.bind(this));
- }
- },
- //是不是我方
- isMy : function(){
- let my = false;
- if (!this._isEnemy) {
- my = true;
- }
- return my;
- },
- initData: function (Index,type,conf,Pool) {
- this._Index = Index;
- this._type = type;
- this.conf = conf;
- // console.log("地鼠出生", "设置特殊数字",Index, type);
- this.PlayDragonBones(this.animationDisplay, "jian" + this._name, this.默认状态, 1);
- // Pool[Index] =this;
- // Log.info("准备伸头 ",this.animationDisplay)
- if (this.isMy()) {
- app.myDishuPool[Index] = this;
- Statistics.dishu.num+=1
- }
- // console.log("现在是什么" ,"判断结果哪个是空的可以上地鼠的",Index ,"进来的地鼠盒", Pool,"全局地鼠盒",app.myDishuPool);
- this.animationDisplay.timeScale = this.conf.top.timeScale;
- this._isEnemy = false;
- if (this.父级.name == "敌方父级") {
- this._isEnemy = true;
- }
- },
- toclick: function (data) {
- // console.log("当前地鼠", this.canClick,"方向是",this._Index,"类型是",this._type);
- if (!this.canClick)
- return;
- ObjectPools.playSimpleAudioEngine(0);
- utils.isMobile(function () {
- if (manager_android_js.gamestatus == 3) {
- return;
- }
- }.bind(this));
- this.attackMode();
- // cc.log("点击地鼠", this._Index);
- },
- attackMode: function () {
- var pos = this.node.parent.parent.position;
- Games.拳套.position = pos;
- // if (this.hit) {
- // return;
- // }
- // this.hit = true;
- var randomInt = parseInt(Math.random() * 3, 10);
- this.node.stopAllActions();
- this.unscheduleAllCallbacks();
- if (!this._isEnemy) {
- if (this._type == 0) {
- Statistics.addScore(0,dishuManager.rewardScore);
- Statistics.addCount(0, this._Index);
- }else{
- Statistics.addScore(0,-dishuManager.rewardScore);
- Statistics.addCount(0, this._Index);
- Statistics.addmiss(0);
- }
- this. attacklose();
- }
- Games.拳套.active = true;
- switch (randomInt) {
- case 0:
- this.PlayDragonBones(Games.glovesDragon, "attack2", this.隐藏拳套, 1);
- this.击中();
- break;
- case 1:
- Games.拳套.scale = new cc.Vec2(1, 1);
- this.PlayDragonBones(Games.glovesDragon, "attack1", this.隐藏拳套, 1);
- this.右击();
- break;
- case 2:
- Games.拳套.scale = new cc.Vec2(-1, 1);
- this.PlayDragonBones(Games.glovesDragon, "attack1", this.隐藏拳套, 1);
- this.左击();
- break;
- }
- },
- //打错了 或者 该打的没有打 就下去了
- lose : function(){
- // console.log("现在被打的或者自己下去的 是什么类型的",this._type);
- Log.info("现在被打的或者自己下去的 是什么类型的",this._type);
- if (Games.gameTag) {
- if (this._type == 0) {
- Statistics.discontinuity(0);
- ObjectPools.playSimpleAudioEngine(8);
- }
- }
- },
- attacklose : function(){
- // console.log("现在被打的或者自己下去的 是什么类型的",this._type);
- if (Games.gameTag){
- if (this._type == 1) {
- Statistics.discontinuity(0);
- ObjectPools.playSimpleAudioEngine(8);
- }
- }
- },
- 添加事件() {
- this.animationDisplay = this.getComponent(dragonBones.ArmatureDisplay);
- if (this._isEnemy) {
- } else {
- this.node.on(cc.Node.EventType.TOUCH_START, function () {
- // this.toclick();
- }, this);
- // this.toclick();
- // Games.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
- // if (!this.canClick)
- // return;
- // if (Games.checkTouch(this.node, event.getLocation())) {
- // if (this.touchFlag == false) {
- // this.lastPos = event.getLocation();
- // this.touchFlag = true;
- // }
- // } else {
- // if (this.touchFlag == true) {
- // this.currentPos = event.getLocation();
- // this.方向判断();
- // }
- // }
- // }, this);
- this.我方事件();
- }
- },
- 敌方事件() {
- this.randomClickTime = 0.5;
- this.clickCallback = function () {
- utils.isMobile(function () {
- if (manager_android_js.gamestatus == 3) {
- return;
- }
- }.bind(this));
- this.randomClickTime = (parseInt(Math.random() * 3, 10) + 3) * 0.1;
- var randomClickHole = parseInt(Math.random() * 100, 10);
- if (this._type == 0) {
- if (randomClickHole > 10) {
- var randomClickCount = parseInt(Math.random() * 9, 10) + 3;
- this.randomIntervalTime = 0.2;
- this.randomIntervalTime = (parseInt(Math.random() * 2, 10) + 1) * 0.1;
- var randomClcikType = parseInt(Math.random() * 3, 10); //0-3(击打类型0:左,1:中2:右)
- // console.log("随机打击?", randomClcikType);
- if (this._isEnemy) {
- Statistics.addCount(1, this._Index);
- if (this._type == 0) {
- Statistics.addScore(1,dishuManager.rewardScore);
- }else{
- Statistics.addScore(1,-dishuManager.rewardScore);
- }
- this. attacklose();
- }
- Games.拳套蓝.active = true;
- if (randomClcikType == 0) {
- var pos = this.node.parent.parent.position;
- Games.拳套蓝.position = pos;
- Games.拳套蓝.scale = new cc.Vec2(-0.5, 0.5);
- this.PlayDragonBones(Games.glovesDragonlan, "attack1", this.隐藏拳套蓝, 1);
- this.左击();
- } else if (randomClcikType == 1) {
- var pos = this.node.parent.parent.position;
- Games.拳套蓝.position = pos;
- Games.拳套蓝.scale = new cc.Vec2(0.5, 0.5);
- this.PlayDragonBones(Games.glovesDragonlan, "attack2", this.隐藏拳套蓝, 1);
- this.击中();
- } else {
- var pos = this.node.parent.parent.position;
- Games.拳套蓝.position = pos;
- Games.拳套蓝.scale = new cc.Vec2(0.5, 0.5);
- this.PlayDragonBones(Games.glovesDragonlan, "attack1", this.隐藏拳套蓝, 1);
- this.右击();
- }
- // this.callback = function () {
- //
- // // if (randomClickCount <= 0) {
- // // this.unschedule(this.callback);
- // // }
- //
- // this.randomIntervalTime = (parseInt(Math.random() * 2, 10) + 1) * 0.1;
- // var randomClcikType = parseInt(Math.random() * 2, 10); //0-3(击打类型0:左,1:中2:右)
- //
- //
- // if (randomClcikType == 0) {
- // this.左击();
- // } else if (randomClcikType == 1) {
- // this.击中();
- // } else {
- // this.右击();
- // }
- // randomClickCount--;
- // }
- // this.schedule(this.callback, this.randomIntervalTime);
- }
- }
- }.bind(this)
- setTimeout(this.clickCallback, this.randomClickTime);
- // this.schedule(this.clickCallback, this.randomClickTime);
- },
- 我方事件() {
- // this.node.on(cc.Node.EventType.TOUCH_START, function () {
- // if (!this.canClick)
- // return;
- // ObjectPools.playSimpleAudioEngine(0);
- // var pos = this.node.parent.parent.position;
- // Games.拳套.position = pos;
- // this.PlayDragonBones(Games.glovesDragon, "attack2", this.隐藏拳套, 1);
- // this.击中();
- // }, this);
- // Games.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
- // if (!this.canClick)
- // return;
- // if (Games.checkTouch(this.node, event.getLocation())) {
- // if (this.touchFlag == false) {
- // this.lastPos = event.getLocation();
- // this.touchFlag = true;
- // } else {
- // this.currentPos = event.getLocation();
- // this.方向判断();
- // }
- // }
- // }, this);
- // ObjectPools.playSimpleAudioEngine(3);
- },
- 方向判断() {
- if (!this.canClick)
- return;
- if (this.node.parent == null)
- return;
- var valuex = this.currentPos.x - this.lastPos.x;
- if (Math.abs(valuex) < 40)
- return;
- this.touchFlag = false;
- // 左右滑动
- if (valuex > 0) {
- ObjectPools.playSimpleAudioEngine(0);
- var pos = this.node.parent.parent.position;
- Games.拳套.position = pos;
- Games.拳套.scale = new cc.Vec2(1, 1);
- this.PlayDragonBones(Games.glovesDragon, "attack1", this.隐藏拳套, 1);
- this.右击();
- } else {
- ObjectPools.playSimpleAudioEngine(0);
- var pos = this.node.parent.parent.position;
- Games.拳套.position = pos;
- Games.拳套.scale = new cc.Vec2(-1, 1);
- this.PlayDragonBones(Games.glovesDragon, "attack1", this.隐藏拳套, 1);
- this.左击();
- }
- },
- 默认状态(event) {
- var scripts = this.node.getComponent("dishu");
- // scripts.PlayDragonBonesRemoveEvent(scripts.animationDisplay,"jian" + this._name);
- // 出现后 倒计时2秒缩头
- if (scripts.animationDisplay._animationName.indexOf('jian') != -1) {
- if (scripts._isEnemy) {
- scripts.敌方事件();
- }
- if (!scripts._isEnemy) {
- ObjectPools.playAudioEngineDirection(scripts._Index);
- // app.myDishuPool[scripts._Index] = scripts;
- // console.log("地鼠出生", "出生类型", this._name, "出生点是", Index,"当前地鼠池样子是",app.myDishuPool);
- // console.log("现在数字" + Index );
- // console.log("假定0" + "左" );
- // console.log("假定1" + "中" );
- // console.log("假定2" + "右" );
- }else{
- // app.hisDishuPool[scripts._Index] = scripts;
- }
- // scripts.缩头();
- // console.log("现在是有");
- scripts.animationDisplay.timeScale = scripts.conf.mid.timeScale;
- if (scripts._type == 1) {
- scripts.PlayDragonBonesNotEvent(scripts.animationDisplay, "cry" + scripts._name, null, 0);
- }else {
- scripts.PlayDragonBonesNotEvent(scripts.animationDisplay, "idle" + scripts._name, null, 0);
- }
- scripts.canClick = true;
- scripts.伸头();
- }else{
- // console.log("现在是没有");
- }
- // console.log("现在上来了",scripts._name,scripts._type,"现在动画名字是",scripts.animationDisplay._animationName);
- // scripts.PlayDragonBones(scripts.animationDisplay, "idle" + scripts._name, scripts.默认状态, 1);
- },
- // 伸头后倒计时 2秒后自动缩头
- 伸头() {
- var self = this;
- // console.log("我现在要缩头了",this._name,this._type);
- this.scheduleOnce(function () {
- if (this.canClick) {
- // console.log("ceshi");
- this.canClick = false;
- this.unscheduleAllCallbacks();
- if (!this._isEnemy) {
- // ObjectPools.playSimpleAudioEngine(5);
- }
- // if (!this._isEnemy) {
- // if (manager_android_js != null) {
- // manager_android_js.mydishu = null;
- // }
- // }
- self.回收(0);
- if (!this._isEnemy) {
- this.lose();
- }
- }
- }, this.conf.mid.time);
- },
- 击中() {
- this.node.stopAllActions();
- this.unscheduleAllCallbacks();
- var names;
- if (this._name == "") {
- names = "21";
- } else {
- names = 20 + parseInt(this._name) + 1;
- }
- this.PlayDragonBones(this.animationDisplay, "attack" + names, this.默认状态, 1);
- // this.PlayDragonBones(this.animationDisplay, "yun" + this._name, this.默认状态, 1);
- this.schedule(function () {
- this.连击();
- }.bind(this), 0.1)
- },
- 左击() {
- this.node.stopAllActions();
- this.unscheduleAllCallbacks();
- var names;
- if (this._name == "") {
- names = "11";
- } else {
- names = 10 + parseInt(this._name) + 1;
- }
- this.PlayDragonBones(this.animationDisplay, "attack" + names, this.默认状态, 1, -1);
- this.schedule(function () {
- this.连击();
- }.bind(this), 0.1)
- },
- 右击() {
- this.node.stopAllActions();
- this.unscheduleAllCallbacks();
- var names;
- if (this._name == "") {
- names = "11";
- } else {
- names = 10 + parseInt(this._name) + 1;
- }
- this.PlayDragonBonesNotEvent(this.animationDisplay, "attack" + names, this.默认状态, 1);
- this.schedule(function () {
- this.连击();
- }.bind(this), 0.1)
- },
- 连击() {
- this.surplusCount--;
- this.clickCount++;
- // console.log("我这边的打击", this._isEnemy);
- if (this.node.parent != null) {
- if (!this._isEnemy) {
- // console.log("播放连击动画中","进来了吗",Statistics.gethit(0));
- if (Statistics.gethit(0) >= 3) {
- if (this.playquan == 0) {
- this.playquan++;
- // ObjectPools.playSimpleAudioEngine(4);
- Games.连击播放(this.node.parent.parent.position, Games.连击动画, Statistics.gethit(0));
- // console.log("播放连击动画中", Statistics.gethit(0));
- }
- }
- }
- }
- this.挂掉();
- // if (this.surplusCount == 0) {
- // this.挂掉();
- // }
- },
- 隐藏拳套蓝(event) {
- Games.拳套蓝.position = cc.Vec2.ZERO;
- },
- 隐藏拳套(event) {
- Games.拳套.position = cc.Vec2.ZERO;
- },
- 挂掉() {
- if (!this.canClick)
- return;
- // ObjectPools.playSimpleAudioEngine(2);
- this.canClick = false;
- // manager_android_js.boom();
- var randomIndex = parseInt(Math.random() * 2, 10);
- // if (randomIndex == 0) {
- //
- // this.PlayDragonBones(this.animationDisplay, "yun" + this._name, this.temps, 0.2);
- // } else {
- // this.PlayDragonBones(this.animationDisplay, "cry" + this._name, this.temps, 0.2);
- // }
- this.PlayDragonBones(this.animationDisplay, "yun" + this._name, this.temps, 0.2);
- // Log.info("打死一个地鼠")
- this.回收(1);
- },
- temps : function(){
- },
- 回收(type) {
- // if (!this._isEnemy) {
- // if (manager_android_js != null) {
- // manager_android_js.mydishu = null;
- // }
- // }
- //0自然 死亡 1 被打死亡
- var scripts = this.node.getComponent("dishu");
- if (type == 0) {
- if (scripts._type == 0) {
- Games.掉血(scripts.目标父级, scripts.reduceBloodCount);
- }
- }else if (type == 1) {
- if (scripts._type == 1) {
- Games.掉血(scripts.目标父级, scripts.reduceBloodCount);
- }
- }
- if (testUI) {
- testUI.showDishu(this._Index,false);
- }
-
- var self = this;
- var finished = cc.callFunc(function () {
- self.node.stopAllActions();
- self.removeDishu();
- setTimeout(function () {
- ObjectPools.地鼠回收(self.node);
- // Games.随机生成(self.父级);
- }.bind(this), 1);
- });
- this.缩头动作 = cc.sequence(cc.moveBy(this.conf.lower.time, cc.v2(0, -150)), finished);
- this.node.runAction(this.缩头动作);
- },
- //删除下去的地鼠
- removeDishu : function(){
- if (this.isMy()) {
- app.myDishuPool[this._Index] = null;
- }else{
- app.hisDishuPool[this._Index] = null;
- }
- },
- PlayDragonBones(animationDisplays, newAnimation, completeCallback, playTimes, scaleX = 1) { //动态加载龙骨
- animationDisplays.playAnimation(newAnimation, playTimes);
- this.node.scale = new cc.Vec2(scaleX, 1);
- animationDisplays.addEventListener(dragonBones.EventObject.COMPLETE, completeCallback, animationDisplays);//.apply(this));
- },
- PlayDragonBonesNotEvent(animationDisplays, newAnimation, completeCallback, playTimes, scaleX = 1) { //动态加载龙骨
- animationDisplays.playAnimation(newAnimation, playTimes);
- this.node.scale = new cc.Vec2(scaleX, 1);
- // animationDisplays.addEventListener(dragonBones.EventObject.COMPLETE, completeCallback, animationDisplays);//.apply(this));
- },
- PlayDragonBonesRemoveEvent(animationDisplays,completeCallback, scaleX = 1) { //动态加载龙骨
- // animationDisplays.playAnimation(newAnimation, playTimes);
- this.node.scale = new cc.Vec2(scaleX, 1);
- animationDisplays.removeEventListener(dragonBones.EventObject.COMPLETE, completeCallback, animationDisplays);//.apply(this));
- },
- 击打次数(index) {
- var count;
- // idle:普通 idle1:安全帽 idel2:海盗帽 idle:南瓜帽
- switch (index) {
- case 1:
- count = 1;
- break;
- case 2:
- count = 1;
- break;
- case 3:
- count = 1;
- break;
- case 4:
- count = 1;
- break;
- }
- return count;
- },
- });
|