首页 > 代码库 > 游戏写一半了
游戏写一半了
<!DOCTYPE html><html> <head> <meta charset=‘utf-8‘> <title>games</title> <style> body{ background: aqua; overflow: hidden; } .box{ width: 600px; height: 400px; background: cornflowerblue; } .box.bird{ width:50px; height: 50px; background: chartreuse; text-align:center; position: absolute; } </style> </head> <body> <div class=‘box‘ id=‘mp‘> <div class=‘box bird‘ id=‘bb‘>bird</div> </div> <script> function init() { var oDiv = document.getElementById(‘bb‘); oDiv.style.top=‘200px‘; oDiv.style.left=‘100px‘; } function flyDown() { var v = 15; var nowTop; var down = setInterval(function(){ var fly = document.getElementById(‘bb‘); nowTop=fly.offsetTop; //alert(nowTop); nowTop+=v; var mmp=document.getElementById(‘mp‘); if(nowTop-v>=+mmp.offsetHeight+mmp.offsetTop) { clearInterval(down); alert("Game Over"); } fly.style.top = nowTop+‘px‘; },100); } function createEnemy() { var zhu = setInterval(function(){ var pos = Math.random() * document.getElementById(‘mp‘).offsetHeight ; var Qup = document.createElement(‘div‘); Qup.className = zhuzhi; Qup.style.top=0; Qup.style.left= var Qdown = document.createElement(‘div‘); Qdown.className = zhuzhi; },2*1000); } document.body.onclick=function() { //alert("hello"); var v = 100; var num = 1; var flyUp = setInterval(function(){ var fly = document.getElementById(‘bb‘); nowTop=fly.offsetTop; //alert(nowTop); nowTop-=v; nowTop=Math.max(nowTop,0); //console.log(nowTop); fly.style.top = nowTop+‘px‘; num--; //console.log(num); if(num==0) { clearInterval(flyUp); num=5; } },100); } init(); flyDown(); </script> </body></html>
游戏写一半了
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。