最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery實現(xiàn)飛機大戰(zhàn)游戲

 更新時間:2022年05月09日 09:19:10   作者:南初?  
這篇文章主要為大家詳細介紹了jQuery實現(xiàn)飛機大戰(zhàn)游戲,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了jQuery實現(xiàn)飛機大戰(zhàn)游戲的具體代碼,供大家參考,具體內(nèi)容如下

一、效果圖

二、核心代碼

1.創(chuàng)建地圖  

this.createMap = function () {
? ?var that = this;
? ? ? ? ? ? ? ? that._bg = $("<div class='bgmap'></div>");
? ? ? ? ? ? ? ? that._bg.css({
? ? ? ? ? ? ? ? ? ? width: sw,
? ? ? ? ? ? ? ? ? ? height: sh,
? ? ? ? ? ? ? ? ? ? backgroundPosition: '0px ' + (-sh) + 'px'
? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? mapEle.append(that._bg);
? ? ? ? ? ? ? ? this.startAnimate();
? ? ? ? ? ? ? ? //創(chuàng)建分數(shù)
? ? ? ? ? ? ? ? that.score=$("<span class='score'>0</span>");
? ? ? ? ? ? ? ? mapEle.append(that.score);
};?

2.用戶選擇飛機界面

this.createPage=function(){
? ? var that=this;
? ? ? ? ? ? ? ? that._userPage=$("<div class='user_check'></div>");
? ? ? ? ? ? ? ? that._userplane[0]=$("<div class='plane1'><img src='./img/my_1.png'></div>");
? ? ? ? ? ? ? ? that._userplane[1]=$("<div class='plane2'><img src='./img/my_2.png'></div>");
? ? ? ? ? ? ? ? that._userplane.map(function (item,index){
? ? ? ? ? ? ? ? ? ? !index?item.addClass("check"):'';//默認第一個選中
? ? ? ? ? ? ? ? ? ? that._userPage.append(item);
? ? ? ? ? ? ? ? ? ? item.on("click",function(){
? ? ? ? ? ? ? ? ? ? ? ? //設(shè)置二選一
? ? ? ? ? ? ? ? ? ? ? ? $(this).addClass("check").siblings().removeClass("check");
? ? ? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? that._start = $("<button class='start'>開始</button>");
? ? ? ? ? ? ? ? that._start.on("click",function(){
? ? ? ? ? ? ? ? ? ? that._userplane.map(function(item,index){
? ? ? ? ? ? ? ? ? ? ? ? if(item.hasClass("check")){
? ? ? ? ? ? ? ? ? ? ? ? ? ? that._userPage.hide();
? ? ? ? ? ? ? ? ? ? ? ? ? ? //開啟背景動畫
? ? ? ? ? ? ? ? ? ? ? ? ? ? that.startAnimate();
? ? ? ? ? ? ? ? ? ? ? ? ? ? //獲取用戶選擇的飛機的圖片路徑
? ? ? ? ? ? ? ? ? ? ? ? ? ? that._userFeisrc=item.find("img").attr("src");
? ? ? ? ? ? ? ? ? ? ? ? ? ? that._plane.createUser(that._userFeisrc);
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? that._close = $("<button class='start'>關(guān)閉</button>");
? ? ? ? ? ? ? ? that._close.on("click",function(){
? ? ? ? ? ? ? ? ? ? //瀏覽器關(guān)閉
? ? ? ? ? ? ? ? ? ? window.close();
? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? that._userPage.append(that._start);
? ? ? ? ? ? ? ? that._userPage.append(that._close);
? ? ? ? ? ? ? ? mapEle.append(that._userPage);
? ? ? ? ? ? }?

3.設(shè)置背景循環(huán)

this.startAnimate=function(){
? ?var that=this;
? ? ? ? ? ? ? ? that._bg.animate({
? ? ? ? ? ? ? ? ? ? backgroundPositionY:0
? ? ? ? ? ? ? ? },5000,'linear').queue(function(){
? ? ? ? ? ? ? ? ? ? $(this).css({
? ? ? ? ? ? ? ? ? ? ? ? backgroundPosition:'0px '+(-sh)+'px'
? ? ? ? ? ? ? ? ? ? }).dequeue();
? ? ? ? ? ? ? ? ? ? that.startAnimate();
? ? ? ? ? ? ? ? });
? ? ? ? ? ? };?

4.創(chuàng)建飛機

this.createUser=function(src){
? ? ?var that=this;
? ? ? ? ? ? ? ? that._user=$("<img class='user' src="+src+"/>");
? ? ? ? ? ? ? ? mapEle.append(that._user);
? ? ? ? ? ? ? ? that._user.css({
? ? ? ? ? ? ? ? ? ? top:sh,
? ? ? ? ? ? ? ? ? ? left: sw / 2 - 30
? ? ? ? ? ? ? ? }).animate({
? ? ? ? ? ? ? ? ? ? top:that.pos.top
? ? ? ? ? ? ? ? },1000,function(){
? ? ? ? ? ? ? ? ? ? //動畫執(zhí)行完成之后用戶開始操作
? ? ? ? ? ? ? ? ? ? console.log("開始觸屏");
? ? ? ? ? ? ? ? ? ? //給當前飛機添加觸屏事件
? ? ? ? ? ? ? ? ? ? that.addTouch();
? ? ? ? ? ? ? ? ? ? //設(shè)置子彈幾發(fā),并且開始發(fā)射
? ? ? ? ? ? ? ? ? ? that.gun();
? ? ? ? ? ? ? ? ? ? //敵機開始動
? ? ? ? ? ? ? ? ? ? that.randomEnemy();
? ? ? ? ? ? ? ? });
? ? ? ? ? ? };?

5.創(chuàng)建敵機

this.createEnemy = function () {
? ?var that = this;
? ? ? that.index = Math.floor(Math.random() * that.enemylist.length);
? ? ? var wrandom = Math.random() * sw;
? ? ? var ele = that.enemylist[that.index];//獲取當前的敵機
? ? ? that.enemy = $("<img class='enemy'/>");
? ? ? mapEle.append(that.enemy);
? ? ? that.top = ele.direct == 'todown' ? -ele.h : sh + ele.h;
? ? ? that.left = wrandom - ele.w < 0 ? 0 : wrandom + ele.w > sw ? sw - ele.w : wrandom;
? ? ? that.w = ele.w;
? ? ? that.h = ele.h;
? ? ? that.enemy.css({
? ? ? ? ? ? ? ? ? ? width: that.w,
? ? ? ? ? ? ? ? ? ? height: that.h,
? ? ? ? ? ? ? ? ? ? left: that.left,
? ? ? ? ? ? ? ? ? ? top: that.top
? ? ? ? ? ? ? ? }).attr("src", ele.src);
? ? ? ? ? ? ? ? that.blood = ele.blood;
? ? ? ? ? ? ? ? that.score = ele.score;
? ? ? ? ? ? ? ? that.way = ele.direct;
? ? ? ? ? ? ? ? that.speed = ele.speed;
? ? ? ? ? ? ? ? //敵機移動
? ? ? ? ? ? ? ? that.move();
? ? ? ? ? ? };?

6.敵機移動

this.move=function(){
? ? ? var that=this;
? ? ? ? ? ? ? ? if(that.way=="todown"){
? ? ? ? ? ? ? ? ? ? that.top+=that.speed;
? ? ? ? ? ? ? ? ? ? if(that.top>=sh){
? ? ? ? ? ? ? ? ? ? ? ? that.enemy.remove();
? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else{
? ? ? ? ? ? ? ? ? ? that.top-=that.speed;
? ? ? ? ? ? ? ? ? ? if(that.top<=0){
? ? ? ? ? ? ? ? ? ? ? ? that.enemy.remove();
? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? that.enemy.css({
? ? ? ? ? ? ? ? ? ? top: that.top
? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? that.timer=setTimeout(function(args){
? ? ? ? ? ? ? ? ? ? args.move();
? ? ? ? ? ? ? ? },that.tspeed,that)
? ? ? ? ? ? }?

7.設(shè)置敵機爆炸

this.blow = function (index) {
? ? var that = this;
? ?//開始爆炸
? ? that.blowool = true;
? ? that.enemy.remove();
? ?//加分
? ? ? ?allsc+=that.score;
? ? ? ? ? ? ? ? $(".score").text(allsc);
? ? ? ? ? ? ? ? //在原位置創(chuàng)建爆炸
? ? ? ? ? ? ? ? var b = $("<img class='blow' src='./img/blow.gif'/>");
? ? ? ? ? ? ? ? b.css({
? ? ? ? ? ? ? ? ? ? left: that.left,
? ? ? ? ? ? ? ? ? ? top: that.top,
? ? ? ? ? ? ? ? ? ? width: that.w,
? ? ? ? ? ? ? ? ? ? height: that.h
? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? b.timer = setTimeout(function (arg) {
? ? ? ? ? ? ? ? ? ? arg.remove();
? ? ? ? ? ? ? ? }, 300, b)
? ? ? ? ? ? ? ? mapEle.append(b);
? ? ? ? ? ? ? ? allEnemy.splice(index, 1);
? ? ? ? ? ? };?

8.創(chuàng)建子彈

this.createBullet=function(pos,left){
this._bullet = $("<img class='bullet' src='" + this.img + "'/>");
? ? ? ? mapEle.append(this._bullet);
? ? ? ? ? ? ? ? //設(shè)置當前子彈的坐標
? ? ? ? ? ? ? ? this.top = pos.top - 20;
? ? ? ? ? ? ? ? this.left = left - this.w / 2;
? ? ? ? ? ? ? ? this._bullet.css({
? ? ? ? ? ? ? ? ? ? width: this.w,
? ? ? ? ? ? ? ? ? ? height: this.h,
? ? ? ? ? ? ? ? ? ? left: this.left,
? ? ? ? ? ? ? ? ? ? top: this.top
? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? this.move();
? ? ? ? ? ? }?

9.檢測子彈的移動(是否打到敵機)

this.move=function(){
?var that=this;
? ? ? ? ? ? ? ? that.top-=that.dus;
? ? ? ? ? ? ? ? if(that.top<=0){
? ? ? ? ? ? ? ? ? ? that._bullet.remove();
? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? //在子彈里面去檢測 ?是否打到敵機
? ? ? ? ? ? ? ? that = that.checkEnemy();
? ? ? ? ? ? ? ? //檢測子彈如果為null ?直接出
? ? ? ? ? ? ? ? if (that == null)
? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? that._bullet.css({
? ? ? ? ? ? ? ? ? ? top: that.top
? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? that.timer=setTimeout(function(args){
? ? ? ? ? ? ? ? ? ? args.move();
? ? ? ? ? ? ? ? },that.speed,that);
? ? ? ? ? ? };?

10.設(shè)置敵機被消滅的情況

this.checkEnemy = function () {
var that = this;
?//left ?top
? ? ? ? ? ? ? ? for (var i = 0; i < allEnemy.length; i++) {
? ? ? ? ? ? ? ? ? ? var item = allEnemy[i];
? ? ? ? ? ? ? ? ? ? //檢測條件
? ? ? ? ? ? ? ? ? ? if (item.blowool == false && that.left + that.w >= item.left && that.left <= item.left + item.w && that.top <= item.top +
item.h && that.top + that.h >= item.top) {
? ? ? ? ? ? ? ? ? ? ? ? //開始血量減少
? ? ? ? ? ? ? ? ? ? ? ? item.blood -= 1;
? ? ? ? ? ? ? ? ? ? ? ? if (item.blood <= 0) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? //敵機移除
? ? ? ? ? ? ? ? ? ? ? ? ? ? item.blow(i);
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? //子彈移除
? ? ? ? ? ? ? ? ? ? ? ? that._bullet.remove();
? ? ? ? ? ? ? ? ? ? ? ? //移除子彈對象
? ? ? ? ? ? ? ? ? ? ? ? return null;
? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? return that;
? ? ? ? ? ? }?

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • jquery中EasyUI實現(xiàn)異步樹

    jquery中EasyUI實現(xiàn)異步樹

    前面我們分享了使用jquery中EasyUI實現(xiàn)同步樹的代碼,本文我們就來看下使用EasyUI實現(xiàn)異步樹的方法和示例,希望小伙伴們能夠喜歡。
    2015-03-03
  • asp.net中oracle 存儲過程(圖文)

    asp.net中oracle 存儲過程(圖文)

    存儲過程是在大型數(shù)據(jù)庫系統(tǒng)中,一組為了完成特定功能的sql語句集,經(jīng)過編譯存儲在數(shù)據(jù)庫中,用戶通過指定存儲過程的名字并給出參數(shù)(如果該存儲過程帶有參數(shù))來執(zhí)行它,下面小編給大家介紹asp.net中oracle存儲過程,需要的朋友可以參考下
    2015-08-08
  • JQuery validate 驗證一個單獨的表單元素實例

    JQuery validate 驗證一個單獨的表單元素實例

    下面小編就為大家?guī)硪黄狫Query validate 驗證一個單獨的表單元素實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-02-02
  • jquery動態(tài)改變onclick屬性導致失效的問題解決方法

    jquery動態(tài)改變onclick屬性導致失效的問題解決方法

    onclick屬性失效的問題,相信很多的朋友都有遇到過吧,jquery動態(tài)改變onclick屬性就會導致此問題的發(fā)生,解決方法如下,希望對大家有所幫助
    2013-12-12
  • JQuery 實現(xiàn)文件下載的常用方法分析

    JQuery 實現(xiàn)文件下載的常用方法分析

    這篇文章主要介紹了JQuery 實現(xiàn)文件下載的常用方法,結(jié)合實例形式分析了jQuery的GET方式、POST方式及HTML5 Blob對象等常見的文件下載機制、原理與實現(xiàn)方法,需要的朋友可以參考下
    2019-10-10
  • jquery怎樣實現(xiàn)ajax聯(lián)動框(一)

    jquery怎樣實現(xiàn)ajax聯(lián)動框(一)

    ajax聯(lián)動框想必大家早有所耳聞,接下來本文詳細介紹下使用jquery實現(xiàn)的原理及代碼,感興趣的你可以參考下,或許對你有所幫助
    2013-03-03
  • jQuery實現(xiàn)Table表格隔行變色及高亮顯示當前選擇行效果示例

    jQuery實現(xiàn)Table表格隔行變色及高亮顯示當前選擇行效果示例

    這篇文章主要介紹了jQuery實現(xiàn)Table表格隔行變色及高亮顯示當前選擇行效果,涉及jQuery針對table元素遍歷、運算、樣式及鼠標事件動態(tài)響應(yīng)相關(guān)操作技巧,需要的朋友可以參考下
    2017-02-02
  • jQuery實現(xiàn)的分子運動小球碰撞效果

    jQuery實現(xiàn)的分子運動小球碰撞效果

    這篇文章主要介紹了jQuery實現(xiàn)的分子運動小球碰撞效果,涉及jQuery基于定時函數(shù)操作頁面元素動態(tài)變換的技巧,需要的朋友可以參考下
    2016-01-01
  • jQuery實現(xiàn)多級聯(lián)動下拉列表查詢框

    jQuery實現(xiàn)多級聯(lián)動下拉列表查詢框

    這篇文章主要為大家介紹了jQuery實現(xiàn)多級聯(lián)動下拉列表查詢框,感興趣的小伙伴們可以參考一下
    2016-01-01
  • jQuery模擬html下拉多選框的原生實現(xiàn)方法示例

    jQuery模擬html下拉多選框的原生實現(xiàn)方法示例

    這篇文章主要介紹了jQuery模擬html下拉多選框的原生實現(xiàn)方法,結(jié)合完整實例形式分析了jQuery動態(tài)操作頁面元素實現(xiàn)select下拉框效果的相關(guān)操作技巧,需要的朋友可以參考下
    2019-05-05

最新評論

星座| 嘉义市| 任丘市| 昂仁县| 页游| 亳州市| 周口市| 惠安县| 阜新市| 白水县| 安阳市| 阿拉善盟| 武清区| 邛崃市| 邯郸市| 三穗县| 莱州市| 大洼县| 翼城县| 阿尔山市| 赣州市| 比如县| 自治县| 德昌县| 长宁区| 南投县| 广饶县| 定西市| 泰和县| 布拖县| 秀山| 即墨市| 贵州省| 卢湾区| 望城县| 庄浪县| 广宗县| 当涂县| 习水县| 陇南市| 博乐市|