js实现霓虹街机风格的空气曲棍球游戏代码

代码语言:html

所属分类:游戏

代码描述:js实现霓虹街机风格的空气曲棍球游戏代码。玩家通过鼠标或触屏在左半场控制蓝色击球器,与右侧红色cpu对战,率先获得7分者获胜。游戏内置动态物理引擎,每累计2个进球冰球自动加速;当任一方达到6分赛点时,会触发电影级慢动作与黑边特效。此外还包含屏幕震动、粒子爆发、音效反馈及最高球速等数据统计,按s键可切换音效,带来沉浸式的快节奏竞技体验。

代码标签: js 霓虹 街机 风格 空气 曲棍球 游戏 代码

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

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
 
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <link rel='stylesheet' href='https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&amp;family=Rajdhani:wght@300;400;500;600;700&amp;display=swap'>
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css'>
  
<style>
:root {
	--title: "Air Hockey";
	--author: "Matt Cannon";
	--contact: "mc@mattcannon.design";
	--description: "A fast-paced neon air hockey game built with Canvas 2D, featuring responsive mouse and touch controls, dynamic physics, CPU opponent AI, particle effects, sound design, and arcade-style UI. Track stats like streaks, top speed, and power hits while racing to 7 in a glowing, high-energy arena. Includes slo-mo game point moments, screen shake, and confetti victory effects for a polished arcade experience.";
	--keywords: "air hockey, arcade game, canvas game, javascript game, neon, sports game, physics, puck, mallet, cpu ai, particle effects, confetti, sound effects, touch controls, mouse controls, responsive, html5 canvas, game ui, codepen, codepen chall;enge";
	--last-modified: "2026-04-28";
	--content-language: "en";
	--generator: "HTML5, CSS3 (Flexbox, Animations, Keyframes), JavaScript, Canvas 2D API";

	--blue: #00d4ff;
	--red: #ff2d55;
	--gold: #ffc940;
	--bg: #04060a;
	--panel: #080d14;
}

* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

body {
	background: var(--bg);
	min-height: 100vh;
	display: flex;
	align-items: center;
	justify-content: center;
	font-family: "Orbitron", monospace;
	overflow: hidden;
	cursor: none;
	user-select: none;
}

html,
body {
	overscroll-behavior: none;
}

#arena {
	position: relative;
	width: 100%;
	max-width: 760px;
	aspect-ratio: 760 / 520;
	margin: 0 auto;
	touch-action: none;
}

.screen {
	cursor: default;
}
button {
	cursor: pointer;
}

/* ── Layout ── */
#outer {
	display: flex;
	align-items: center;
	gap: 0;
	width: min(100vw, 1100px);
}

canvas {
	display: block;
	width: 100%;
	height: 100%;
	border-radius: 18px;
	box-shadow: 0 0 0 2px rgba(0, 212, 255, 0.2), 0 0 50px rgba(0, 212, 255, 0.1),
		0 20px 70px rgba(0, 0, 0, 0.8);
}

#outer {
	justify-content: center;
}

/* ── Stat Panels ── */
.stat-panel {
	width: 130px;
	flex-shrink: 0;
	padding: 16px 10px 12px;
	background: var(--panel);
	border: 1px solid rgba(255, 255, 255, 0.05);
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0;
}

#stat-left {
	border-radius: 16px 0 0 16px;
	border-right: none;
}
#stat-right {
	border-radius: 0 16px 16px 0;
	border-left: none;
}

.stat-name {
	font-family: "Orbitron", monospace;
	font-weight: 700;
	font-size: 10px;
	letter-spacing: 4px;
	margin-bottom: 6px;
	text-align: center;
	width: 100%;
}

.stat-score {
	font-family: "Orbitron", monospace;
	font-weight: 900;
	font-size: 52px;
	line-height: 1;
	margin-bottom: 6px;
	text-align: center;
	width: 100%;
	letter-spacing: -2px;
}

.stat-divider {
	width: 100%;
	height: 1px;
	background: rgba(255, 255, 255, 0.07);
	margin: 6px 0 8px;
}

.stat-row {
	width: 100%;
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 9px;
}

.stat-label {
	font-family: "Rajdhani", sans-serif;
	font-weight: 500;
	font-size: 9px;
	letter-spacing: 1.5px;
	color: rgba(255, 255, 255, 0.3);
	text-transform: uppercase;
}

.stat-val {
	font-family: "Orbitron", monospace;
	font-weight: 700;
	font-size: 12px;
	color: rgba(255, 255, 255, 0.75);
}

.stat-footer {
	font-family: "Rajdhani", sans-serif;
	font-weight: 500;
	font-size: 9px;
	letter-spacing: 2px;
	color: rgba(255, 255, 255, 0.2);
	text-align: center;
	text-transform: uppercase;
	margin-top: 2px;
}

/* ── Screens ── */
#ui {
	position: absolute;
	inset: 0;
	pointer-events: none;
	border-radius: 18px;
	overflow: hidden;
}

.screen {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.4s ease;
	background: rgba(4, 6, 10, 0.4);
	backdrop-filter: blur(8px);
	border-radius: 18px;
}
.screen.on {
	opacity: 1;
	pointer-events: all;
}

/* ── Ready ── */
.ready-inner {
	text-align: center;
}

.ready-logo {
	font-weight: 900;
	font-size: clamp(42px, 8vw, 72px);
	line-height: 0.9;
	color: #fff;
}
.ready-logo span {
	display: block;
	color: var(--blue);
	text-shadow: 0 0 30px var(--blue), 0 0 70px rgba(0, 212, 255, 0.35);
}

.ready-sub {
	font-family: "Rajdhani", sans-serif;
	font-weight: 300;
	font-size: 12px;
	letter-spacing: 10px;
	color: var(--gold);
	margin-top: 6px;
	margin-bottom: 28px;
}

.ready-prompt {
	font-size: 13px;
	font-weig.........完整代码请登录后点击上方下载按钮下载查看

网友评论0