123456789101112131415161718192021222324252627282930313233343536373839 |
- var lefts=Math.floor(Math.random()*200);var _timer=parseInt(Date.now()+Math.random()*100000000000);window.shareData={imgUrl:"http://wbpkh5001.17c.cn/html5/h5mini/jumpingFrog/img/icon.jpg",timeLineLink:"http://url.cn/Zy7vkz?timer="+_timer,tTitle:"蛙蛙跳",tContent:"小荷轻轻飘,青蛙跳跳跳~~"};
- var Game={canvas:null,cvs:null,scale:1,score:0,isFlow:null,isStart:true,isGame:false,isOver:false,isPlaySound:false,$el:{loading:$("#grid"),spn:$("#spn"),o_btn:$("#o_btn"),scoreId:$("#score"),score:$("#score span"),btnStart:$("#btn_start"),btnTry:$("#btn_try"),btnMore:$("#btn_more"),btnShare:$("#btn_share"),scoreOver:$("#score_over"),share:$("#share"),scoreOverSpan:$("#score_over span")},bg:{speed:1,top1:0},yeziData:[{margin:127,left:500,top:60,width:127,height:127,img:"flow",isFlow:true,dir:"right",speed:4},{margin:640-(406+127),type:"left",left:256,top:300,width:127,height:127,img:"leaf",dir:"right",speed:4},{margin:256,type:"right",left:406,top:300,width:127,height:127,img:"leaf",dir:"right",speed:4},{left:256,top:540,width:127,height:127,img:"leaf",dir:"right",speed:4},{left:256,top:780,width:127,height:127,img:"leaf",dir:"right",speed:4}],yeziMove:false,qingwa:{left:278,top:804,width:83,height:79,img:"frog",dir:"right",speed:4},jumpFrog:{left:290,top:684,width:58,height:104,img:"jump_frog",dir:"right",speed:4},addScore:{left:200,top:780,width:50,height:40,img:"score_1",dir:"right",speed:4}};
- window.onload=function(){util.init();util.resize();window.onresize=function(){util.resize();};var a=[{key:"scorebtn",src:"img/scorebtn.png"},{key:"flow",src:"img/flow.png"},{key:"leaf",src:"img/leaf.png"},{key:"frog",src:"img/frog.png"},{key:"jump_frog",src:"img/jump_frog.png"},{key:"jump_wfrog",src:"img/jump_wfrog.png"},{key:"water",src:"img/water.png"},{key:"score_1",src:"img/score1.png"},{key:"score_3",src:"img/score3.png"},{key:"bg",src:"img/bg.png"},{key:"gamebg",src:"img/bg2.png"},{key:"startbtn",src:"img/start.png"},{key:"title",src:"img/title.png"},{key:"frogflow",src:"img/frogflow.png"},{key:"frogbg",src:"img/frog_bg.png"},{key:"more",src:"img/more.png"},{key:"share",src:"img/share.png"},{key:"try",src:"img/try.png"}];
- util.img.loadAll(a,function(){Game.$el.loading.hide();gameStart();});};function gameStart(){Game.canvas=$("#cvs");Game.cvs=Game.canvas.dom.getContext("2d");
- drawStart();initEvent();weixinShare();}function drawStart(){drawImage("bg",0,0,640,960);drawImage("startbtn",230,300,183,177);drawImage("title",130,120,409,122);
- drawImage("frogflow",0,544,640,416);Game.$el.btnStart.show();}function gameing(){Game.$el.btnStart.hide();runGame();Game.$el.o_btn.hide();Game.$el.scoreId.show();
- }var runGameTimer=null;function runGame(){if(Game.isStop){Game.yeziMove=false;Game.isGame=false;Game.isOver=true;setTimeout(gameOver,400);return;}update();
- draw();window.shareData.tTitle="萌萌哒~小青蛙跳出"+Game.score+"米,求超越!";runGameTimer=setTimeout(runGame,1000/60);}function gameOver(){Game.$el.o_btn.show();Game.$el.scoreId.hide();
- Game.$el.scoreOver.show();Game.$el.scoreOverSpan.html(Game.score);clearTimeout(runGameTimer);Game.cvs.clearRect(0,0,640,960);drawImage("bg",0,0,640,960);
- drawImage("frogbg",90,65,464,828);drawImage("try",160,460,324,96);drawImage("more",160,570,324,96);drawImage("share",160,685,324,96);Game.$el.btnStart.hide();
- Game.$el.btnTry.show();Game.$el.btnMore.show();Game.$el.btnShare.show();}function weixinShare(){document.addEventListener("WeixinJSBridgeReady",function a(){WeixinJSBridge.on("menu:share:appmessage",function(d){WeixinJSBridge.invoke("sendAppMessage",{img_url:window.shareData.imgUrl,link:window.shareData.timeLineLink,desc:window.shareData.tContent,title:window.shareData.tTitle},c);
- });WeixinJSBridge.on("menu:share:timeline",function(d){WeixinJSBridge.invoke("shareTimeline",{img_url:window.shareData.imgUrl,img_width:"640",img_height:"640",link:window.shareData.timeLineLink,desc:window.shareData.tContent,title:window.shareData.tTitle},b);
- });},false);function c(d){DCAgent.onEvent("share_app",1,{userID:"null"});}function b(d){DCAgent.onEvent("share_timeline",1,{userID:"null"});}}function initEvent(){Game.$el.btnStart.bind(util.mousedown,function(a){if(Game.isStart){Game.isStart=false;
- Game.isGame=true;gameing();}});Game.$el.btnTry.bind(util.mousedown,function(a){if(Game.isOver){Game.cvs.clearRect(0,0,640,960);Game.isOver=false;Game.isGame=true;
- resetGame();}});Game.$el.btnShare.bind(util.mousedown,function(a){if(Game.isOver){Game.$el.share.show();}return true;});Game.$el.btnMore.bind(util.mousedown,function(b){if(Game.isOver){var a=/micromessenger/.test(window.navigator.userAgent.toLowerCase())?"http://mp.weixin.qq.com/s?__biz=MzI4MjA2MjE0MQ==&mid=246005295&idx=1&sn=490f8141976d607ba079d48f52a3fcd7#rd":"http://mp.weixin.qq.com/s?__biz=MzI4MjA2MjE0MQ==&mid=246005295&idx=1&sn=490f8141976d607ba079d48f52a3fcd7#rd";
- window.location.href=a;}});Game.canvas.bind(util.mousedown,function(a,b){if(Game.isGame){Game.cvs.clearRect(0,0,640,960);if(Game.qingwa.istiao){return true;
- }Game.qingwa.istiao=true;Game.jumpTime=Date.now();Game.EndTop=Game.bg.top1+240;return true;}},false);}function resetGame(){Game.$el.o_btn.hide();Game.$el.btnTry.hide();
- Game.$el.btnMore.hide();Game.$el.btnShare.hide();Game.$el.scoreOver.hide();Game.isStop=false;Game.score=0;Game.$el.score.html(Game.score);Game.yeziData=[{margin:127,left:500,top:60,width:127,height:127,img:"flow",isFlow:true,dir:"right",speed:4},{margin:640-(350+127),type:"left",left:200,top:300,width:127,height:127,img:"leaf",dir:"right",speed:4},{margin:200,type:"right",left:350,top:300,width:127,height:127,img:"leaf",dir:"right",speed:4},{left:256,top:540,width:127,height:127,img:"leaf",dir:"right",speed:4},{left:256,top:780,width:127,height:127,img:"leaf",dir:"right",speed:4}];
- Game.yeziMove=false;Game.qingwa={left:278,top:804,width:83,height:79,img:"frog",dir:"right",speed:4};Game.bg={speed:1,top1:0};gameing();}function update(){if(Game.qingwa.istiao){Game.bg.top1+=16;
- if(Game.bg.top1>=Game.EndTop){Game.bg.top1=Game.EndTop;Game.qingwa.istiao=false;Game.yeziMove=true;var a=-Game.bg.top1+60;var c=Math.floor(Math.random()*200);
- if(Math.random()<0.2){Game.yeziData.push({margin:640-(c+190+127),type:"left",left:c,top:a,isFlow:false,width:127,height:127,img:"leaf",dir:"right",speed:4});
- Game.yeziData.push({margin:c,type:"right",left:c+190,top:a,isFlow:false,width:127,height:127,img:"leaf",dir:"right",speed:4});}else{if(Math.random()>0.2&&Math.random()<0.7){var b=Math.random()>0.2&&Math.random()<0.7;
- Game.yeziData.push({margin:640-(c+190+127),type:"left",left:c,top:a,isFlow:b,width:127,height:127,img:b?"flow":"leaf",dir:"right",speed:4});Game.yeziData.push({margin:c,type:"right",left:c+190,top:a,isFlow:!b,width:127,height:127,img:!b?"flow":"leaf",dir:"right",speed:4});
- }else{Game.yeziData.push({margin:640-(c+190+127),type:"left",left:c+127,top:a,isFlow:false,width:127,height:127,img:"leaf",dir:"right",speed:4});}}checkDiaoLuo(function(d){Game.yaotiaoTime=Date.now();
- Game.qingwa.dir=d.dir;Game.qingwa.speed=d.speed;Game.qingwa.left=d.left+22;Game.qingwa.type=d.type;Game.qingwa.initPath=d.initPath+22;Game.qingwa.margin=d.margin;
- if(d.isFlow){Game.isFlow=d.isFlow;Game.score+=3;Game.$el.score.html(Game.score);return;}Game.score+=1;Game.isFlow=false;Game.$el.score.html(Game.score);
- },function(){Game.isStop=true;});}}}function checkDiaoLuo(d,a){for(var b=0;b<Game.yeziData.length;b++){var c=Game.yeziData[b];if(Math.abs((Game.qingwa.left+41.5)-(c.left+63.5))<=80){if(Math.abs((Game.qingwa.top+39.5)-(c.top+Game.bg.top1+63.5))<=80){if(d){d(c);
- }return true;}}}if(a){a();}}function draw(){Game.cvs.clearRect(0,0,640,960);drawImage("gamebg",0,0,640,960);drawImage("scorebtn",220,0,215,73);for(var b=0;
- b<Game.yeziData.length;b++){var e=Game.yeziData[b];if(Game.yeziMove){if(e.initPath==undefined){e.initPath=e.left;}if(e.dir=="right"){e.left+=e.speed;if(e.type=="right"||e.type==undefined){if(e.left>=513){e.left=513;
- e.dir="left";}}else{if(e.type=="left"){if(e.left>=(e.initPath+e.margin)){e.left=e.initPath+e.margin;e.dir="left";}}}}else{if(e.dir=="left"){e.left-=e.speed;
- if(e.type=="left"||e.type==undefined){if(e.left<=0){e.left=0;e.dir="right";}}else{if(e.type=="right"){if(e.left<=(e.initPath-e.margin)){e.left=e.initPath-e.margin;
- e.dir="right";}}}}}}var d=e.top+Game.bg.top1;drawImage(e.img,e.left,d,e.width,e.height);if(d>=960){Game.yeziData.splice(b,1);}}if(Game.isStop){drawImage("jump_wfrog",Game.qingwa.left+0+28,Game.qingwa.top-0,63,104);
- drawImage("water",Game.qingwa.left+0,Game.qingwa.top-0-23,115,151);return;}var e=Game.qingwa;if(Game.yeziMove){if(e.initPath==undefined){e.initPath=e.left;
- }if(e.dir=="right"){e.left+=e.speed;if(e.type=="right"||e.type==undefined){if(e.left>=535){e.left=535;e.dir="left";}}else{if(e.type=="left"){if(e.left>=(e.initPath+e.margin)){e.left=e.initPath+e.margin;
- e.dir="left";}}}}else{if(e.dir=="left"){e.left-=e.speed;if(e.type=="left"||e.type==undefined){if(e.left<=22){e.left=22;e.dir="right";}}else{if(e.type=="right"){if(e.left<=(e.initPath-e.margin)){e.left=e.initPath-e.margin;
- e.dir="right";}}}}}}var d=e.top+6;var g=Game.jumpFrog;var a=Game.qingwa.istiao;var f=Date.now();if((f-Game.jumpTime)<=500&&a){drawImage(g.img,e.left,d,g.width,g.height);
- return;}drawImage(e.img,e.left,d,e.width,e.height);var c=Date.now();if((c-Game.yaotiaoTime)<=500){addScore();}}function addScore(){var c=Game.qingwa;var a=c.top;
- if(Game.score==0){return;}else{if(Game.score>0&&Game.isFlow){var b=Game.addScore;drawImage("score_3",c.left+50,a-50,b.width,b.height);}else{var b=Game.addScore;
- drawImage("score_1",c.left+50,a-50,b.width,b.height);}}}function drawImage(b,e,d,c,a){Game.cvs.drawImage(util.img.get(b),e,d,c,a);}
|