欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript實(shí)現(xiàn)飛機(jī)大戰(zhàn)小游戲

 更新時(shí)間:2022年05月08日 09:17:33   作者:絨尾  
這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)飛機(jī)大戰(zhàn)小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

文檔結(jié)構(gòu)如下

其中tool文件中只使用了隨機(jī)數(shù),audio中是存放的音樂文件,images中是己方和敵方飛機(jī)的圖片。

HTML部分

<!DOCTYPE html>
<html lang="en">
<head>
? ? <meta charset="UTF-8">
? ? <meta http-equiv="X-UA-Compatible" content="IE=edge">
? ? <meta name="viewport" content="width=device-width, initial-scale=1.0">
? ? <title>Document</title>
? ? <link rel="stylesheet" href="css/game.css" >
</head>
<body>
? ? <section>
? ? ? ? <input type="button" value="GAME START" id="btn">
? ? ? ? <div id="socre">
? ? ? ? ? ? <p id="num">當(dāng)前分?jǐn)?shù)為:</p>
? ? ? ? ? ? <p id="historynum">歷史最高:</p>
? ? ? ? </div>
? ? </section>
?
? ? <script src="js/tool.js"></script>
? ? <script src="js/game.js"></script>
</body>
</html>

CSS部分

section{
? ? background-image: url(../material/images/startBG.png);
? ? background-repeat: no-repeat;
? ? background-size: 320px,570px;
? ? width: 320px;
? ? height: 570px;
? ? margin: auto;
? ? margin-top: 30px;
? ? position: relative;
? ? overflow: hidden;
}
?
section>input{
? ? width: 150px;
? ? position: absolute;
? ? bottom: 65px;
? ? left: 85px;
}
?
#socre{
? ? display: none;
}

JS部分

主要是通過類方法創(chuàng)建敵機(jī)和我方飛機(jī),再通過類的繼承給予小/中/大/boss等敵機(jī)屬性和方法。

