css实现跳跃碰撞小游戏代码
代码语言:html
所属分类:游戏
代码描述:css实现跳跃碰撞小游戏代码,按住鼠标左键不放跳跃升起,松开下落,小球击中立体方块增加一分。
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
@import url("https://fonts.googleapis.com/css?family=Raleway:400,400i,700");
*, *::before, *::after {
padding: 0;
margin: 0 auto;
box-sizing: border-box;
}
body {
font-family: Raleway, sans-serif;
background-color: #111;
color: #fff;
min-height: 100vh;
display: grid;
place-items: center;
overflow: hidden;
}
body:active {
--controlHeight: 19em;
--transitionDuration: 1.5s;
--playerScale: 0.9 1.1;
}
.gameContainer {
position: relative;
font-size: 8vmin;
width: 10em;
aspect-ratio: 1;
outline: 4px solid #fff;
background-image: repeating-linear-gradient(53.5deg, #fff1, transparent, #fff1 2em);
overflow: hidden;
-webkit-animation: background 3.5s infinite linear;
animation: background 3.5s infinite linear;
}
@-webkit-keyframes background {
to {
background-position-x: -10em;
}
}
@keyframes background {
to {
background-position-x: -10em;
}
}
.gameContainer::before {
content: var(--score);
position: absolute;
inset: 0.2em;
}
.controlContainer {
position: absolute;
left: 0;
bottom: 0;
width: 10em;
height: var(--controlHeight, 10em);
transition: height var(--transitionDuration, 3s) ease-out;
}
.player {
position: absolute;
left: 2em;
top: 9em;
width: 1em;
height: 1em;
background-color: red;
background-image: radial-gradient(circle at top, red, #200);
border-radius: 50%;
scale: var(--playerScale, 1);
transition: scale 0.3s;
}
.boxContainer {
position: absolute;
left: -2em;
top: 0;
width: 14em;
height: calc(100% - var(--boxY));
container-type: size;
-webkit-animation: boxMove 24s var(--delay, 0s) infinite linear;
animation: boxMove 24s var(--delay, 0s) .........完整代码请登录后点击上方下载按钮下载查看
















网友评论0