CocosCreatorに今ゲームが見ている前に、ピクセルの鳥のゲームを書いて2日間を過ごしたが、火災はまだかなりのゲームである前に、彼らは、どのように棚がわからない、それを考えるために行くの後にいくつかの時間を学びます理由の違反の元を見て、オンラインに見えた、スーパーマリオのゲーム要素は、ああ、外国の著作権意識がまだ高価ピクセルレベルのゲームです。さて、この上の脱線、と彼は本題にし始めました。
このゲームは難しいことではありません書く、最も重要なのはアイデア、どのように私はまた、C ++、簡単な言語、Cocos2dのオンライン版を見てきました、書き込みには大きな神をしている、の多くを持って、あります
これは創造主、Cocos2dとほとんど差の私のバージョンであるが、その差は大きくありません
まあ、コードの上に(スクリーンショットが欲しかったが、それでもそれを自分自身に公平であることを考える、または手)
このゲームは、私は、TSを書き込むために使用される、プラスCocosCreator
onLoad(){
//これは目の前の最初のステートメントである、鳥、パイプライン、背景、地上ノードを取得します。
//鳥
this.bird = cc.find( 'layout_wrap / node_bird'、this.node)
//背景
this.bg = cc.find( 'layout_wrap / layout_bg'、this.node)
//パイプライン
this.pipe = cc.find( 'layout_wrap / layout_cont'、this.node)
//土地
this.land = cc.find( 'layout_wrap / layout_land'、this.node)
//初期化データ
this.initData()
}
//ゲームデータのいくつかのステートメントを見て、ここで初期化します
プライベートinitData():無効{
this.time = 0 //フレームレート(コールあたりのフレーム、アナログ鳥が羽ばたきます)
this.speed = 0 //スピード
this.distance = 150 //ダクトから
this.rateSpeed = 1 //移速
this.upSpeed = 2 //加速
this.slowSpeed = 0.06 //減速
//イベントを実行している聞きます
聞かせてラップ= cc.find( 'layout_wrap'、this.node)
wrap.on(cc.Node.EventType.TOUCH_START、this.runnIng.bind(本)、この)
//インターフェースを開始
this.layoutstar = cc.find( 'layout_wrap / layout_star'、this.node)
// [スタート]ボタン
this.starbtn = cc.find( 'layout_content / button_play'、this.layoutstar)
this.addClickEvent(this.starbtn、 'onClickStar')
//一時停止ボタン
pausebtn = cc.find( 'node_score / button_pause'、ラップ)しましょう
this.addClickEvent(pausebtn、 'onClickPause')
//ボタンを続行
resumebtn = cc.find( 'layout_pause / button_resume'、ラップを)聞かせて
this.addClickEvent(resumebtn、 'onClickResume')
//ゲームが終わって、再びスタート
聞かせて再びcc.findを=( 'layout_over / node_content / button_play'、ラップ)
this.addClickEvent(再び、 'onClickAgain')
//レディプロンプトノードを取得します。
this.ready = cc.find( 'node_score / node_ready'、ラップ)
//エンドゲーム
this.gameover = cc.find( 'layout_over'、ラップ)
//ロードチューブ
this.addPipe()
//衝突システム
聞かせマネージャー= cc.director.getCollisionManager()
真= manager.enabled
}
//次の関数は、書き始めました
[スタート]ボタンをクリックし//
保護onClickStar():ボイド{
//ズームインターフェース
せ行為= cc.callFunc(()=> {
偽= this.layoutstar.active
this.layoutstar.destroy()
})
//ここでは、アニメーションの少しも、システムやフェードのズーム操作を使用します
seqが= cc.sequence(cc.spawn(cc.scaleTo(0.3、0)、cc.fadeOut(0.3))、行為)しましょう
IF(this.layoutstar){
this.layoutstar.runAction(配列)
}
//ここでは、エンド・インタフェースが隠されていないことを忘れないようにすることです
IF(this.gameover){
偽= this.gameover.active
}
}
//実行]をクリックします
プライベートRUNNING():無効{
もし(this.ready.active &&!this.layoutstar.active){
//レディプロンプトノードを取得隠します
偽= this.ready.active
//表示の更新、スイッチとしてISONアップデート
this.ison =真
}
鳥にthis.speed = 2.5 //上向きに加速
}
ここ//ロードチューブ、パイプは、プリフォームをアップロードすることです
プライベートaddPipe():無効{
this.LoadPrefabs( 'node_pipe'、(N:cc.Node)=> {
{(!N)の場合
リターン
}
{(;私は4 <I ++は、I = 0せて)のために
//コピーノード
聞かせてコピー= cc.instantiate(N)
//挿入ノード
this.pipe.addChild(コピー、I)
//パイプの位置を調整
copy.x = this.node.width / 2 +(this.distance + copy.width)* I
// 480〜720
copy.y =(Math.random()* 0.5 + 1)×480
IF(I> 0){
//隣接する管の間の隙間は、120を超えません
this.distanceY(I、I - 1)
}
}
})
}
//背景を動かします
プライベートmoveBg(BGS:cc.Node):無効{
bgs.x = bgs.x - 1
//背景が画面の外に移動し、背景の背景と2つのフロント
//ピクセルスナップ、そうbg.xの正確な数
IF(bgs.x <-614){
bgs.x = 1228
//ノードの順序を調整
IF(BGS == this.bg.children [0]){
this.bg.children [1] = 0 .zIndex
this.bg.children [2] .zIndex = 1
this.bg.children [0] .zIndex = 2
}そうであれば(BGS == this.bg.children [1]){
this.bg.children [2] = 0 .zIndex
this.bg.children [0] .zIndex = 1
this.bg.children [1] .zIndex = 2
}そうであれば(BGS == this.bg.children [2]){
this.bg.children [0] = 0 .zIndex
this.bg.children [1] .zIndex = 1
this.bg.children [2] .zIndex = 2
}
}
}
//パイプラインを移動
プライベートmovePipe(パイプ:cc.Node):無効{
pipes.x = pipes.x - 2
//導管ワイド画面を移動し、画面の右側に、パイプの位置を変更します
IF(pipes.x < - (pipes.width + this.node.width / 2)){
pipes.x = 515
// 480〜1000年
pipes.y =(Math.random()+ 1)* 520から40
//隣接する管の間の隙間は、120を超えません
IF(パイプ== this.pipe.children [0]){
this.distanceY(0,3)
}そうであれば(パイプ== this.pipe.children [1]){
this.distanceY(1、0)
}そうであれば(パイプ== this.pipe.children [2]){
this.distanceY(2、1)
}そうであれば(パイプ== this.pipe.children [3]){
this.distanceY(3、2)
}
}
}
//土地を移動
プライベートmoveLand(ランド:cc.Node):無効{
lands.x = lands.x - 2 * this.rateSpeed
//とき陸上移動ワイドスクリーン、その後、画面の右側にある土地の位置を変更します
IF(lands.x < - (this.node.width)){
lands.x = this.node.width - 2 * this.rateSpeed
}
}
隣接するパイプ間// Y方向隙間
プライベートdistanceY(:数、B:数):無効{
IF(Math.abs(this.pipe.children [A] .Y - this.pipe.children [B] .Y)> 140){
this.pipe.children [A] .Y = this.pipe.children [B]・Y +((Math.random()* 1 - 2)* 140)
IF(this.pipe.children [A] .Y> 1000){
this.pipe.children [A] .Y = this.pipe.children [B] .Y - (Math.random()* 140)
}そうであれば(this.pipe.children [A]・Y <480){
this.pipe.children [A] .Y = this.pipe.children [B]・Y +(Math.random()* 140)
}
}
}
//主なものは、スムーズな効果を形成するために、このアイデアで、すべてのフレームにそれを呼び出す必要があり、
アップデート(DT:数){
//モバイル終了
{(this.gameover.active)場合
this.ison =偽
}
//スイッチングノードの表示フレームレート、アナログ翼ファン
IF(this.ison){
timeTemp = this.time + dtをしましょう
this.time = timeTemp
IF(this.time> 0.5){
IF(this.bird.children [0] .active){
偽= [0] .active this.bird.children
真= [1] .active this.bird.children
}
そうであれば(this.bird.children [1] .active){
偽= [1] .active this.bird.children
真= [2] .active this.bird.children
}
そうであれば(this.bird.children [2] .active){
偽= [2] .active this.bird.children
真= [3] .active this.bird.children
}
そうであれば(this.bird.children [3] .active){
偽= [3] .active this.bird.children
真= [0] .active this.bird.children
}
//ゼロにリセットすることを忘れないでください。
this.time = 0
}
//減速の鳥与え辞退します
this.speed = this.speed - 0.06
// y軸に鳥を動かします
this.bird.y = this.bird.y + this.speed
//飛ぶ鳥の方向を変える、鳥は、回転方向の向きを変化させることによって達成されます。
this.bird.angle = this.speed * 10
//背景を動かします
this.moveBg(this.bg.children [0])
this.moveBg(this.bg.children [1])
this.moveBg(this.bg.children [2])
//パイプラインを移動
this.movePipe(this.pipe.children [0])
this.movePipe(this.pipe.children [1])
this.movePipe(this.pipe.children [2])
this.movePipe(this.pipe.children [3])
//土地を移動
this.moveLand(this.land.children [0])
this.moveLand(this.land.children [1])
}
}
//これは、スクリプト、スクリーンとそれを行うための機能のメインシーンに搭載されているが、終了しない場合、私はこのゲームがあまりにも面白いではないと考えています
//どのようにゲームを終了するには?鳥がパイプに取り付けられたとき、つまり、ゲームが終わって、いない場合は、それがプラスになります
//ここでは、衝突を書き込むために使用され、もちろん、あなたが達成するために、他の道を行くことができます
//このスクリプトは鳥のノードにマウントされています
//ロード時間は、初期のスコアになります
onLoad(){
//得点
this.gameMain.Score = 0
//ノードのスコア
this.topScore = cc.find( 'node_score / label_score'、this.node.parent)
}
//本明細書で使用される衝突、鳥、パイプ、及びギャップの中央には、結合アセンブリが衝突します
//鳥がパイプを打つ、ゲームの終わり、
//ギャップの仲介による鳥、プラス1ポイント
onCollisionEnter(他の、自己){
IF(other.tag == 2){
this.gameMain.Score ++
}もしそうでなければ(other.tag == 1){
this.gameOver()
}
//表示のスコア
this.topScore.getComponent(cc.Label).string = this.gameMain.Score.toString()
}
//エンドゲーム
プライベートゲームオーバー():無効{
ゲームのインターフェイスの終わりを表示します//
聞かせてゲームオーバー= cc.find( 'layout_over'、this.node.parent)
真= gameover.active
//フェード
gameover.runAction(cc.fadeTo(0.5、255))
//得点
聞かせてscorelabel = cc.find( 'node_content / sprite_panel / label_score'、ゲームオーバー).getComponent(cc.Label)
scorelabel.string = this.gameMain.Score.toString()
//スコアをリセット
this.scheduleOnce(()=> {
this.gameMain.Score = 0
}、0.5)
}
まあ、鳥の単純な単一のピクセルだけでなく、私たちは私の小さな友人のより詳細なソースをしたいが~~ああささやくことができます
次のリリースのレンダリングが、残念ながら、サーバーをマウントしていないWebプラットフォームに直接アップロードすることができない、それだけでGIFをリリースすることができます