Cocos2d别踩白块儿游戏源码

Cocos2d别踩白块儿游戏源码,第1张

概述授权协议:GPL 开发语言:JavaScript *** 作系统:跨平台 别踩白块儿游戏源码(CocosEditor) 详细介绍 游戏源代码下载 运行demo需要配置好CocosEditor,暂不支持其他工具。demo是跨平台的,可移植运行android,ios,html5网页等,代码是基于javasc
      GPL        JavaScript        跨平台        
别踩白块儿游戏源码(CocosEditor)详细介绍
游戏源代码下载 运行demo需要配置好CocosEditor,暂不支持其他工具。demo是跨平台的,可移植运行androID,ios,HTML5网页等,代码是基于JavaScript语言,cocos2d-x游戏引擎,CocosEditor手游开发工具完成的。 github下载: https://github.com/makeapp/cocoseditor-piano 不同平台下的效果图: windows平台 HTML5平台 androID平台 代码分析:(只挑选核心主代码分析,更多细节自行研究源码) 1 创建曲谱数组 do、re、mi、fa,sol、la、duo
CITY_OF_SKY=[4,3,4,1,7,6,5,3];
2 初始化表格,本来先创建4*曲谱数组长度的表格,但为了优化,先创建4*5表格,使用时候再不断新建增加表格;
//tablesthis.tables=newArray(this.pianolengthIndex);for(varj=0;j<this.pianolength;j++){varSprites=newArray(4);varrandom=getRandom(4);for(vari=0;i<4;i++){Sprites[i]=this.newBlock(i,j,random);}this.tables[j]=Sprites;}
3 创建单个表格元素,可根据colortype在一行里确定一个黑色元素
MainLayer.prototype.newBlock=function(i,colorType){//simpleblockvarblock=cc.Sprite.create("res/whiteBlock.png");block.setposition(cc.p(this.blockWIDth/2+this.blockWIDth*i,this.blockHeight/2+this.blockHeight*j));block.setScaleX(this.scaleX);block.setScaleY(this.scaleY);block.setZOrder(100);block.setAnchorPoint(cc.p(0.5,0.5));varcolor="white";if(j==0){block.setcolor(cc.c3b(0,255,0));}else{if(i==colorType){block.setcolor(cc.c3b(30,30,30));color="black";}}block.blockData={col:i,row:j,color:color};this.blockNode.addChild(block);returnblock;};
4 触摸表格,如果是黑色;如果是当前一行的上一行才能继续; #如果没到顶,创建新的一行moveAddNewSprites,如果到顶了,创建分数结束节点createtopOverNode; #如果整个表格移动到顶if (block.blockData.row == (this.pianolengthIndex - 1)),游戏结束this.gameStatus = OVER; #如果没到顶,整个表格往下移一行this.blockNode.runAction(cc.Moveto.create(0.2,cc.p(0,(this.blockNode.getpositionY() - this.blockHeight * heightNum)))); #单个元素运行一个缩放动画,移动步数+1;this.moveNum += 1;
//touchblackif(block.blockData.color=="black"){if(block.blockData.row==(this.moveNum+1)){//createnewspriteif(this.pianolength<this.pianolengthIndex){//notreachtopthis.moveAddNewSprites();}if(this.pianolength==this.pianolengthIndex){//whenreachtopthis.createtopOverNode();}//movedowncc.AudioEngine.getInstance().playEffect(PIANO_SIMPLE[this.pianoListIndex[j-1]],false);block.setcolor(cc.c3b(100,100,100));varheightNum=1;if(block.blockData.row==(this.pianolengthIndex-1)){//whenlastrow,gamesuccessend,movetwoheightheightNum=2;cc.log("end");this.gameStatus=OVER;cc.AudioEngine.getInstance().playEffect(SOUNDS.win,false);}this.blockNode.runAction(cc.Moveto.create(0.2,cc.p(0,(this.blockNode.getpositionY()-this.blockHeight*heightNum))));this.moveNum+=1;block.runAction(cc.Sequence.create(cc.Scaleto.create(0,this.scaleX*4/5,this.scaleY),cc.Scaleto.create(0.2,this.scaleX,this.scaleY)));}}
5触摸表格,如果是白色,游戏结束; #创建分数结束节点this.createtopOverNode(); #改变分数节点的颜色背景,结果失败;
this.createtopOverNode();//createscorenodeandmovethis.gameStatus=OVER;cc.AudioEngine.getInstance().playEffect(SOUNDS.error,false);block.setcolor(cc.c3b(255,0,0));block.runAction(cc.Sequence.create(cc.Scaleto.create(0,this.scaleY*4/5),this.scaleY)));this.scoreNode.bgcolor.setcolor(cc.c3b(255,0));this.scoreNode.result.setString("失败了");this.scoreNode.runAction(cc.Moveto.create(0.2,this.blockHeight*this.moveNum)));
6 创建添加新的一行
MainLayer.prototype.moveAddNewSprites=function(){cc.log("moveAddNewSprites");varSprites=newArray(4);varrandom=getRandom(4);for(vark=0;k<4;k++){Sprites[k]=this.newBlock(k,this.pianolength,random);}this.tables[this.pianolength]=Sprites;this.pianolength+=1;};
7 分数结束节点创建函数
MainLayer.prototype.createtopOverNode=function(){//topscorenodethis.scoreNode=cc.Node.create();this.scoreNode.setposition(cc.p(0,this.blockHeight*this.pianolength));this.scoreNode.setAnchorPoint(cc.p(0,0));this.scoreNode.setZOrder(130);this.blockNode.addChild(this.scoreNode);//colorbgvarbgcolor=cc.Sprite.create("res/whiteBlock.png");bgcolor.setposition(cc.p(0,0));bgcolor.setScaleX(720/300);bgcolor.setScaleY(1280/500);bgcolor.setAnchorPoint(cc.p(0,0));bgcolor.setcolor(cc.c3b(0,0));this.scoreNode.addChild(bgcolor);this.scoreNode.bgcolor=bgcolor;//modevarwordsMode=["经典","街机","禅"];varmodeLabel=cc.LabelTTF.create(wordsMode[GAME_MODE]+"模式","Arial",70);this.scoreNode.addChild(modeLabel);modeLabel.setposition(cc.p(350,1000));modeLabel.setcolor(cc.c3b(0,0));modeLabel.setAnchorPoint(cc.p(0.5,0.5));//resultvarresultLabel=cc.LabelTTF.create("成功了",110);this.scoreNode.addChild(resultLabel);resultLabel.setposition(cc.p(360,750));resultLabel.setAnchorPoint(cc.p(0.5,0.5));resultLabel.setcolor(cc.c3b(139,58,58));this.scoreNode.result=resultLabel;//backvarbackLabel=cc.LabelTTF.create("返回",50);this.scoreNode.addChild(backLabel);backLabel.setposition(cc.p(200,400));backLabel.setAnchorPoint(cc.p(0.5,0.5));backLabel.setcolor(cc.c3b(0,0));this.scoreNode.back=backLabel;//returnvarreturnLabel=cc.LabelTTF.create("重来",50);this.scoreNode.addChild(returnLabel);returnLabel.setposition(cc.p(500,400));returnLabel.setAnchorPoint(cc.p(0.5,0.5));returnLabel.setcolor(cc.c3b(0,0));this.scoreNode.return=returnLabel;};
这是经典模式的核心代码,这一篇就到这里; cocos2d-x跨平台游戏引擎 cocos2d-x是全球知名的游戏引擎 ,引擎在全球范围内拥有众多开发者,涵盖国内外各知名游戏开发商。目前Cocos2d-x引擎已经实现横跨ios、AndroID、Bada、MeeGo、BlackBerry、Marmalade、windows、linux等平台。编写一次,到处运行,分为两个版本 cocos2d-c++和cocos2d-Js本文使用了后者; cocos2d-x 官网: http://cocos2d-x.org/ cocos2d-x 资料下载 http://cocos2d-x.org/download CocosEditor开发工具: CocosEditor,它是开发跨平台的手机游戏工具,运行window/mac系统上,JavaScript脚本语言,基于cocos2d-x跨平台游戏引擎,集合代码编辑,场景设计,动画制作,字体设计,还有粒子,物理系统,地图等等的,而且调试方便,和实时模拟; CocosEditor官方博客: http://blog.makeapp.co/;


查看原文:http://www.51xyyx.com/2679.html
总结

以上是内存溢出为你收集整理的Cocos2d别踩白块儿游戏源码全部内容,希望文章能够帮你解决Cocos2d别踩白块儿游戏源码所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1083661.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存