战斗代码

fighting: function(fighter,beHiter){
       var that = this
        var node = fighter.shift()
            var beHitNode = beHiter[parseInt(Math.random()*beHiter.length)]

        var basePos = node.getPosition()
        var targetPos = beHitNode.getPosition()
        node.runAction(
            cc.sequence(
                cc.moveTo(0.5, targetPos),
                cc.callFunc(countAttack),
                cc.moveTo(0.2, basePos),
                cc.callFunc(attackEnd)
            )
        )
       
        function countAttack(){
            beHitNode.getComponent('warRole').pub_beHit(node.getComponent('warRole').pub_getAtt())
           
        }
        function attackEnd(){
            for(var index in that.MonsterArr){
                var blood = that.MonsterArr[index].getComponent('warRole').pub_getlife()
                var name  = that.MonsterArr[index].getComponent('warRole').pub_getname()
                var survival=  that.MonsterArr[index].getComponent('warRole').pub_getSurvival()
                cc.log(name,"生命值 : ",blood,"生存情况 :",survival)
            }
            if(fighter.length > 0) {
                that.fighting(fighter, beHiter)
            }else{
                that.beginWar()
            }
        }
    },
    onDestroy: function(){
    },

你可能感兴趣的:(战斗代码)