<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
* {
margin: 0;
padding: 0;
}
body {
background: #cccccc;
height: 100%;
}
#wrap {
position: relative;
width: 540px;
height: 960px;
margin: 20px auto;
border: 1px solid transparent;
background: url('img/bg.jpg') center/cover;
}
#wrap h1 {
color: azure;
text-align: center;
padding: 30px;
}
.option {
width: 200px;
height: 110px;
line-height: 110px;
font-size: 30px;
color: steelblue;
background: wheat;
font-weight: bold;
margin: 20px auto;
text-align: center;
cursor: pointer;
background: url(./img/fire-row.png) no-repeat center -10px/ 90% auto ;
}
.footer {
position: absolute;
right: 0;
bottom: 0;
font-size: 20px;
color: #fff;
}
/* enemy 敌机定位 */
.enemy {
position: absolute;
}
/* 血条 */
.blood {
position: absolute;
left: 0;
right: 0;
top: -6px;
margin: 0 auto;
width: 70%;
height: 2px;
border-radius: 2px;
/* border: 1px solid red; */
}
.blood p {
height: 100%;
/* background: red; */
}
/* 小飞机 */
.small {
width: 50px;
}
img:not(.boom) {
width: 100%;
height: 100%;
}
/* 大飞机 */
.big {
width: 60px;
}
.big .blood {
position: absolute;
left: 0;
right: 0;
top: -10px;
margin: 0 auto;
height: 4px;
border-radius: unset;
}
.blood p {
height: 100%;
/* background: red; */
}
/* 我军 */
.plane {
position: absolute;
}
.plane img{
transform: rotate(270deg);
}
.plane.small {
width: 80px;
}
.plane.big {
width: 100px;
}
.biu {
position: absolute;
}
.biu.strong1 {
width: 26px;
height: 26px;
}
.biu.strong2 {
width: 20px;
height: 20px;
}
/* 爆炸图片 */
img.boom {
position: absolute;
animation: opa 1s;
}
@keyframes opa {
0% {
opacity: 1;
}
25% {
opacity: 0.5;
}
50% {
opacity: 1;
}
100% {
opacity: 0;
}
}
/* prize */
.prize {
position: absolute;
width: 50px;
height: 50px;
font-size: 50px;
text-align: center;
line-height: 50px;
border: 1px dashed red;
color: red;
font-weight: bold;
animation: prize 1s infinite;
}
@keyframes prize {
0% {
transform: scale(1);
}
50% {
transform: scale(1.2);
}
100% {
transform: scale(1);
}
}
/* 得分板 */
.score {
position: absolute;
top: 0;
left: 0;
width: 70px;
height: 30px;
color: #fff;
font-size: 20px;
}
/* 记录得分 */
.record {
width: 60%;
height: 100px;
margin: 100px auto;
background: #000;
padding: 10px;
border: 4px double #fff;
color: #fff;
}
.record p {
height: 50px;
font-size: 40px;
font-weight: bold;
text-align: center;
color: skyblue;
}
/* 再来一次 */
.btn {
position: absolute;
bottom: 50px;
right: 0;
left: 0;
margin: auto;
width: 150px;
height: 40px;
text-align: center;
line-height: 40px;
color: #fff;
font-size: 20px;
font-weight: bold;
border-radius: 10px;
background: #000;
cursor: pointer;
}
</style>
</head>
<body onselectstart="return false">
<div id="wrap">
</div>
<script>
(function() {
var wrap = document.getElementById("wrap"),
speedEnemy = [400, 350, 300, 200],
wrapWidth = wrap.clientWidth,
wrapHeight = wrap.clientHeight,
enePlane = document.getElementsByClassName('enemy'),
plane = document.getElementsByClassName("plane"),
prize = document.getElementsByClassName('prize'),
defaultEne = {
big: {
width: 260,
height: 200,
strong: 5
},
small: {
width: 108,
height: 80,
strong: 1
}
},
defaultPlane = {
big: {
width: 97,
height: 97,
filename: 'plane_1.png'
},
small: {
width: 122,
height: 95,
filename: 'plane_0.gif'
}
};
init() // 初始化界面
function init() {
var optArr = ['简单模式', '一般模式', '困难模式', '地狱模式'];
wrap.innerHTML = "";
var h1 = document.createElement('h1');
h1.innerHTML = '飞机大战进化版';
wrap.appendChild(h1)
for (var i = 0, len = optArr.length; i < len; i++) {
var div = document.createElement('div');
div.className = 'option';
div.innerHTML = optArr[i];
div.i = i;
div.onclick = function(e) {
startGame(this.i, e)
}
wrap.appendChild(div)
}
}
// startGame 开始游戏
function startGame(idx, e) {
var mod = ['small', 'big', 'small', 'small'];
wrap.innerHTML = "";
wrap.className = 'bg.jpg';
wrap.eneTime = setInterval(function() {
enemy(idx, mod[randomArea(0, 3)]) //
}, speedEnemy[idx])
myPlane(e, idx, 'small')
wrap.prizeTime = setInterval(function() {
createPrize(['爱你', '么么'][randomArea(0, 1)])
}, 5000);
showScore();
var audio = document.createElement('audio');
audio.src = 'img/game_music.mp3';
audio.autoplay = true;
audio.loop = true;
audio.volume = 0.5;
wrap.appendChild(audio)
}
// 创建敌军函数
function enemy(idx, model) {
var ene = document.createElement('div'),
bloodBorder = document.createElement('div'),
blood = document.createElement('p'),
img = document.createElement('img');
ene.className = 'enemy ' + model;
ene.model = model;
bloodBorder.className = 'blood';
img.src = 'img/enemy_' + model + '.png';
img.width = defaultEne[model].width;
img.height = defaultEne[model].height;
ene.style.top = 0;
ene.strong = defaultEne[model].strong;
ene.speed = randomArea(2, 4);
//
wrap.appendChild(ene).appendChild(bloodBorder).appendCh
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
js实现飞机大战源代码,雷电经典游戏,web高分大作业,小白必看! js实现飞机大战源代码,雷电经典游戏,web高分大作业,小白必看! js实现飞机大战源代码,雷电经典游戏,web高分大作业,小白必看! js实现飞机大战源代码,雷电经典游戏,web高分大作业,小白必看! js实现飞机大战源代码,雷电经典游戏,web高分大作业,小白必看! js实现飞机大战源代码,雷电经典游戏,web高分大作业,小白必看! js实现飞机大战源代码,雷电经典游戏,web高分大作业,小白必看! js实现飞机大战源代码,雷电经典游戏,web高分大作业,小白必看! js实现飞机大战源代码,雷电经典游戏,web高分大作业,小白必看! js实现飞机大战源代码,雷电经典游戏,web高分大作业,小白必看!
资源推荐
资源详情
资源评论
收起资源包目录
飞机大战.zip (6个子文件)
飞机大战
img
game_music.mp3 115KB
enemy2_out.mp3 12KB
bullet.mp3 8KB
enemy3_down.mp3 9KB
game_over.mp3 14KB
飞机大战.html 18KB
共 6 条
- 1
资源评论
振华OPPO
- 粉丝: 27w+
- 资源: 534
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功