色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

JS面向對象實現飛機大戰

瀏覽:71日期:2024-04-23 15:45:51

本文實例為大家分享了JS面向對象實現飛機大戰的具體代碼,供大家參考,具體內容如下

主頁面

<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>Title</title> <style> .bg{ width: 530px; height: 600px; position: relative; margin: 100px auto; background: url('bg.png') no-repeat 0 -9399px; } .plane{ width: 60px; height: 53px; position: absolute; left: 235px; bottom: 10px; background: url('my_air.gif') no-repeat; } .enemy{ position: absolute; } .buttle{ width: 9px; height: 37px; position: absolute; background: url('my_ari_1.gif') no-repeat; } .bomp{ width: 160px; height: 160px; position: absolute; background: url('0.gif') no-repeat; } </style></head><body><div id='bg'> <div id='plane'></div></div></body><script type='text/javascript' src='http://m.lshqa.cn/bcjs/buttle.js'></script><script type='text/javascript' src='http://m.lshqa.cn/bcjs/enemies.js'></script><script src='http://m.lshqa.cn/bcjs/jquery-3.0.0.min.js'></script><script> //bg移動begin var bg_height=-9399; function bg_move(){ var bg=document.getElementById('bg'); bg_height+=3; if (bg_height>0){ bg_height=-9399; } bg.setAttribute('style','background: url(’bg.png’) no-repeat 0 '+bg_height+'px'); } setInterval(bg_move,30); //bg移動over //通過獲取鍵盤的key值來控制飛機的方向begin document.onkeydown = function(){ var key=event.keyCode; var plane =document.getElementById('plane'); switch (key){ case 37: plane_Left(); break; case 38: plane_Top(); break; case 39: plane_Right(); break; case 40: plane_Bottom(); break; case 32: fire(); break; } }; //通過獲取鍵盤的key值來控制飛機的方向over //飛機的方向begin var planeLeft=235; var planeBottom=10; //聲明全局變量planeBottom、planeLeft用來讓飛機移動 function plane_Left(){ if(planeLeft>0){ planeLeft-=8; document.getElementById('plane').setAttribute('style','left:'+planeLeft+'px'+';'+'bottom:'+planeBottom+'px'); } } function plane_Right(){ if(planeLeft<470){ planeLeft+=8; document.getElementById('plane').setAttribute('style','left:'+planeLeft+'px'+';'+'bottom:'+planeBottom+'px'); } } function plane_Top(){ if(planeBottom<550){ planeBottom+=8; document.getElementById('plane').setAttribute('style','left:'+planeLeft+'px'+';'+'bottom:'+planeBottom+'px'); } } function plane_Bottom(){ if(planeBottom>10){ planeBottom-=8; document.getElementById('plane').setAttribute('style','left:'+planeLeft+'px'+';'+'bottom:'+planeBottom+'px'); } } //飛機的方向over function enemyShow(){ var number = parseInt(Math.random()*10); for(var i=0;i<number;i++){ var enemies=new enemiesShow(); } } setInterval(enemyShow,3000); function fire(){ var bottom=planeBottom+5+53; var left=planeLeft+30-5; var buttle = new buttleDemo(left,bottom); }</script></html>

子彈