const section = document.querySelector("section");
const enemy = document.getElementsByClassName("enemys");
let [flag1, flag2, flag3, flag4] = [false, false, false, false];
//小飛機(jī)
let splane;
//中飛機(jī)
let mplane;
//大飛機(jī)
let bplane;
//boss
let boss;
let shoot;
let bossshoot;
//得分
let number;
let move1;
//本地獲取數(shù)據(jù)
let arr = localStorage.getItem("scort");
arr = JSON.parse(arr);
//音頻
var mp3;
var gameover;
var bossrun;
?
//游戲開始
btn.addEventListener("click", function () {
? ? //console.log(gameover);
? ? if (gameover) {
? ? ? ? gameover.pause();
? ? }
? ? mp3 = "./material/audio/bgm.mp3";
? ? mp3 = new Audio(mp3);
? ? mp3.play(); //播放mp3這個(gè)音頻對(duì)象
?
? ? //計(jì)算分?jǐn)?shù)
? ? number = 0;
? ? num.innerText = `當(dāng)前分?jǐn)?shù)為:0`;
? ? //從本地獲取分?jǐn)?shù)
? ? arr = localStorage.getItem("scort");
? ? arr = JSON.parse(arr);
? ? const newmyplane = document.getElementById("myplane");
? ? if (newmyplane) {
? ? ? ? section.removeChild(newmyplane)
? ? }
?
? ? //判斷本地是否有數(shù)據(jù)
? ? if (arr == null) {
? ? ? ? historynum.innerText = `歷史最高:0`
? ? } else {
? ? ? ? historynum.innerText = `歷史最高:${arr}`
? ? }
? ? //得分面板
? ? socre.style.display = "block";
? ? btn.style.display = "none";
? ? //更改背景
? ? section.style.backgroundImage = "url(./material/images/background_1.png)";
? ? //實(shí)例化自身飛機(jī)
? ? let myplane = new Myplane(0, 127);
? ? //實(shí)例化敵機(jī)
? ? splane = setInterval(
? ? ? ? function () {
? ? ? ? ? ? let smallenemys = new Smallenemys(random(0, 286), "material/images/enemy1_fly_1.png", -24, 1);
? ? ? ? }, 1000)
? ? mplane = setInterval(
? ? ? ? function () {
? ? ? ? ? ? let midenemys = new Midenemys(random(0, 274), "material/images/enemy3_fly_1.png", -60, 3);
? ? ? ? }, 6000)
? ? bplane = setInterval(
? ? ? ? function () {
? ? ? ? ? ? let bigenemys = new Bigenemys(random(0, 210), "material/images/enemy2_fly_1.png", -164, 10);
? ? ? ? }, 10000)
?
? ? boss = setInterval(
? ? ? ? function () {
? ? ? ? ? ? let boss = new Bossenemys(random(0, 210), "material/images/boss.png", -118, 20);
? ? ? ? ? ? bossrun = "./material/audio/bossrun.mp3";
? ? ? ? ? ? bossrun = new Audio(bossrun);
? ? ? ? ? ? bossrun.play(); //播放mp3這個(gè)音頻對(duì)象
? ? ? ? ? ? //延遲器
? ? ? ? ? ? setTimeout(() => {
? ? ? ? ? ? ? ? bossrun.pause();
? ? ? ? ? ? }, 3000)
? ? ? ? }, 50000)
?
});
?
//己方飛機(jī)
class Myplane {
? ? constructor(firstbot, firstleft) {
? ? ? ? this.node = document.createElement("img");
? ? ? ? // console.log(this.node);
? ? ? ? this.firstbot = firstbot;
? ? ? ? this.firstleft = firstleft;
? ? ? ? this.init();
? ? }
?
? ? init() {
? ? ? ? this.create();
? ? ? ? this.render();
? ? ? ? this.action();
? ? ? ? this.crash();
? ? ? ? shoot = setInterval(() => {
? ? ? ? ? ? let bullet = new Bullet(this.firstbot + 80, this.firstleft + 31);
? ? ? ? ? ? num.innerText = `當(dāng)前分?jǐn)?shù)為:${number}`
?
? ? ? ? }, 230)
? ? }
?
? ? render() {
? ? ? ? Object.assign(this.node.style, {
? ? ? ? ? ? position: `absolute`,
? ? ? ? ? ? bottom: `${this.firstbot}px`,
? ? ? ? ? ? left: `${this.firstleft}px`,
? ? ? ? })
? ? }
?
? ? create() {
? ? ? ? this.node.setAttribute('src', 'material/images/myPlane.gif');
? ? ? ? this.node.setAttribute('id', 'myplane')
? ? ? ? section.appendChild(this.node);
? ? }
?
? ? action() {
? ? ? ? //鍵盤按下
? ? ? ? document.addEventListener("keydown", (event) => {
? ? ? ? ? ? if (this.move) {
? ? ? ? ? ? ? ? this.move(event);
? ? ? ? ? ? }
?
? ? ? ? });
? ? ? ? //鍵盤抬起
? ? ? ? document.addEventListener("keyup", function (event) {
? ? ? ? ? ? switch (event.key) {
? ? ? ? ? ? ? ? case "w":
? ? ? ? ? ? ? ? ? ? flag1 = false;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case "a":
? ? ? ? ? ? ? ? ? ? flag2 = false;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case "s":
? ? ? ? ? ? ? ? ? ? flag3 = false;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case "d":
? ? ? ? ? ? ? ? ? ? flag4 = false;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
?
? ? ? ? })
?
? ? }
? ? //移動(dòng)
? ? move(event) {
? ? ? ? switch (event.key) {
? ? ? ? ? ? case "w":
? ? ? ? ? ? ? ? flag1 = true;
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case "a":
? ? ? ? ? ? ? ? flag2 = true;
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case "s":
? ? ? ? ? ? ? ? flag3 = true;
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case "d":
? ? ? ? ? ? ? ? flag4 = true;
? ? ? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? if (move1) {
? ? ? ? ? ? clearInterval(move1)
? ? ? ? }
? ? ? ? move1 = setInterval(() => {
? ? ? ? ? ? //左側(cè)邊框
? ? ? ? ? ? if (flag2) {
? ? ? ? ? ? ? ? if (parseInt(getComputedStyle(this.node).left) <= 0) {
? ? ? ? ? ? ? ? ? ? this.firstleft = 0;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? this.firstleft -= 2;
? ? ? ? ? ? ? ? this.render()
? ? ? ? ? ? }
? ? ? ? ? ? //上側(cè)邊框
? ? ? ? ? ? else if (flag1) {
? ? ? ? ? ? ? ? this.firstbot += 2;
? ? ? ? ? ? ? ? if (parseInt(getComputedStyle(this.node).bottom) >= 490) {
? ? ? ? ? ? ? ? ? ? this.firstbot = 490;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? this.render()
? ? ? ? ? ? }
? ? ? ? ? ? //右側(cè)邊框
? ? ? ? ? ? else if (flag4) {
? ? ? ? ? ? ? ? if (parseInt(getComputedStyle(this.node).left) >= 255) {
? ? ? ? ? ? ? ? ? ? this.firstleft = 255;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? this.firstleft += 2;
? ? ? ? ? ? ? ? this.render()
?
? ? ? ? ? ? }
? ? ? ? ? ? //下側(cè)邊框
? ? ? ? ? ? else if (flag3) {
? ? ? ? ? ? ? ? if (parseInt(getComputedStyle(this.node).bottom) <= 0) {
? ? ? ? ? ? ? ? ? ? this.firstbot = 0;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? this.firstbot -= 2;
? ? ? ? ? ? ? ? this.render()
? ? ? ? ? ? }
? ? ? ? ? ? this.render()
? ? ? ? }, 10)
?
?
? ? }
?
? ? crash() {
? ? ? ? let time = setInterval(() => {
? ? ? ? ? ? let bottom = parseInt(getComputedStyle(this.node).bottom);
? ? ? ? ? ? let left = parseInt(getComputedStyle(this.node).left);
? ? ? ? ? ? for (let item of enemy) {
? ? ? ? ? ? ? ? //碰撞判斷
? ? ? ? ? ? ? ? if (bottom <= parseInt(getComputedStyle(item).bottom) + parseInt(getComputedStyle(item).height) &&
? ? ? ? ? ? ? ? ? ? bottom >= parseInt(getComputedStyle(item).bottom) - parseInt(getComputedStyle(this.node).height) &&
? ? ? ? ? ? ? ? ? ? left >= parseInt(getComputedStyle(item).left) - parseInt(getComputedStyle(this.node).width) &&
? ? ? ? ? ? ? ? ? ? left <= parseInt(getComputedStyle(item).left) + parseInt(getComputedStyle(item).width)) {
?
? ? ? ? ? ? ? ? ? ? this.node.setAttribute('src', 'material/images/本方飛機(jī)爆炸.gif');
? ? ? ? ? ? ? ? ? ? this.move = null;
?
? ? ? ? ? ? ? ? ? ? //游戲結(jié)束時(shí)清除除自身外飛機(jī)
? ? ? ? ? ? ? ? ? ? for (let item1 of enemy) {
? ? ? ? ? ? ? ? ? ? ? ? item1.style.display = 'none';
? ? ? ? ? ? ? ? ? ? }
?
? ? ? ? ? ? ? ? ? ? clearInterval(bossshoot);
? ? ? ? ? ? ? ? ? ? clearInterval(time);
? ? ? ? ? ? ? ? ? ? clearInterval(splane);
? ? ? ? ? ? ? ? ? ? clearInterval(mplane);
? ? ? ? ? ? ? ? ? ? clearInterval(bplane);
? ? ? ? ? ? ? ? ? ? clearInterval(shoot);
? ? ? ? ? ? ? ? ? ? clearInterval(boss);
?
? ? ? ? ? ? ? ? ? ? mp3.pause();
?
? ? ? ? ? ? ? ? ? ? gameover = "./material/audio/gameover.mp3";
? ? ? ? ? ? ? ? ? ? gameover = new Audio(gameover);
? ? ? ? ? ? ? ? ? ? gameover.play(); //播放mp3這個(gè)音頻對(duì)象
? ? ? ? ? ? ? ? ? ? if (arr < number) {
? ? ? ? ? ? ? ? ? ? ? ? localStorage.setItem('scort', JSON.stringify(number));
? ? ? ? ? ? ? ? ? ? ? ? historynum.innerText = `歷史最高:${number}`;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? btn.style.display = "block";
? ? ? ? ? ? ? ? ? ? // alert("游戲結(jié)束");
? ? ? ? ? ? ? ? ? ? // location.reload(true);?
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }, 10)
? ? }
?
};
?
?
//子彈類
class Bullet {
? ? constructor(firstbot, firstleft) {
? ? ? ? this.node = document.createElement("img");
? ? ? ? this.firstbot = firstbot;
? ? ? ? this.firstleft = firstleft;
? ? ? ? this.init();
? ? ? ? // console.log(this.firstbot);
? ? }
?
? ? init() {
? ? ? ? this.create();
? ? ? ? this.render();
? ? ? ? this.move();
? ? ? ? this.crash();
? ? }
?
? ? create() {
? ? ? ? this.node.setAttribute('src', 'material/images/bullet1.png');
? ? ? ? section.appendChild(this.node);
? ? }
? ? render() {
? ? ? ? Object.assign(this.node.style, {
? ? ? ? ? ? position: `absolute`,
? ? ? ? ? ? bottom: `${this.firstbot}px`,
? ? ? ? ? ? left: `${this.firstleft}px`,
? ? ? ? })
? ? }
? ? move() {
? ? ? ? let time = setInterval(() => {
? ? ? ? ? ? this.crash();
? ? ? ? ? ? this.firstbot += 2;
? ? ? ? ? ? if (this.firstbot >= 550 || getComputedStyle(this.node).display == 'none') {
? ? ? ? ? ? ? ? section.removeChild(this.node);
? ? ? ? ? ? ? ? clearInterval(time);
? ? ? ? ? ? }
? ? ? ? ? ? this.render();
? ? ? ? }, 10);
? ? }
? ? //碰撞
?
? ? crash() {
? ? ? ? //獲取所有敵機(jī)
? ? ? ? const enemy = document.getElementsByClassName("enemys");
? ? ? ? //console.log(enemy);
? ? ? ? let bottom = parseInt(getComputedStyle(this.node).bottom);
? ? ? ? let left = parseInt(getComputedStyle(this.node).left);
? ? ? ? for (let item of enemy) {
? ? ? ? ? ? //子彈撞擊敵方飛機(jī)
? ? ? ? ? ? if (bottom <= parseInt(getComputedStyle(item).bottom) + parseInt(getComputedStyle(item).height) &&
? ? ? ? ? ? ? ? bottom >= parseInt(getComputedStyle(item).bottom) - parseInt(getComputedStyle(this.node).height) &&
? ? ? ? ? ? ? ? left >= parseInt(getComputedStyle(item).left) - parseInt(getComputedStyle(this.node).width) &&
? ? ? ? ? ? ? ? left <= parseInt(getComputedStyle(item).left) + parseInt(getComputedStyle(item).width)) {
? ? ? ? ? ? ? ? // 停止子彈碰撞計(jì)時(shí)器
? ? ? ? ? ? ? ? this.node.style.display = "none";
? ? ? ? ? ? ? ? item.dataset.id--;
? ? ? ? ? ? ? ? if (item.dataset.id < 0) {
? ? ? ? ? ? ? ? ? ? item.dataset.id = 0;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (parseInt(getComputedStyle(item).width) == 34) {
? ? ? ? ? ? ? ? ? ? if (item.dataset.id == 0) {
? ? ? ? ? ? ? ? ? ? ? ? //圖片替換
? ? ? ? ? ? ? ? ? ? ? ? item.setAttribute('src', 'material/images/小飛機(jī)爆炸.gif');
? ? ? ? ? ? ? ? ? ? ? ? //延遲器
? ? ? ? ? ? ? ? ? ? ? ? setTimeout(() => {
? ? ? ? ? ? ? ? ? ? ? ? ? ? item.style.display = "none";
? ? ? ? ? ? ? ? ? ? ? ? }, 300)
? ? ? ? ? ? ? ? ? ? ? ? number += 1;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (parseInt(getComputedStyle(item).width) == 46) {
? ? ? ? ? ? ? ? ? ? if (item.dataset.id == 0) {
? ? ? ? ? ? ? ? ? ? ? ? item.setAttribute('src', 'material/images/中飛機(jī)爆炸.gif');
? ? ? ? ? ? ? ? ? ? ? ? setTimeout(() => {
? ? ? ? ? ? ? ? ? ? ? ? ? ? item.style.display = "none";
?
? ? ? ? ? ? ? ? ? ? ? ? }, 300)
? ? ? ? ? ? ? ? ? ? ? ? number += 5;
? ? ? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? ? ? item.setAttribute('src', 'material/images/中飛機(jī)挨打.png');
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (parseInt(getComputedStyle(item).width) == 110) {
? ? ? ? ? ? ? ? ? ? if (item.dataset.id == 0) {
? ? ? ? ? ? ? ? ? ? ? ? item.setAttribute('src', 'material/images/大飛機(jī)爆炸.gif');
? ? ? ? ? ? ? ? ? ? ? ? //大飛機(jī)爆炸
? ? ? ? ? ? ? ? ? ? ? ? let bigboom = "./material/audio/bigboom.mp3";
? ? ? ? ? ? ? ? ? ? ? ? bigboom = new Audio(bigboom);
? ? ? ? ? ? ? ? ? ? ? ? bigboom.play(); //播放mp3這個(gè)音頻對(duì)象
?
? ? ? ? ? ? ? ? ? ? ? ? setTimeout(() => {
? ? ? ? ? ? ? ? ? ? ? ? ? ? item.style.display = "none";
? ? ? ? ? ? ? ? ? ? ? ? ? ? bigboom.pause();
? ? ? ? ? ? ? ? ? ? ? ? }, 300)
? ? ? ? ? ? ? ? ? ? ? ? number += 30;
? ? ? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? ? ? item.setAttribute('src', 'material/images/大飛機(jī)挨打.png');
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
?
? ? ? ? ? ? ? ? //boss爆炸
? ? ? ? ? ? ? ? if (parseInt(getComputedStyle(item).width) == 160) {
? ? ? ? ? ? ? ? ? ? if (item.dataset.id == 0) {
? ? ? ? ? ? ? ? ? ? ? ? item.setAttribute('src', 'material/images/boomx.png');
? ? ? ? ? ? ? ? ? ? ? ? clearInterval(bossshoot);
?
? ? ? ? ? ? ? ? ? ? ? ? let bossover = "./material/audio/bossover.mp3";
? ? ? ? ? ? ? ? ? ? ? ? bossover = new Audio(bossover);
? ? ? ? ? ? ? ? ? ? ? ? bossover.play(); //播放mp3這個(gè)音頻對(duì)象
?
? ? ? ? ? ? ? ? ? ? ? ? setTimeout(() => {
? ? ? ? ? ? ? ? ? ? ? ? ? ? item.style.display = "none";
? ? ? ? ? ? ? ? ? ? ? ? ? ? bossover.pause();
? ? ? ? ? ? ? ? ? ? ? ? ? ? mp3.play();
? ? ? ? ? ? ? ? ? ? ? ? }, 300)
? ? ? ? ? ? ? ? ? ? ? ? number += 200;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
?
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
?
//敵機(jī)
class Enemys {
? ? constructor(x, url, height) {
? ? ? ? this.node = document.createElement("img");
? ? ? ? this.x = x;
? ? ? ? this.y = 546;
? ? ? ? this.url = url;
? ? ? ? this.height = height;
? ? ? ? this.init();
? ? }
?
? ? init() {
? ? ? ? this.create();
? ? ? ? this.render();
? ? ? ? this.move();
? ? }
?
? ? create() {
? ? ? ? this.node.setAttribute('src', this.url);
? ? ? ? this.node.setAttribute('class', "enemys");
? ? ? ? section.appendChild(this.node);
? ? }
? ? render() {
? ? ? ? Object.assign(this.node.style, {
? ? ? ? ? ? position: `absolute`,
? ? ? ? ? ? bottom: `${this.y}px`,
? ? ? ? ? ? left: `${this.x}px`,
? ? ? ? })
?
? ? }
?
? ? move() {
? ? ? ? let enemytime = setInterval(() => {
? ? ? ? ? ? this.y -= 1;
? ? ? ? ? ? if (this.y <= this.height || getComputedStyle(this.node).display == 'none') {
? ? ? ? ? ? ? ? section.removeChild(this.node);
? ? ? ? ? ? ? ? clearInterval(enemytime)
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? this.render();
? ? ? ? ? ? }
? ? ? ? }, 10);
? ? }
};
?
//小飛機(jī)
class Smallenemys extends Enemys {
? ? constructor(x, url, height, hp) {
? ? ? ? super(x, url, height);
? ? ? ? this.hp = hp;
? ? ? ? this.node.dataset.id = hp;
? ? }
?
};
?
//中飛機(jī)
class Midenemys extends Enemys {
? ? constructor(x, url, height, hp) {
? ? ? ? super(x, url, height)
? ? ? ? this.hp = hp;
? ? ? ? this.node.dataset.id = hp;
? ? }
};
//大飛機(jī)
class Bigenemys extends Enemys {
? ? constructor(x, url, height, hp) {
? ? ? ? super(x, url, height)
? ? ? ? this.hp = hp;
? ? ? ? this.node.dataset.id = hp;
? ? }
};
?
//boss
class Bossenemys extends Enemys {
? ? constructor(x, url, height, hp) {
? ? ? ? super(x, url, height)
? ? ? ? this.hp = hp;
? ? ? ? this.node.dataset.id = hp;
? ? ? ? this.bottom = 570;
? ? ? ? this.left = 80;
? ? ? ? this.render();
? ? ? ? this.move();
? ? ? ? this.shoot();
? ? }
? ? render() {
? ? ? ? Object.assign(this.node.style, {
? ? ? ? ? ? position: `absolute`,
? ? ? ? ? ? bottom: `${this.bottom}px`,
? ? ? ? ? ? left: `${this.left}px`,
? ? ? ? })
? ? }
? ? move() {
? ? ? ? let i = -2;
? ? ? ? let time = setInterval(() => {
? ? ? ? ? ? this.bottom--;
? ? ? ? ? ? if (this.bottom <= 452) {
? ? ? ? ? ? ? ? clearInterval(time);
? ? ? ? ? ? }
? ? ? ? ? ? this.render();
? ? ? ? }, 10);
? ? ? ? let newaction = setTimeout(() => {
? ? ? ? ? ? if (parseInt(getComputedStyle(this.node).bottom) <= 452) {
? ? ? ? ? ? ? ? let transverse = setInterval(() => {
? ? ? ? ? ? ? ? ? ? this.left += i;
? ? ? ? ? ? ? ? ? ? if (this.left <= 0) {
? ? ? ? ? ? ? ? ? ? ? ? i = 2;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? if (this.left >= 160) {
? ? ? ? ? ? ? ? ? ? ? ? i = -2;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? this.render();
? ? ? ? ? ? ? ? }, 50)
? ? ? ? ? ? }
? ? ? ? }, 1000)
? ? }
? ? shoot() {
? ? ? ? bossshoot = setInterval(() => {
? ? ? ? ? ? let midenemys = new Midenemys(this.left + 56, "material/images/fire.png", -117, 1);
? ? ? ? }, 5000)
? ? }
};

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • JavaScript原生實(shí)現(xiàn)觀察者模式的示例

    JavaScript原生實(shí)現(xiàn)觀察者模式的示例

    下面小編就為大家分享一篇JavaScript原生實(shí)現(xiàn)觀察者模式的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2017-12-12
  • bootstrap選項(xiàng)卡使用方法解析

    bootstrap選項(xiàng)卡使用方法解析

    這篇文章主要為大家詳細(xì)介紹了bootstrap選項(xiàng)卡使用方法,包括選項(xiàng)卡組件和底部可以切換的選項(xiàng)卡面板使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • JavaScript自定義日期格式化函數(shù)詳細(xì)解析

    JavaScript自定義日期格式化函數(shù)詳細(xì)解析

    下面的一個(gè)例子就是以獨(dú)立函數(shù)寫出的JavaScript日期格式化函數(shù),獨(dú)立的format函數(shù)?;氐礁袷交倪@一知識(shí)點(diǎn)上,我們考查的是怎么實(shí)現(xiàn)的、運(yùn)用了哪些原理
    2014-01-01
  • javascript 跨瀏覽器的事件系統(tǒng)

    javascript 跨瀏覽器的事件系統(tǒng)

    從技術(shù)上講,javascript并沒有提供內(nèi)置的系統(tǒng)來實(shí)現(xiàn)這個(gè)非常重要的事件驅(qū)動(dòng)編程,不過得益于瀏覽器的DOM 事件模型,這缺點(diǎn)并沒有過多地暴露出來。
    2010-03-03
  • JavaScript生成帶有縮進(jìn)的表格代碼

    JavaScript生成帶有縮進(jìn)的表格代碼

    這篇文章主要介紹了JavaScript生成有縮進(jìn)的表格代碼的相關(guān)資料,代碼簡(jiǎn)單易懂,非常具有參考價(jià)值,需要的朋友可以參考下
    2016-06-06
  • laydate時(shí)間日歷插件使用方法詳解

    laydate時(shí)間日歷插件使用方法詳解

    這篇文章主要為大家詳細(xì)介紹了laydate時(shí)間日歷插件的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • js 事件小結(jié) 表格區(qū)別

    js 事件小結(jié) 表格區(qū)別

    js 事件小結(jié) 表格區(qū)別...
    2007-08-08
  • JavaScript的事件綁定(方便不支持js的時(shí)候)

    JavaScript的事件綁定(方便不支持js的時(shí)候)

    看了JavaScript DOM 編程藝術(shù)的Best Practices那章,才知道我們?cè)谥谱骶W(wǎng)頁的時(shí)候有很多東西需要考慮
    2013-10-10
  • Bootstrap Table列寬拖動(dòng)的方法

    Bootstrap Table列寬拖動(dòng)的方法

    Bootstrap Table可拖動(dòng),需要用到它的Resizable擴(kuò)展插件,下面腳本之家小編給大家?guī)砹薆ootstrap Table列寬拖動(dòng)的方法,感興趣的朋友一起看看吧
    2018-08-08
  • 如何利用moment處理時(shí)間戳并計(jì)算時(shí)間的差值

    如何利用moment處理時(shí)間戳并計(jì)算時(shí)間的差值

    前端很多場(chǎng)景都會(huì)涉及到對(duì)時(shí)間的處理,我所用得最多的庫是moment,下面這篇文章主要給大家介紹了關(guān)于如何利用moment處理時(shí)間戳并計(jì)算時(shí)間的差值的相關(guān)資料,需要的朋友可以參考下
    2022-04-04

最新評(píng)論