js实现控制小球收集金币躲避障碍闯关游戏代码

代码语言:html

所属分类:游戏

代码描述:js实现控制小球收集金币躲避障碍闯关游戏代码

代码标签: js 控制 小球 收集 金币 躲避 障碍 闯关 游戏 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>小球闯关游戏</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  background: #1a1a2e;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-family: Arial, sans-serif;
  overflow: hidden;
}
#gameContainer {
  position: relative;
  width: 400px;
  height: 650px;
  overflow: hidden;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  background: #f5deb3;
}
canvas {
  display: block;
  position: absolute;
  top: 0; left: 0;
}
#hud {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  pointer-events: none;
  z-index: 5;
}
#scoreBox {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.45);
  color: #fff;
  font-size: 22px;
  font-weight: bold;
  padding: 4px 22px;
  border-radius: 20px;
  letter-spacing: 1px;
}
#levelBox {
  position: absolute;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.3);
  color: #fff;
  font-size: 13px;
  padding: 2px 14px;
  border-radius: 12px;
}
#livesBox {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 18px;
  background: rgba(0,0,0,0.3);
  padding: 3px 8px;
  border-radius: 12px;
}
#progressWrap {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 70px;
  height: 10px;
  background: rgba(255,255,255,0.25);
  border-radius: 5px;
  overflow: hidden;
}
#progressBar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2ecc71, #27ae60);
  border-radius: 5px;
  transition: width 0.2s;
}
#controls {
  position: absolute;
  bottom: 16px;
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  gap: 12px;
  z-index: 10;
  pointer-events: all;
}
.ctrl-btn {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.6);
  background: rgba(255,255,255,0.75);
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  transition: transform 0.08s, background 0.08s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.ctrl-btn:active, .ctrl-btn.pressed {
  transform: scale(0.88);
  background: rgba(200,200,200,0.9);
}
#overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.72);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 20;
  border-radius: 20px;
}
#overlay h1 { color: #fff; font-size: 34px; margin-bottom: 10px; }
#overlay .sub { color: #ccc; font-size: 14px; margin-bottom: 28px; text-align: center; line-height: 1.7; }
#overlay .finalScore { color: #ffd700; font-size: 28px; font-weight: bold; margin-bottom: 6px; }
.startBtn {
  padding: 14px 44px;
  font-size: 20px;
  border: none;
  border-radius: 30px;
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  color: .........完整代码请登录后点击上方下载按钮下载查看

网友评论0