【开源】在嘉定存活的100种方式小游戏开源
大概是给学生会做的最后一件大事了吧(好伤感。。。)
先附上游戏主体部分源码
var play=function(){ $(".container").hide(300); $(window).on("touchstart",function(e){ e.preventDefault(); }); var b_good=["lsc","dlwy","lz","gef","hte","kq","mtl","mm","fdsys","dzgcg","cxfsys","al","bl","cl","dl","el","fl","gl","hl","tdg","kwg","nyg","zxg","dcg","txg","txl","tdl","jrl","jsl","chy","qgy","lyer","gh101"]; var b_bad=["gk","jsydhyn","atljc","zcwsj"]; var b_break=["yydxc","nvb","jhdy","kmsdtyg","tqwsyp"]; var b_move=["bak","tsgdyf"]; var hei=$(window).height(); var wid=$(window).width(); var frame=$("#game"); var man=$("#man"); $("#game").animate({ top:"0px" },500); var t=$(document.createElement("div")).addClass("ban").addClass("good"); frame.append(t); t.css({ left:(wid-t.width())/2+"px", top:hei-t.height()+"px" }); t.addClass(b_good[randint(0,b_good.length)]); var manl=wid/2-21; var mant=hei-t.height()-300; var mans=0; man.css({ left:manl+"px", top:mant+"px" }); var banlist=[t]; var banmake=0; var banspace=0; var nows=4; var manws=0; score=0; var subscore=0; var scoreitem=$("#score span"); $("#btn-l-real").on("touchstart",function (){ manws=-10; $("#man").removeClass("r").addClass("l"); }); $("#btn-l-real,#btn-r-real").on("touchend",function (){ manws=0; }); $("#btn-r-real").on("touchstart",function (){ manws=10; $("#man").removeClass("l").addClass("r"); }); scoreitem.html(0); var int=setInterval(function (){ nows+=0.001; if (subscore++>40){ subscore=0; score++; scoreitem.html(score); } mans+=1.5; for (var i=0;i<banlist.length;){ var tt=banlist[i].css("top").replace(/[^0-9^\-^.]/ig,"")-0; var tl=banlist[i].css("left").replace(/[^0-9^\-^.]/ig,"")-0; if (tl-manl<21 && tl+banlist[i].width()>manl && mant+25<=tt && mant+40+mans>=tt){ mans=Math.min(mans,Math.max(0,tt-mant-40)); if (mans==0 && banlist[i].hasClass("break")){ banlist[i].fadeTo(300,0,function (){ $(this).remove(); }); for (var j=i;j<banlist.length-1;j++){ banlist[j]=banlist[j+1]; } banlist.length--; continue; } if (banlist[i].hasClass("bad")){ clearInterval(int); gameend(); } if (banlist[i].hasClass("bak")){ manl+=5; } if (banlist[i].hasClass("tsgdyf")){ manl-=5; } } if (tt<-banlist[i].height()){ banlist[i].remove(); for (var j=i;j<banlist.length-1;j++){ banlist[j]=banlist[j+1]; } banlist.length--; }else{ banlist[i].css("top",tt-nows); i++; } } if (mans==0){ mant-=nows; }else{ mant+=mans; } manl+=manws; if (manl<0){ manl=0; } if (manl>wid-21){ manl=wid-21; } man.css({ left:manl+"px", top:mant+"px" }); if (mant>hei || mant<0){ clearInterval(int); gameend(); } banmake++; banspace++; var tr=randint(1,1000); if ((banspace>30 && tr>950) || banmake>40){ banspace=0; if (banmake>40){ var type=0; }else{ var type=randint(0,4); } if (type==0){ banmake=0; } var t=$(document.createElement("div")).addClass("ban"); if (type==0){ t.addClass("good").addClass(b_good[randint(0,b_good.length)]); }else if (type==1){ t.addClass("bad").addClass(b_bad[randint(0,b_bad.length)]); }else if (type==2){ t.addClass("move").addClass(b_move[randint(0,b_move.length)]); }else{ t.addClass("break").addClass(b_break[randint(0,b_break.length)]); } frame.append(t); t.css({ top:hei+"px", left:randint(0,wid-t.width())+"px" }); banlist[banlist.length]=t; } },33); }其中
var b_good=["lsc","dlwy","lz","gef","hte","kq","mtl","mm","fdsys","dzgcg","cxfsys","al","bl","cl","dl","el","fl","gl","hl","tdg","kwg","nyg","zxg","dcg","txg","txl","tdl","jrl","jsl","chy","qgy","lyer","gh101"]; var b_bad=["gk","jsydhyn","atljc","zcwsj"]; var b_break=["yydxc","nvb","jhdy","kmsdtyg","tqwsyp"]; var b_move=["bak","tsgdyf"];这四个数组分别记录好,坏,动,碎板的classname。
gameend()为另外编写的游戏结束后的函数
manl为人物X坐标
mant为Y坐标
mans为人物下落速度
banmake,banspace为生成板的计时参数
nows为当前板上升速度
manws为人物横向速度
banlist为记录所有板(记录方式为object)的数组
然后我就是任性不写注释,你们自己慢慢看吧
2016
05 31
上一篇
Older
下一篇
Newer
评论
0
点击
2083