js实现一个音乐避障节拍类游戏NANO HEXAGO代码
代码语言:html
所属分类:游戏
代码描述:js实现一个音乐避障节拍类游戏NANO HEXAGO代码,玩家控制一个位于屏幕中心的小三角形或六边形。 通过键盘左右方向键,让图形顺时针或逆时针旋转。避开从中心向外扩展的障碍物。 障碍物会以不同的速度和模式向玩家逼近,玩家需要快速反应并调整角度。
代码标签: js 音乐 避障 节拍类 游戏 代码 NANO HEXAGO
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=Micro+5&display=swap" rel="stylesheet"> <style> body, html { margin: 0; overflow: hidden; width: 100%; height: 100%; display: grid; place-items: center; background: black; } body { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } audio { position: absolute; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; visibility: hidden; } #container { width: 100%; height: 100%; display: grid; left: 0; top: 0; position: fixed; place-items: center; overflow: hidden; } canvas { display: block; transform-origin: center; -ms-interpolation-mode: nearest-neighbor; image-rendering: -moz-crisp-edges; image-rendering: pixelated; } </style> </head> <body translate="no"> <div id="container"> <canvas id="gameCanvas"></canvas> </div> <script> const BASE = 320; // change to 920 to remove pixel look let VIEWPORT_WIDTH = BASE; let VIEWPORT_HEIGHT = Math.floor( (window.innerHeight / window.innerWidth) * BASE ); let SCALE_FACTOR = window.innerWidth / BASE; const canvas = document.getElementById("gameCanvas"); const ctx = canvas.getContext("2d", { alpha: false }); let center = { x: VIEWPORT_WIDTH / 2, y: VIEWPORT_HEIGHT / 2 }; function resizeCanvas() { VIEWPORT_HEIGHT = Math.floor((window.innerHeight / window.innerWidth) * BASE); SCALE_FACTOR = Math.max(BASE, window.innerWidth) / Math.min(BASE, window.innerWidth); canvas.width = VIEWPORT_WIDTH; canvas.height = VIEWPORT_HEIGHT; canvas.style.transform = `scale(${SCALE_FACTOR})`; center = { x: VIEWPORT_WIDTH / 2, y: VIEWPORT_HEIGHT / 2 }; container.style.width = `${VIEWPORT_WIDTH * SCALE_FACTOR}px`; container.style.height = `${VIEWPORT_HEIGHT * SCALE_FACTOR}px`; } window.addEventListener("resize", resizeCanvas); resizeCanvas(); const CONFIG = { COLORS: { running: [ { areas: [ "#352879", "#6C5EB5", "#352879", "#6C5EB5", "#352879", "#6C5EB5" ], hexagon: { fill: "#6C5EB5", stroke: "#B3995D" }, obstacle: { normal: "#B03FB6", collision: "#FF7C00" }, player: "#68B2B2" }, { areas: [ "#8B76E7", "#4B3C83", "#8B76E7", "#4B3C83", "#8B76E7", "#4B3C83" ], hexagon: { fill: "#8B76E7", stroke: "#68B2B2" }, obstacle: { normal: "#E04B4B", collision: "#FF7C00" }, player: "#59FF59" }, { areas: [ "#2B335F", "#5955D8", "#2B335F", "#5955D8", "#2B335F", "#5955D8" ], hexagon: { fill: "#5955D8", stroke: "#59FF59" }, obstacle: { normal: "#B55EE3", collision: "#FF7C00" }, player: "#68E2E2" }, { areas: [ "#9B51E0", "#4B2B59", "#9B51E0", "#4B2B59", "#9B51E0", "#4B2B59" ], hexagon: { fill: "#9B51E0", stroke: "#68E2E2" }, obstacle: { normal: "#7C54E3", collision: "#FF7C00" }, player: "#59FF98" } ], strobo: [ { areas: [ "#2B335F", "#5955D8", "#2B335F", "#5955D8", "#2B335F", "#5955D8" ], hexagon: { fill: "#5955D8", stroke: "#59FF59" }, obstacle: { normal: "#B55EE3", collision: "#FF7C00" }, player: "#68E2E2" }, { areas: [ "#352879", "#6C5EB5", "#352879", "#6C5EB5", "#352879", "#6C5EB5" ], hexagon: { fill: "#6C5EB5", stroke: "#B3995D" }, obstacle: { normal: "#B03FB6", collision: "#FF7C00" }, player: "#68B2B2" .........完整代码请登录后点击上方下载按钮下载查看
网友评论0