赛车(改良版)
利用js实现以下功能:
在四个赛道随记生成路障,其移动速度随用户生存的时间增加而增加
用户可以通过方向键或者A、D键控制用户小车左右移动,躲避路障
当路障与用户小车碰撞,游戏结束
实时记录和显示生存时间以及所得分数
效果展示
在这里插入图片描述
源代码
html
Document
Score: 0
Time: 0s
css
* {
margin: 0;
padding: 0;
}
body {
text-align: center;
}
#background {
margin: 0 auto;
width: 1000px;
background: url(../img/bg.jpg) no-repeat #5f5762;
background-position: center;
border-radius: 50px;
}
#band {
margin: 0 auto;
margin-top: 15px;
width: 300px;
height: 100px;
background-color: #333;
border-radius: 15px;
font-size: 25px;
line-height: 50px;
font-family: 'Times New Roman', Times, serif;
font-weight: bold;
color: #fff;
}
#bgImg {
position: relative;
}
#bg {
position: relative;
margin: 0px auto;
width: 320px;
background-color: #5d7182;
overflow: hidden;
/* background: url(../img/racing.png) repeat-y; */
opacity: 0.98;
}
.box, #mybox {
position: absolute;
width: 45px;
height: 60px;
background-color: #333;
/* opacity: 1; */
}
#mybox {
/* background-color: red; */
background: url(../img/mycar.png);
}
javascript
window.onload = function () {
alert('使用左右方向键或者A,D字母控制小车左右移动\n\n点击确定