疯狂火箭哥

欢迎来到程序小院

疯狂火箭哥

玩法:选择游戏人物,人物随手指上下滑动而升降,游戏共计30秒,
撞到小鸟和云朵时间减去2秒,撞到包裹时间加1秒,快去飞行吧^^。

开始游戏icon-default.png?t=N7T8https://www.ormcc.com/play/gameStart/253

html

<canvas id="gameCanvas" width="320" height="480"></canvas>

css

body, canvas, div {
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  -khtml-user-select: none;
}

js

var gameScene = cc.Scene.extend({
  gameLayer:null,
  timerID:null,
  px:0,
  onEnter:function () {
      this._super();
      cc.spriteFrameCache.addSpriteFrames(res.a_spriteList);
      this.gameLayer = new cc.Layer();
      this.gameLayer.addChild(new BackgroundLayer(), 0, TagOfLayer.background);
      this.gameLayer.addChild(new AnimationLayer(), 0, TagOfLayer.Animation);
      this.addChild(this.gameLayer);
      this.addChild(new StatusLayer(),0,TagOfLayer.Status);
      this.schedule(function () {
              /*if(g_time <= 0){
                  cc.eventManager.removeAllListeners();
                  this.overLabel = new cc.LabelTTF("没油啦!紧急迫降!","Arail",30);
                  this.overLabel.color = cc.color.RED;
                  this.overLabel.attr({
                      x:cc.winSize.width/2,
                      y:cc.winSize.height/2,
                      anchorX:0.5,
                      anchorY:0.5
                  });
                  this.addChild(this.overLabel);
              }*/
              g_time --;
          /*moveTime -= 0.1;
          if(g_moveTime <= 0.5){
              g_moveTime = 0.5;
          }*/
      },1);
      this.scheduleUpdate();
      this.initIntroduce();
  },
  update:function(){
      var statusLayer = this.getChildByTag(TagOfLayer.Status);
      statusLayer.updateTimer(g_time);

      if(g_time > 0){
          statusLayer.updateMeter();
      }

      if(g_gameStatus != 0){
          cc.director.pause();
          if(g_gameStatus == 2){
              /*var prizePanel = new cc.Sprite(res.a_prizePanel);
              prizePanel.attr({
                  x:cc.winSize.width/2,
                  y:cc.winSize.height/2,
                  anchorX:0.5,
                  anchorY:0.5,
                  scale:0.5
              });
              this.addChild(prizePanel,20);

              var goonMenu = new cc.MenuItemImage(
                  res.a_btnGn,
                  res.a_btnGs,
                  function(){
                      g_gameStatus = 0;
                      g_time = g_tempTime;
                      this.removeChild(prizePanel,true);
                      this.removeChild(menu,true);
                      cc.director.resume();
                  },this
              );
              goonMenu.attr({
                  scale:0.5,
                  anchorX:0.5,
                  anchorY:0.5
              });
              var menu = new cc.Menu(goonMenu);
              menu.x = cc.winSize.width/2;
              menu.y = cc.winSize.height/3+10;
              this.addChild(menu,20);*/
          }else{
              //stop bg music
              //cc.audioEngine.stopMusic();

              //clearInterval(this.timerID);
              cc.eventManager.removeAllListeners();
              this.addChild(new GameOverLayer(),20);
          }
      }
  },
  initIntroduce:function(){
      var introduce = new cc.Sprite(res.a_introduce);
      introduce.attr({
          anchorX:0.5,
          anchorY:0.5,
          x:cc.winSize.width/2,
          y:cc.winSize.height/2+20,
          scale:cc.winSize.width/640
      });
      this.addChild(introduce,10);
      var self = this;
      var listener = cc.EventListener.create({
          event: cc.EventListener.TOUCH_ONE_BY_ONE,
          swallowTouches: true,
          onTouchBegan: function (touch, event) {
              var target = event.getCurrentTarget();
              var locationInNode = target.convertToNodeSpace(touch.getLocation());
              var s = target.getContentSize();
              var rect = cc.rect(0, 0, s.width, s.height);

              if(cc.rectContainsPoint(rect, locationInNode)) {
                  self.removeChild(introduce,true);
                  //alert("g_playNum的值:"+g_playNum+"g_IsSub的值:"+g_IsSub);
                  self.judge();
                  return false;
              }
              return false;
          }
      });
      cc.eventManager.addListener(listener,introduce);
      cc.director.pause();
  },
  judge:function(){
      if(g_playNum<=0){
          //TODO:显示分享到朋友圈可获得抽奖机会
    cc.eventManager.removeAllListeners();
          this.createShare();
          //TODO:图片的切换效果
      }else{
          g_playNum--;
          cc.director.resume();
      }
  },
  createShare:function(){
  cc.director.pause();
      //显示该精灵时,不响应点击
      this.IsShow=true;
      var sharePopup = cc.Sprite.create(res.a_wanle_png);
      sharePopup.attr({
          x:cc.winSize.width/2,
          y:cc.winSize.height/2,
          scale:0.5
      });
      this.addChild(sharePopup,4);

      //create button
      var shareItem= new cc.MenuItemImage(
          res.a_btnShn,
          null,
          this.OnShare,this
      );
      shareItem.attr({
          x:cc.winSize.width/2,
          y:cc.winSize.height/2-130,
          anchorX:0.5,
          anchorY:0.5,
          scale:0.5
      });
      //create menu
      var menu = new cc.Menu(shareItem);
      menu.setPosition(cc.p(0,0));
      this.addChild(menu,4);
  },
  OnShare:function(){
      this.guidePng = new cc.Sprite(res.a_guide_jpg);
      this.guidePng.attr({
          anchorX:0.5,
          anchorY:0.5,
          x:cc.winSize.width/2,
          y:cc.winSize.height/2,
          scale:cc.winSize.height/960
      });
      this.addChild(this.guidePng,100);

      var self = this;
      var listener = cc.EventListener.create({
          event: cc.EventListener.TOUCH_ONE_BY_ONE,
          swallowTouches: true,
          onTouchBegan: function (touch, event) {
              var target = event.getCurrentTarget();
              var locationInNode = target.convertToNodeSpace(touch.getLocation());
              var s = target.getContentSize();
              var rect = cc.rect(0, 0, s.width, s.height);

              if(cc.rectContainsPoint(rect, locationInNode)) {
                  self.removeChild(target,true);
                  return false;
              }
              return false;
          }
      });
      cc.eventManager.addListener(listener,this.guidePng);
  }
});
var g_percent = 100;
var g_score = 0;
var g_share = 0;
var g_moveTime = 3;