/** * Created by echo22 on 2016/7/29. */function buttleDemo(left,bottom){ var buttleLeft =left; var buttleBottom = bottom; var id; var Move; inti(); function inti(){ id=getRandom(); var str = '<div class=’buttle’ id=’b'+id+'’></div>'; $('#bg').append(str); $('#b'+id).css({'left':buttleLeft,'bottom':buttleBottom}); Move=setInterval(buttleMove,10); } //獲取隨機ID function getRandom(){ return parseInt(Math.random()*10000); } //子彈的移動 function buttleMove(){ if(buttleBottom<550){ buttleBottom+=10; $('#b'+id).css('bottom',buttleBottom); if(JudgeShot()){ dispire(); } } else { dispire(); } } //清除子彈 function dispire(){ $('#b'+id).remove(); clearInterval(Move); } //判斷子彈與敵機的碰撞位置 function JudgeShot(){ var enemy=$('.enemy'); for (var i=0;i<enemy.length;i++){ var enemy_top=$('.enemy').eq(i).css('top'); var enemy_left=$('.enemy').eq(i).css('left'); enemy_bottom=600-getInt(enemy_top); enemy_left=getInt(enemy_left); console.log(enemy_left); if (buttleLeft>enemy_left&&buttleLeft<enemy_left+50&&buttleBottom>enemy_bottom&&buttleBottom<enemy_bottom+60){ $('.enemy').eq(i).remove(); var bomp='<div class=’bomp’ id=’bo'+id+'’></div>'; $('#bg').append(bomp); $('#bo'+id).css({'left':buttleLeft-70,'bottom':buttleBottom-100}); setTimeout(gundan,50); return true; } } return false; } function getInt(str){ var result = str.substring(0,(str.length-2)); return parseInt(result); } function gundan(){ $('#bo'+id).remove(); }}

敵機

/** * Created by echo22 on 2016/7/29. */function enemiesShow(){ var id; init(); function init(){ var type=getEnemyType(); var enemyLeft=getEnemyLeft(); getEnemyPlane(type,enemyLeft); getLine(); } function getEnemyPlane(type,left){ console.log(111); id=parseInt(Math.random()*10000); var width; var height; if(type==1){ width=47; height=72; } else { width=64; height=56; } var enemy='<div class=’enemy’ id=’e'+id+'’ ></div>'; $('#bg').append(enemy); $('#e'+id).css({'width':width,'height':height,'left':left,'background':'url(’d_j_'+type+'.gif’) no-repeat'}); } function getEnemyType(){ return (parseInt(Math.random()*10/5)>0)?1:3; } function getEnemyLeft(){ return parseInt(Math.random()*(530-64)); } function getLine(){ Math.random()>0.5?zhiLine():quLine(); } function zhiLine(){ $('#e'+id).animate({ 'top':'520px' },3000,function(){ $('#e'+id).remove(); }) } function quLine(){ $('#e'+id).animate({ 'top':'200px', 'left':getEnemyLeft() },1500,function(){}) $('#e'+id).animate({ 'top':'520px', 'left':getEnemyLeft() },1500,function(){ $('#e'+id).remove(); }) }}

更多有趣的經典小游戲實現專題,分享給大家:

C++經典小游戲匯總

python經典小游戲匯總

python俄羅斯方塊游戲集合

JavaScript經典游戲 玩不停

java經典小游戲匯總

javascript經典小游戲匯總

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 欧美中日韩在线 | 黄色aaa毛片 | 草草影院ccyy免费看片 | 国产91区| 欧美做爰野外在线视频观看 | 久草小视频 | 亚洲黄a| 国产专区第一页 | 国产一级一片免费播放刺激 | 国产成人精品视频一区二区不卡 | 天天爱天天做天天爽天天躁 | 成人一级大片 | 亚洲第一页在线 | 毛片看看| 91aaa免费免费国产在线观看 | 欧美 在线 成 人怡红院 | 韩国19禁主播裸免费福利 | 色情毛片| 国产精品免费一区二区三区 | 精品久久网 | 日韩欧美视频一区 | 直接看的毛片 | 制服丝袜在线视频香蕉 | 九九九九九九精品免费 | 欧美黑人巨大最猛性xxxxx | 美女视频网站永久免费观看软件 | 91精品国产91热久久p | 国产成人精品日本亚洲专 | 成人免费网站在线观看 | 欧洲亚洲一区二区三区 | 国内精品自产拍在线观看91 | 九九99久麻豆精品视传媒 | 一区二区中文字幕亚洲精品 | 欧美毛片aaa激情 | 国产手机免费视频 | 国产人妖xxxx做受视频 | 成人国产午夜在线视频 | 日韩欧美二区 | 免费毛片全部不收费的 | 国产香蕉成人综合精品视频 | 国产三级做爰在线观看∵ |