代码拉取完成,页面将自动刷新
import { MiddleEnemy, SmallEnemy, BigEnemy } from "./modules/Enemy.js";
import { MyPlane } from "./modules/MyPlane.js";
import { randNum } from "./utils/Base.js";
import {
wrap,
myPlaneInfo,
smallEnemyInfo,
middleEnemyInfo,
bigEnemyInfo
} from './utils/config.js';
const btn = document.querySelector('.btn');
wrap.el = document.querySelector('.wrap');
btn.onclick = function() {
this.style.display = 'none';
wrap.el.style.backgroundImage = `url(${wrap.srcImg})`;
// 创建 我的飞机
const myPlane = new MyPlane(
wrap.el,
wrap.w / 2 - myPlaneInfo.w / 2,
wrap.h - myPlaneInfo.h - 30,
'./img/我的飞机.gif',
myPlaneInfo.w,
myPlaneInfo.h
);
myPlane.createMyPlane();
myPlaneInfo.el = document.querySelector('.myPlane');
setInterval(function() {
let prob = randNum(0, 100)
let num1 = randNum(myPlaneInfo.w / 2 - smallEnemyInfo.w, wrap.w - myPlaneInfo.w + myPlaneInfo.w / 2);
let num2 = randNum(0, wrap.w - smallEnemyInfo.w);
let num3 = randNum(0, wrap.w - bigEnemyInfo.w);
if(prob >=0 && prob <= 70) {
new SmallEnemy({
wrap: wrap.el,
x: num1,
y: -smallEnemyInfo.h,
srcImg: smallEnemyInfo.srcImg,
w: smallEnemyInfo.w,
h: smallEnemyInfo.h,
iSpeed: smallEnemyInfo.iSpeed,
hitNum: smallEnemyInfo.hitNum,
hitImg: smallEnemyInfo.hitImg,
boomImg: smallEnemyInfo.boomImg
}).createEnemy();
} else if (prob > 70 && prob <= 90) {
new MiddleEnemy({
wrap: wrap.el,
x: num2,
y: -middleEnemyInfo.h,
srcImg: middleEnemyInfo.srcImg,
w: middleEnemyInfo.w,
h: middleEnemyInfo.h,
iSpeed: middleEnemyInfo.iSpeed,
hitNum: middleEnemyInfo.hitNum,
hitImg: middleEnemyInfo.hitImg,
boomImg: middleEnemyInfo.boomImg
}).createEnemy();
}else {
new BigEnemy({
wrap: wrap.el,
x: num3,
y: -bigEnemyInfo.h,
srcImg: bigEnemyInfo.srcImg,
w: bigEnemyInfo.w,
h: bigEnemyInfo.h,
iSpeed: bigEnemyInfo.iSpeed,
hitNum: bigEnemyInfo.hitNum,
hitImg: bigEnemyInfo.hitImg,
boomImg: bigEnemyInfo.boomImg
}).createEnemy();
}
}, 1000)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。