| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- cc.Class({
- extends: cc.Component,
- properties: {
- speed:0,
- playerControllerScp:null,
- gameStatesScp:null,
- nameIndex:0
- },
- onLoad () {
- this.bMoving = true;
- this.bHightLight = false;
- this.bHit = false;
- //注册Touch事件 TOUCH_START TOUCH_END TOUCH_MOVE
- this.node.on(cc.Node.EventType.TOUCH_START,this.touchBegin,this);
- this.node.on(cc.Node.EventType.TOUCH_MOVE,this.touchBegin,this);
- this.node.on(cc.Node.EventType.TOUCH_END,this.touchBegin,this);
- this.actionBarWidth = 720;
- },
- touchBegin:function(event) {
- this.hit();
- },
- update (dt) {
- if(this.bMoving)
- {
- this.node.x+=this.speed * dt * 30;
- if(this.node.x>this.actionBarWidth)
- // if(this.node.x>400)
- {
- this.bMoving = false;
- this.node.destroy();
- return;
- }
- if(this.node.x >= -100 && this.node.x <= +100)
- // if(this.node.x >= -100 && this.node.x <= 100)
- {
- if(!this.bHightLight)
- {
- this.node.getChildByName('1').active = false;
- this.node.getChildByName('2').active = true;
- this.node.getChildByName('3').active = false;
- this.gameStatesScp.hightLightActionArr.push(this);
- this.bHightLight = true;
- }
- }
- if(this.node.x > 100)
- {
- if(this.bHightLight)
- {
- this.node.getChildByName('1').active = false;
- this.node.getChildByName('2').active = false;
- this.node.getChildByName('3').active = true;
- if(!this.bHit){
- //如果没有打击,判断miss
- this.gameStatesScp.missCount ++;
- }
-
- for(let i=0;i<this.gameStatesScp.hightLightActionArr.length;i++)
- {
- if(this.gameStatesScp.hightLightActionArr[i] == this)
- {
- this.gameStatesScp.hightLightActionArr.splice(i,1);
- break;
- }
- }
- this.bHightLight = false;
- }
- }
- }
- },
- hit()
- {
- if(this.bHightLight && !this.bHit)
- {
- this.bHit =true;
- this.node.getChildByName('explosion').active = true;
- this.node.getChildByName('1').active = false;
- this.node.getChildByName('2').active = false;
- this.node.getChildByName('3').active = false;
- this.playerControllerScp.triggleCombo(this.playerControllerScp);
- this.gameStatesScp.hitCount++;
- this.bMoving = false;
- this.scheduleOnce(function () {
- this.node.destroy();
- },1);
- }
- }
- });
|