1 Star 0 Fork 0

1810-share/打灰机

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.js 2.20 KB
一键复制 编辑 原始数据 按行查看 历史
qxy 提交于 2021-04-12 14:39 . 第一次提交
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)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/qian_zhen_shuai/duster.git
git@gitee.com:qian_zhen_shuai/duster.git
qian_zhen_shuai
duster
打灰机
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385