橡皮怪Dici,over,welcome,player

Dici

cc.Class({
    extends: cc.Component,
    properties:
    {
        //主角遇刺音效
        dieAudio:
        {
           default:null,
           url:cc.AudioClip
        },
    },

    onLoad: function () 
    {
        //計時器
        this.schedule(this.setDiciMove,1);
        //爲屏幕設置觸摸偵聽事件,控制地刺移動
        this.node.parent.on(cc.Node.EventType.MOUSE_ENTER,this.setDiciMove.bind(this),this);
    },

    //設置地刺移動
    setDiciMove:function()
    {     
        var goAction= cc.moveBy(1,cc.p(-960,0));
        this.node.runAction(goAction);
    },

    //返回地刺在世界座標中的包圍盒
    noteBox:function()
    {
        return this.node.getBoundingBoxToWorld();
    },

    update: function (dt) 
    {
        var player = cc.find("Canvas/player").getComponent("Player");
        if(cc.rectIntersectsRect(player.node.getBoundingBoxToWorld(),this.noteBox()))
        {
            cc.audioEngine.playEffect(this.dieAudio,false);
           //cc.director.loadScene('over');
        }
        if(this.node.y > cc.winSize.height/2)
        {
            this.node.destroy();
        }
    },
});```


**over**

cc.Class({
extends: cc.Component,

properties: 
{
   scoreLabel:cc.Label,     //本輪得分文本
   button:cc.Node,          //重新開始按鈕
   highScoreLab:cc.Label,   //最高分文本
   breakRecordParticle:cc.ParticleSystem,
},


breakRecordAction:function()
{
  var action1 = cc.scaleTo(0.2,1.2);
  var action2 = cc.scaleTo(0.2,1);
  var seq = cc.sequence(action1, action2);
  var repeat = cc.repeatForever(seq);
  return repeat;
},

onLoad: function () 
{
    this.breakRecordParticle.enabled = false;
    var highScore = cc.sys.localStorage.getItem("highScore") || 0;
    var score = cc.sys.localStorage.getItem("score");
    cc.director.preloadScene("game");
    if(Number(highScore) < Number(score))
    {
        this.breakRecordParticle.enabled = true;
        this.highScoreLab.node.runAction(this.breakRecordAction());
        cc.sys.localStorage.setItem("highScore",Number(score));
    }
    highScore = cc.sys.localStorage.getItem("highScore");
    this.highScoreLab.string = "HighScore: " + highScore;
    this.scoreLabel.string = "本輪得分:"+score;
    this.button.on("touchstart",function(){
        cc.director.loadScene("game");
    });
},

});


**welcome**

cc.Class({
extends: cc.Component,
properties:
{
//背景音樂
bgAudio:
{
default:null,
url:cc.AudioClip
},
//按鈕圖標
startBtn: cc.Node,
},

onLoad: function () 
{
    cc.audioEngine.playMusic(this.bgAudio,true);
    cc.director.preloadScene("game");
    var scaleTo = cc.scaleTo(0.8,0.9);
    var reverse = cc.scaleTo(0.8,1);
    var seq = cc.sequence(scaleTo,reverse);
    var repeat = cc.repeatForever(seq);
    this.startBtn.runAction(repeat);
    this.startBtn.on("touchstart",function(){
         cc.audioEngine.pauseMusic();
         cc.director.loadScene("game");
    });
},

});



**player**

cc.Class({
extends: cc.Component,

properties: {},

onLoad: function (){},

noteBox:function()
{
    return this.node.getBoundingBox();
}

});
“`

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章