css实现跳跃碰撞小游戏代码

代码语言:html

所属分类:游戏

代码描述:css实现跳跃碰撞小游戏代码,按住鼠标左键不放跳跃升起,松开下落,小球击中立体方块增加一分。

代码标签: 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) infinite linear;
}
@-webkit-keyframes boxMove {
  0% {
    width: 14em;
  }
  15%, 100% {
    width: 1em;
  }
}
@keyframes boxMove {
  0% {
    width: 14em;
  }
  15%, 100% {
    width: 1em;
  }
}
.boxContainer:nth-child(1) {
  --delay: 0s;
  --boxY: 2em;
  --rotateDelay: -0.2s;
  --hue: 0;
}
.boxContainer:nth-child(2) {
  --delay: 1.2s;
  --boxY: 7em;
  --rotateDelay: -0.5s;
  --hue: 18;
}
.boxContainer:nth-child(3) {
  --delay: 2.4s;
  --boxY: 1em;
  --rotateDelay: -0.8s;
  --hue: 36;
}
.boxContainer:nth-child(4) {
  --delay: 3.6s;
  --boxY: 5em;
  --rotateDelay: -0.8s;
  --hue: 54;
}
.boxContainer:nth-child(5) {
  --delay: 4.8s;
  --boxY: 9em;
  --rotateDelay: -0.5s;
  --hue: 72;
}
.boxContainer:nth-child(6) {
  --delay: 6s;
  --boxY: 8em;
  --rotateDelay: -0.5s;
  --hue: 90;
}
.boxContainer:nth-child(7) {
  --delay: 7.2s;
  --boxY: 6em;
  --rotateDelay: -0.5s;
  --hue: 108;
}
.boxContainer:nth-child(8) {
  --delay: 8.4s;
  --boxY: 4em;
  --rotateDelay: -0.5s;
  --hue: 126;
}
.boxContainer:nth-child(9) {
  --delay: 9.6s;
  --boxY: 0em;
  --rotateDelay: -0.9s;
  --hue: 144;
}
.boxContainer:nth-child(10) {
  --delay: 10.8s;
  --boxY: 7em;
  --rotateDelay: -1s;
  --hue: 162;
}
.boxContainer:nth-child(11) {
  --delay: 12s;
  --boxY: 4em;
  --rotateDelay: -0.4s;
  --hue: 180;
}
.boxContainer:nth-child(12) {
  --delay: 13.2s;
  --boxY: 6em;
  --rotateDelay: -0.4s;
  --hue: 198;
}
.boxContainer:nth-child(13) {
  --delay: 14.4s;
  --boxY: 0em;
  --rotateDelay: -0.7s;
  --hue: 216;
}
.boxContainer:nth-child(14) {
  --delay: 15.6s;
  --boxY: 8em;
  --rotateDelay: -0.2s;
  --hue: 234;
}
.boxContainer:nth-child(15) {
  --delay: 16.8s;
  --boxY: 0em;
  --rotateDelay: -1s;
  --hue: 252;
}
.boxContainer:nth-child(16) {
  --delay: 18s;
  --boxY: 4em;
  --rotateDelay: -0.8s;
  --hue: 270;
}
.boxContainer:nth-child(17) {
  --delay: 19.2s;
  --boxY: 2em;
  --rotateDelay: -1s;
  --hue: 288;
}
.boxContainer:nth-child(18) {
  --delay: 20.4s;
  --boxY: 8em;
  --rotateDelay: -0.9s;
  --hue: 306;
}
.boxContainer:nth-child(19) {
  --delay: 21.6s;
  --boxY: 1em;
  --rotateDelay: -0.1s;
  --hue: 324;
}
.boxContainer:nth-child(20) {
  --delay: 22.8s;
  --boxY: 6em;
  --rotateDelay: -1s;
  --hue: 342;
}

.box {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 1em;
  height: 1em;
  transform-style: preserve-3d;
  -webkit-animation: boxRotate 1s var(--rotateDelay) infinite linear, explode 1ms forwards paused;
          animation: boxRotate 1s var(--rotateDelay) infinite linear, explode 1ms forwards paused;
}
@-webkit-keyframes explode {
  to {
    --itz: 5em;
    --opacity: 0;
  }
}
@keyframes explode {
  to {
    --itz: 5em;
    --opacity: 0;
  }
}
@-webkit-keyframes boxRotate {
  from {
    transform: perspective(5em) rotateX(0deg) rotateY(0deg);
  }
  to {
    transform: perspective(5em) rotateX(90deg) rotateY(180deg);
  }
}
@keyframes boxRotate {
  from {
    transform: perspective(5em) rotateX(0deg) rotateY(0deg);
  }
  to {
    transform: perspective(5em) rotateX(90deg) rotateY(180deg);
  }
}
.box i {
  position: absolute;
  inset: 0;
  background-color: hsl(var(--hue), 100%, 50%);
  opacity: var(--opacity, 1);
  box-shadow: 0 0 0.25em #0007 inset;
  transition: all 0.5s ease-out;
}
.box i:nth-child(1) {
  transform: translateZ(var(--itz, 0.5em));
}
.box i:nth-child(2) {
  transform: rotateY(90deg) translateZ(var(--itz, 0.5em));
}
.box i:nth-child(3) {
  transform: rotateY(180deg) translateZ(var(--itz, 0.5em));
}
.box i:nth-child(4) {
  transform: rotateY(270deg) translateZ(var(--itz, 0.5em));
}
.box i:nth-child(5) {
  transform: rotateX(90deg) translateZ(var(--itz, 0.5em));
}
.box i:nth-child(6) {
  transform: rotateX(.........完整代码请登录后点击上方下载按钮下载查看

网友评论0