打靶游戏

设置好打靶图片和准心的图片。设置点击的时候发射子弹,并发射子弹的时候出现效果并移除

sheji:function(touch){
        var s = touch.getLocation();
        var pic3 = new cc.Sprite(res.pic_3)
        pic3.setPosition(s);
        this.addChild(pic3);
        setTimeout(function(){
            pic3.removeFromParent()
        },1000)
    },

判断点击打靶的时候多少分数,定义打靶圆心的位置设置一个全局变量

 circle:null,

在点击的地方输出圆心点击位置

onTouchBegan:function(touch, event){
                    cc.log(touch.getLocation())
                    return true;
            },

定义好圆心的坐标

this.circle = cc.p(400,230);

然后根据圆心的位置来设置范围来规定分数

_biaoji:function(touch){
       var dise = cc.pDistance(touch.getLocation(),this.circle)
       if(dise>=0 && dise<=30){
           this.dis = "A";
       }else if(dise>=30 && dise<=60){
           this.dis = "B";
       }else if(dise>=60 && dise<=90){
           this.dis = "C";
       }else if(dise>=90 && dise<=120){
           this.dis = "D";
       }else if(dise>=120 && dise<=150){
           this.dis = "E";
       }else{
          this.dis = "F";
       }

       switch(this.dis){
           case "A":
               this.make.string = "100";
               cc.log("我进来了。。。。")
               break;
           case "B":
               this.make.string = "75";
               break;
           case "C":
               this.make.string = "50";
               break;
           case "D":
               this.make.string = "25";
               break;
           case "E":
               this.make.string = "10";
               break;
           case "F":
               this.make.string = "0";
               break;
       }
   }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值