var g_gameStatus = 0;
var g_prizeStatus = 0;


//剩余时间
var g_time = 30;
//可以玩的次数
/*var g_playNum=30;
//是否为第一次游戏
var g_firstPlay=1;//1:是第一次玩 0:不是第一次玩
//用户是否已经提交过手机号
var g_IsSub=null;//如果为空,没有提交过手机号,否则,会传过来提交的手机号*/
//玩家选择的角色性别
var g_roleSex = "man";
var g_packetNum = 0;

//可以抽奖的次数
var g_awardTime = 0;
//是否中奖
var g_isAward = false;
//抽中索引的下标值为0【1~4】
var g_awardIndex=4;
//参与抽奖的限制
var g_awardlimiting = 15;
//触摸方式
var g_touchMethod = false;//false:按住上下移动 true:时刻坠落

var self=null;


if(typeof TagOfLayer == "undefined") {
    var TagOfLayer = {};
    TagOfLayer.background = 0;
    TagOfLayer.Animation = 1;
    TagOfLayer.GameLayer = 2;
    TagOfLayer.Status = 3;
};

// collision type for chipmunk
/*if(typeof SpriteTag == "undefined") {
    var SpriteTag = {};
    SpriteTag.player = 0;
    SpriteTag.rock = 1;
    SpriteTag.packet = 2;
    SpriteTag.qiqiu = 3;
};*/
SpriteTag = {
    player:0,
    rock:1,
    packet:2,
    qiqiu:3
};

var g_AwardIndex = [
    4,1,5,3,
    3,0,0,4,
    5,0,0,2,
    2,4,3,5
];
/**
 * Created by Administrator on 14-12-1.
 */
function GetDate(){
    /*//是否为第一次玩
    g_firstPlay=false;
    //可以玩的次数
    g_playNum=3;
    //是否提交过手机号
    g_IsSub=false;*/

    //用户的最多抽奖次数为99次
    //判断从后台传过来的数据是不是小于99次
    //要不要获取用户可以抽奖的次数
    //g_awardTime=0;
    //判断从后台传过来的数据是否有效
    //第一次玩次数为3,否则应该是大于0
}

