寻仙蜃楼
by WildMaker43582 lines14.1 KB
<!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: radial-gradient(ellipse at top, #1b2540 0%, #0a0f1f 70%);
color: #f4e9c8;
font-family: "KaiTi", "STKaiti", serif;
overflow: hidden;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
#game {
position: relative;
width: 960px;
height: 600px;
border: 2px solid #3a4a70;
border-radius: 18px;
overflow: hidden;
background: linear-gradient(180deg, #2c3a5e 0%, #121a33 100%);
box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
canvas { display: block; background: transparent; }
#ui {
position: absolute;
top: 14px; left: 14px; right: 14px;
display: flex;
justify-content: space-between;
align-items: center;
pointer-events: none;
z-index: 10;
}
.panel {
background: rgba(12, 20, 42, 0.55);
border: 1px solid #4a5d8c;
border-radius: 12px;
padding: 10px 14px;
backdrop-filter: blur(6px);
pointer-events: auto;
}
#title { font-size: 20px; letter-spacing: 4px; }
#status { font-size: 15px; }
#diceBtn {
pointer-events: auto;
width: 90px; height: 90px;
border-radius: 50%;
border: 2px solid #f4e9c8;
background: radial-gradient(circle at 30% 30%, #f7d56a, #b57b1f);
font-size: 34px;
color: #3b2a08;
font-weight: bold;
cursor: pointer;
box-shadow: 0 10px 24px rgba(0,0,0,0.45);
transition: transform 0.15s;
}
#diceBtn:hover { transform: scale(1.08); }
#diceBtn:disabled { opacity: 0.45; cursor: not-allowed; }
#message {
position: absolute;
left: 50%;
bottom: 18px;
transform: translateX(-50%);
background: rgba(12, 20, 42, 0.6);
border: 1px solid #4a5d8c;
border-radius: 12px;
padding: 10px 18px;
font-size: 16px;
letter-spacing: 2px;
opacity: 0;
transition: opacity 0.35s;
pointer-events: none;
z-index: 10;
white-space: nowrap;
}
#hint {
position: absolute;
top: 70px; left: 50%;
transform: translateX(-50%);
font-size: 14px;
color: #d7c99a;
letter-spacing: 3px;
opacity: 0.8;
pointer-events: none;
}
#resetBtn {
position: absolute;
bottom: 18px; right: 18px;
padding: 8px 14px;
border-radius: 10px;
border: 1px solid #4a5d8c;
background: rgba(12, 20, 42, 0.6);
color: #f4e9c8;
cursor: pointer;
font-family: inherit;
z-index: 10;
}
#resetBtn:hover { background: rgba(74, 93, 140, 0.4); }
</style>
</head>
<body>
<div id="game">
<canvas id="stage" width="960" height="600"></canvas>
<div id="ui">
<div class="panel" id="title">寻仙蜃楼</div>
<div class="panel" id="status">关卡:1 步数:0</div>
<button id="diceBtn" disabled>🎲</button>
</div>
<div id="hint">点击骰子决定步数,踏过蜃楼古台,抵达天门</div>
<div id="message"></div>
<button id="resetBtn">重新开始</button>
</div>
<script>
const canvas = document.getElementById("stage");
const ctx = canvas.getContext("2d");
const W = canvas.width;
const H = canvas.height;
const diceBtn = document.getElementById("diceBtn");
const statusEl = document.getElementById("status");
const messageEl = document.getElementById("message");
const resetBtn = document.getElementById("resetBtn");
// 古风背景音乐
const bgm = new Audio("https://cdn.pixabay.com/audio/2022/10/30/audio_3a5da5af71.mp3");
bgm.loop = true;
bgm.volume = 0.5;
// 主角IP:蓝发古风小人
const hero = {
x: 90, y: 460,
targetX: 90, targetY: 460,
stepIndex: 0,
moving: false,
pathIndex: 0,
scale: 1
};
// 关卡路径:古风蜃楼式错层平台
const level = {
platforms: [
{ x: 40, y: 490, w: 160, h: 24, type: "start" },
{ x: 230, y: 430, w: 140, h: 24, type: "normal" },
{ x: 400, y: 370, w: 140, h: 24, type: "puzzle" },
{ x: 570, y: 310, w: 140, h: 24, type: "normal" },
{ x: 740, y: 250, w: 180, h: 24, type: "end" }
],
path: [
{ x: 120, y: 460 },
{ x: 300, y: 400 },
{ x: 470, y: 340 },
{ x: 640, y: 280 },
{ x: 830, y: 220 }
],
gates: [
{ x: 380, y: 410, w: 20, h: 60, open: false, label: "雾门" },
{ x: 550, y: 350, w: 20, h: 60, open: false, label: "星门" }
],
puzzles: [
{ x: 440, y: 350, r: 18, active: false, order: 1 },
{ x: 500, y: 350, r: 18, active: false, order: 2 }
]
};
let gameState = {
steps: 0,
phase: "start", // start / rolling / moving / puzzle / win
rollResult: 0,
moveQueue: [],
messageTimer: null
};
function showMessage(text) {
messageEl.textContent = text;
messageEl.style.opacity = "1";
clearTimeout(gameState.messageTimer);
gameState.messageTimer = setTimeout(() => {
messageEl.style.opacity = "0";
}, 2200);
}
function updateStatus() {
statusEl.textContent = "关卡:1 步数:" + gameState.steps;
}
// 输入
diceBtn.addEventListener("click", rollDice);
resetBtn.addEventListener("click", resetGame);
// 初始化
function init() {
hero.x = level.path[0].x;
hero.y = level.path[0].y;
hero.targetX = hero.x;
hero.targetY = hero.y;
hero.pathIndex = 0;
hero.moving = false;
gameState.steps = 0;
gameState.phase = "start";
gameState.moveQueue = [];
level.gates[0].open = false;
level.gates[1].open = false;
level.puzzles[0].active = false;
level.puzzles[1].active = false;
diceBtn.disabled = false;
updateStatus();
showMessage "点击骰子,决定前行步数");
}
function resetGame() {
bgm.pause();
bgm.currentTime = 0;
init();
}
// 骰子
function rollDice() {
if (gameState.phase === "moving" || gameState.phase === "puzzle") return;
if (bgm.paused) {
bgm.play().catch(() => {});
}
gameState.rollResult = Math.floor(Math.random() * 6) + 1;
gameState.phase = "rolling";
diceBtn.disabled = true;
showMessage("骰子:" + gameState.rollResult + " 点");
// 构造移动队列
gameState.moveQueue = [];
for (let i = 1; i <= gameState.rollResult; i++) {
let next = hero.pathIndex + i;
if (next < level.path.length) {
gameState.moveQueue.push({
x: level.path[next].x,
y: level.path[next].y,
pathIndex: next
});
}
}
setTimeout(() => {
gameState.phase = "moving";
moveStep();
}, 700);
}
// 逐格移动
function moveStep() {
if (gameState.moveQueue.length === 0) {
arriveCheck();
return;
}
const next = gameState.moveQueue.shift();
hero.targetX = next.x;
hero.targetY = next.y;
hero.pathIndex = next.pathIndex;
hero.moving = true;
}
function arriveCheck() {
gameState.steps += gameState.rollResult;
updateStatus();
// 到达终点
if (hero.pathIndex >= level.path.length - 1) {
gameState.phase = "win";
showMessage "恭喜抵达天门,寻仙圆满!");
diceBtn.disabled = true;
return;
}
// 机关触发
if (hero.pathIndex === 1 && !level.gates[0].open) {
gameState.phase = "puzzle";
showMessage "雾门阻挡,踩下机关开启通路");
openGate(0);
return;
}
if (hero.pathIndex === 2 && !level.gates[1].open) {
gameState.phase = "puzzle";
showMessage "星门封印,依次点亮星盘");
startPuzzleSequence();
return;
}
gameState.phase = "start";
diceBtn.disabled = false;
}
// 开门
function openGate(index) {
level.gates[index].open = true;
showMessage(level.gates[index].label + " 已开启");
setTimeout(() => {
gameState.phase = "start";
diceBtn.disabled = false;
}, 1400);
}
// 小型顺序机关谜题
let puzzleStep = 0;
function startPuzzleSequence() {
puzzleStep = 0;
showMessage "按顺序触碰星盘:先 1,再 2");
}
function clickPuzzle(x, y) {
if (gameState.phase !== "puzzle") return;
for (let p of level.puzzles) {
const dx = x - p.x;
const dy = y - p.y;
if (dx * dx + dy * dy < p.r * p.r) {
if (p.order === puzzleStep + 1) {
p.active = true;
puzzleStep = p.order;
showMessage "星盘 " + p.order + " 已点亮");
if (puzzleStep >= level.puzzles.length) {
setTimeout(() => openGate(1), 900);
}
} else {
showMessage "顺序错误,重新开始");
puzzleStep = 0;
level.puzzles.forEach(p => p.active = false);
}
return;
}
}
}
canvas.addEventListener("click", (e) => {
const rect = canvas.getBoundingClientRect();
const x = (e.clientX - rect.left) * (W / rect.width);
const y = (e.clientY - rect.top) * (H / rect.height);
clickPuzzle(x, y);
});
// 绘制
function draw() {
ctx.clearRect(0, 0, W, H);
drawBackground();
drawPlatforms();
drawPath();
drawGates();
drawPuzzles();
drawHero();
}
function drawBackground() {
// 远山
ctx.fillStyle = "#1a2447";
ctx.beginPath();
ctx.moveTo(0, 420);
ctx.lineTo(180, 300);
ctx.lineTo(340, 380);
ctx.lineTo(520, 260);
ctx.lineTo(720, 340);
ctx.lineTo(960, 280);
ctx.lineTo(960, 600);
ctx.lineTo(0, 600);
ctx.closePath();
ctx.fill();
// 云
ctx.strokeStyle = "rgba(244, 233, 200, 0.35)";
ctx.lineWidth = 2;
for (let i = 0; i < 4; i++) {
ctx.beginPath();
ctx.arc(180 + i * 240, 120 + (i % 2) * 40, 30, 0, Math.PI * 2);
ctx.stroke();
}
// 月
ctx.fillStyle = "rgba(244, 233, 200, 0.9)";
ctx.beginPath();
ctx.arc(820, 110, 40, 0, Math.PI * 2);
ctx.fill();
}
function drawPlatforms() {
level.platforms.forEach(p => {
// 平台阴影
ctx.fillStyle = "rgba(0,0,0,0.25)";
ctx.fillRect(p.x + 4, p.y + 4, p.w, p.h);
// 平台主体
const grad = ctx.createLinearGradient(p.x, p.y, p.x, p.y + p.h);
if (p.type === "start") {
grad.addColorStop(0, "#d7b36a");
grad.addColorStop(1, "#8a6a2b");
} else if (p.type === "end") {
grad.addColorStop(0, "#9ad7ff");
grad.addColorStop(1, "#365f8c");
} else if (p.type === "puzzle") {
grad.addColorStop(0, "#b7a8ff");
grad.addColorStop(1, "#5a4fa3");
} else {
grad.addColorStop(0, "#c9b58a");
grad.addColorStop(1, "#7a6540");
}
ctx.fillStyle = grad;
ctx.fillRect(p.x, p.y, p.w, p.h);
// 古纹
ctx.strokeStyle = "rgba(244, 233, 200, 0.5)";
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(p.x + 10, p.y + p.h / 2);
ctx.lineTo(p.x + p.w - 10, p.y + p.h / 2);
ctx.stroke();
});
}
function drawPath() {
ctx.strokeStyle = "rgba(244, 233, 200, 0.4)";
ctx.lineWidth = 2;
ctx.setLineDash([6, 8]);
ctx.beginPath();
ctx.moveTo(level.path[0].x, level.path[0].y);
for (let i = 1; i < level.path.length; i++) {
ctx.lineTo(level.path[i].x, level.path[i].y);
}
ctx.stroke();
ctx.setLineDash([]);
}
function drawGates() {
level.gates.forEach(g => {
if (g.open) {
ctx.strokeStyle = "rgba(154, 215, 255, 0.7)";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(g.x, g.y);
ctx.lineTo(g.x + g.w, g.y + g.h);
ctx.stroke();
} else {
ctx.fillStyle = "#3a4a70";
ctx.fillRect(g.x, g.y, g.w, g.h);
ctx.strokeStyle = "#f4e9c8";
ctx.lineWidth = 2;
ctx.strokeRect(g.x, g.y, g.w, g.h);
ctx.fillStyle = "#f4e9c8";
ctx.font = "12px KaiTi";
ctx.textAlign = "center";
ctx.fillText(g.label, g.x + g.w / 2, g.y - 6);
}
});
}
function drawPuzzles() {
level.puzzles.forEach(p => {
ctx.beginPath();
ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2);
if (p.active) {
ctx.fillStyle = "#f7d56a";
ctx.shadowColor = "#f7d56a";
ctx.shadowBlur = 20;
} else {
ctx.fillStyle = "#5a4fa3";
ctx.shadowBlur = 0;
}
ctx.fill();
ctx.shadowBlur = 0;
ctx.strokeStyle = "#f4e9c8";
ctx.lineWidth = 2;
ctx.stroke();
ctx.fillStyle = "#121a33";
ctx.font = "bold 14px KaiTi";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(p.order, p.x, p.y);
});
}
function drawHero() {
ctx.save();
ctx.translate(hero.x, hero.y);
ctx.scale(hero.scale, hero.scale);
// 影子
ctx.fillStyle = "rgba(0,0,0,0.3)";
ctx.beginPath();
ctx.ellipse(0, 22, 16, 5, 0, 0, Math.PI * 2);
ctx.fill();
// 蓝色长发
ctx.fillStyle = "#00bfff";
ctx.beginPath();
ctx.moveTo(-14, -8);
ctx.quadraticCurveTo(-28, 10, -22, 30);
ctx.quadraticCurveTo(-10, 22, 0, 24);
ctx.quadraticCurveTo(10, 22, 22, 30);
ctx.quadraticCurveTo(28, 10, 14, -8);
ctx.closePath();
ctx.fill();
// 头部
ctx.fillStyle = "#f4e9c8";
ctx.beginPath();
ctx.arc(0, -4, 10, 0, Math.PI * 2);
ctx.fill();
// 眼睛
ctx.fillStyle = "#121a33";
ctx.beginPath();
ctx.arc(-3, -4, 1.5, 0, Math.PI * 2);
ctx.arc(3, -4, 1.5, 0, Math.PI * 2);
ctx.fill();
// 额饰
ctx.fillStyle = "#f7d56a";
ctx.beginPath();
ctx.arc(0, -9, 1.8, 0, Math.PI * 2);
ctx.fill();
// 黑衣服
ctx.fillStyle = "#1a1a2e";
ctx.beginPath();
ctx.moveTo(-8, 6);
ctx.lineTo(8, 6);
ctx.lineTo(10, 24);
ctx.lineTo(-10, 24);
ctx.closePath();
ctx.fill();
// 白色腰带
ctx.strokeStyle = "#f4e9c8";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(-8, 12);
ctx.lineTo(8, 12);
ctx.stroke();
ctx.restore();
}
// 主角移动动画
function updateHero() {
const dx = hero.targetX - hero.x;
const dy = hero.targetY - hero.y;
const dist = Math.hypot(dx, dy);
if (dist > 0.5) {
hero.x += dx * 0.12;
hero.y += dy * 0.12;
hero.moving = true;
} else if (hero.moving) {
hero.x = hero.targetX;
hero.y = hero.targetY;
hero.moving = false;
setTimeout(moveStep, 220);
}
}
function loop() {
updateHero();
draw();
requestAnimationFrame(loop);
}
init();
loop();
</script>
</body>
</html>
Game Source: 寻仙蜃楼
Creator: WildMaker43
Libraries: none
Complexity: complex (582 lines, 14.1 KB)
The full source code is displayed above on this page.
Remix Instructions
To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: game-wildmaker43" to link back to the original. Then publish at arcadelab.ai/publish.