//跳转到提交手机号页面
function GetPhone(){
    window.location.href = "get_phone.html";
}

//跳转到提交手机号页面
function GetAward(){
    window.location.href = "getMyGiftInfo.jsp";
}

//分享成功之后,调回到游戏页面
function hrefSU(){
 //alert("g_IsSub的值:"+g_IsSub);
    if(g_IsSub==""){
        window.location.href ="get_phone.html";
    }else{
        window.location.href = "http://m.suning.com/";
    }
}
//调用后台抽奖函数
function Post(){
    $.post("drawAward.action",function(data){
        //alert(data.msg);
        //alert("后台Post传过来的抽奖数据:【1~4】"+data.msg);
        g_awardIndex = data.msg;//4不中奖
        //alert("后台Post传过来的抽奖数据:【1~4】"+g_awardIndex);
    });
}

function ShareText(){
 window.appMessage.tTitle ="我在苏宁双12狂奔送货"+g_packetNum+"件,谁不服,来挑战!";
}
var StartLayer = cc.LayerColor.extend({
    sprite:null,
    IsShow:false,//是否显示提示框?
    ctor:function () {
        this._super();
        //this.getDate();
        cc.spriteFrameCache.addSpriteFrames(res.a_menuList);
        /*var size = cc.winSize;

        var start = new cc.MenuItemImage(
            res.a_btnSn,
            res.a_btnSs,
            this.onPlay, this);
        start.attr({
            x: size.width/2,
            y: size.height/8,
            anchorX: 0.5,
            anchorY: 0.5,
            scale:0.5
        });

        this.menu = new cc.Menu(start);
        this.menu.x = 0;
        this.menu.y = 0;
        this.addChild(this.menu, 10);

        this.sprite = new cc.Sprite(res.a_bg);
        this.sprite.attr({
            x: size.width / 2,
            y: size.height / 2,
            scale:size.height / 960
        });
        this.addChild(this.sprite, 0);

        this.sprite1 = new cc.Sprite(res.a_bgContent);
        this.sprite1.attr({
            x: size.width / 2,
            y: size.height / 2,
            scale:size.height / 980
        });
        this.addChild(this.sprite1, 0);*/
        //create bg
        var bg = cc.Sprite.create(res.a_bg_index);
        bg.attr({
            anchorX:0.5,
            anchorY:0.5,
            x:cc.winSize.width/2,
            y:cc.winSize.height/2,
            scale:0.5
        });
        this.addChild(bg,0);
        //显示“请选择游戏角色”
        // font definition【自定义字体名fontDefBlueStroke】
        /*var fontDefBlueStroke = new cc.FontDefinition();
        fontDefBlueStroke.fontName = "Impact";//系统
        fontDefBlueStroke.fontSize = 20;//字体大小
        fontDefBlueStroke.textAlign = cc.TEXT_ALIGNMENT_CENTER;//居中显示
        fontDefBlueStroke.verticalAlign = cc.VERTICAL_TEXT_ALIGNMENT_TOP;
        fontDefBlueStroke.fillStyle = cc.color(0,255,0);//主体颜色

        // stroke描边
        fontDefBlueStroke.strokeEnabled = true;//显示描边
        fontDefBlueStroke.strokeStyle = cc.color(0,0,0);//描边颜色

        var label = cc.LabelTTF.create("请选择游戏角色",fontDefBlueStroke);
        label.attr({
            x:cc.winSize.width/2,
            y:cc.winSize.height/2+100
        });
        this.addChild(label,1);*/

        //TODO:点击菜单时,菜单最好有特效
        //创建游戏角色选择菜单
        var manSprite = new cc.MenuItemImage(
            "#hjg0.png",
            "#hjg1.png",
            this.OnSelectMan,this
        );
        manSprite.attr({
            x:cc.winSize.width/2-70,
            y:cc.winSize.height/2+20,
            scale:0.3
        });

        var womanSprite = new cc.MenuItemImage(
            "#hjj0.png",
            "#hjj1.png",
            this.OnSelectWoman,this
        );
        womanSprite.attr({
            x:cc.winSize.width/2+70,
            y:cc.winSize.height/2+20,
            scale:0.3
    });

        var menu = new cc.Menu(manSprite,womanSprite);
        menu.setPosition(cc.p(0,0));
        this.addChild(menu,1);
  //alert("g_firstPlay = "+g_firstPlay+"  g_playNum = "+g_playNum+"  g_IsSub = " +g_IsSub);

        if(g_firstPlay==1){
            //第一次玩,显示“欢迎加入火箭送货团队,初次见面,奉上5元苏宁易购优惠券一张。立刻开始疯狂送货吧!”
            this.createMessage();
            this.IsShow=true;
        }

        return true;
    },/*,

    onPlay: function () {
        this.removeChild(this.menu,true);
        cc.director.runScene(new gameScene());
    }*/
    OnSelectMan:function(){
        //显示提示框时,不响应
        if(this.IsShow==true) return;
        g_roleSex="man";
        this.judge();
    },
    OnSelectWoman:function(){
        if(this.IsShow==true) return;
        g_roleSex="woman";
        this.judge();
    },
    /*getDate:function(){
        GetDate();
    },*/
    createMessage:function(){
      //create popup
      this.popup = cc.Sprite.create("#tk_5yuan.png");
      this.popup.attr({
         x:cc.winSize.width/2,
         y:cc.winSize.height/2,
         scale:0.5
      });
      this.addChild(this.popup,2);
      //设置层的透明度
      //this.setOpacity(100);
      //create button
      this.start = new cc.MenuItemImage(
          "#btn_5yuan.png",
          null,
          this.OnStart,this
      );
      this.start.attr({
          x:cc.winSize.width/2,
          y:cc.winSize.height/2-105,
          anchorX:0.5,
          anchorY:0.5,
          scale:0.5
      });
      //create menu
      var menu = new cc.Menu(this.start);
      menu.setPosition(cc.p(0,0));
      this.addChild(menu,3);
    },
    OnStart:function(){
        this.IsShow=false;
        this.setOpacity(0);
        //TODO:先执行一系列的动作,再隐藏
        this.popup.visible=false;
        this.start.visible=false;
    },
    judge:function(){
        /*if(g_playNum<=0){
            //TODO:显示分享到朋友圈可获得抽奖机会
            this.createShare();
            //TODO:图片的切换效果
        }else{
            //切换场景
            cc.director.runScene(new gameScene());
        }*/
        //切换场景
        cc.director.runScene(new gameScene());
    }/*,
    createShare:function(){
        //显示该精灵时,不响应点击
        this.IsShow=true;
        var sharePopup = cc.Sprite.create(res.a_guide_jpg);
        sharePopup.attr({
            x:cc.winSize.width/2,
            y:cc.winSize.height/2,
            scale:0.5
        });
        this.addChild(sharePopup,4);

        //create button
        var shareItem= new cc.MenuItemImage(
            res.a_btnAn,
            res.a_btnAs,
            this.OnShare,this
        );
        shareItem.attr({
            x:cc.winSize.width/2,
            y:cc.winSize.height/2,
            anchorX:0.5,
            anchorY:0.5,
            scale:0.5
        });
        //create menu
        var menu = new cc.Menu(shareItem);
        menu.setPosition(cc.p(0,0));
        this.addChild(menu,4);
    },
    OnShare:function(){
        this.guidePng = new cc.Sprite(res.a_guide_jpg);
        this.guidePng.attr({
            anchorX:0.5,
            anchorY:0.5,
            x:cc.winSize.width/2,
            y:cc.winSize.height/2,
            scale:cc.winSize.height/960
        });
        this.addChild(this.guidePng,100);

        var self = this;
        var listener = cc.EventListener.create({
            event: cc.EventListener.TOUCH_ONE_BY_ONE,
            swallowTouches: true,
            onTouchBegan: function (touch, event) {
                var target = event.getCurrentTarget();
                var locationInNode = target.convertToNodeSpace(touch.getLocation());
                var s = target.getContentSize();
                var rect = cc.rect(0, 0, s.width, s.height);

                if(cc.rectContainsPoint(rect, locationInNode)) {
                    self.removeChild(target,true);
                    return false;
                }
                return false;
            }
        });
        cc.eventManager.addListener(listener,this.guidePng);
    }*/
});

var MyScene = cc.Scene.extend({
    onEnter:function () {
        this._super();
  cc.audioEngine.playMusic(res.a_bgMusic_mp3,true);
        var layer = new StartLayer();
        this.addChild(layer);
    }
});

源码

需要源码请关注添加好友哦^ ^

转载:欢迎来到本站,转载请注明文章出处https://ormcc.com/

  • 9
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值