diff --git a/site/src/quantum-devil/QuantumDevilDialog.jsx b/site/src/quantum-devil/QuantumDevilDialog.jsx index f29863b..d5e9cb3 100644 --- a/site/src/quantum-devil/QuantumDevilDialog.jsx +++ b/site/src/quantum-devil/QuantumDevilDialog.jsx @@ -1,10 +1,12 @@ import React from "react"; const INITIAL_STATUS = { - level: 1, - levelName: "Detector floor", + zone: 1, + zoneName: "Detector ascent", phase: "|0>", deaths: 0, + altitude: 0, + score: 0, completed: false, }; @@ -147,8 +149,10 @@ export default function QuantumDevilDialog({ open, onClose }) {
- Level {status.level}/3 - {status.completed ? "Experiment complete" : status.levelName} + Zone {status.zone}/3 + {status.completed ? "Summit reached" : status.zoneName} + Altitude {status.altitude}% + Coherence {String(status.score).padStart(4, "0")} State {status.phase} Retries {status.deaths}
diff --git a/site/src/quantum-devil/createQuantumDevilGame.js b/site/src/quantum-devil/createQuantumDevilGame.js index 471219b..3a95d1d 100644 --- a/site/src/quantum-devil/createQuantumDevilGame.js +++ b/site/src/quantum-devil/createQuantumDevilGame.js @@ -1,8 +1,17 @@ import Phaser from "phaser"; -const GAME_WIDTH = 960; -const GAME_HEIGHT = 540; -const LEVEL_NAMES = ["Detector floor", "Superposition bridge", "Entangled crossings"]; +const GAME_WIDTH = 800; +const GAME_HEIGHT = 600; +const RENDER_SCALE = 2; +const MASCOT_SCALE = 0.82; +const WORLD_HEIGHT = 3300; +const START_Y = 3080; +const ZONE_NAMES = ["Detector ascent", "Superposition shaft", "Entangled summit"]; +const CHECKPOINTS = [ + { x: 90, y: START_Y }, + { x: 400, y: 2240 }, + { x: 400, y: 1200 }, +]; class QuantumDevilScene extends Phaser.Scene { constructor(callbacks) { @@ -11,21 +20,34 @@ class QuantumDevilScene extends Phaser.Scene { } init(data = {}) { - this.levelIndex = data.levelIndex ?? 0; this.deaths = data.deaths ?? 0; - this.phase = data.phase ?? 0; + this.checkpointZone = data.checkpointZone ?? 0; + this.zoneIndex = this.checkpointZone; + this.phase = 0; this.completed = false; this.dying = false; this.external = { left: false, right: false }; this.pendingJump = false; + this.lastGroundedAt = 0; + this.jumpBufferedUntil = 0; + this.wasGrounded = false; + this.previousVelocityY = 0; + this.landingUntil = 0; + this.lastStatusKey = ""; } create() { try { + this.physics.world.setBounds(0, 0, GAME_WIDTH, WORLD_HEIGHT); this.drawBackground(); - this.createWorld(); + this.createCharacterTextures(); + this.createTower(); + this.createPlayer(); this.createKeyboard(); - this.emitState(); + this.createProgressRail(); + this.configureCamera(); + this.applyPhase(false); + this.emitState(true); this.callbacks.onReady?.(); } catch (error) { this.callbacks.onError?.(error instanceof Error ? error.message : "Game initialization failed."); @@ -33,103 +55,283 @@ class QuantumDevilScene extends Phaser.Scene { } drawBackground() { - this.cameras.main.setBackgroundColor("#05070b"); - const grid = this.add.graphics(); - grid.lineStyle(1, 0x163044, 0.45); - for (let x = 0; x <= GAME_WIDTH; x += 48) { - grid.lineBetween(x, 0, x, GAME_HEIGHT); + this.cameras.main.setBackgroundColor("#03070b"); + const bands = [ + { y: 2675, height: 1250, color: 0x07131d, accent: 0x22d3ee }, + { y: 1775, height: 550, color: 0x0a1020, accent: 0x7c6cff }, + { y: 650, height: 1700, color: 0x07151a, accent: 0x35e0b8 }, + ]; + + bands.forEach(({ y, height, color, accent }) => { + this.add.rectangle(GAME_WIDTH / 2, y, GAME_WIDTH, height, color, 1).setDepth(-12); + this.add.rectangle(8, y, 4, height - 40, accent, 0.52).setDepth(-11); + }); + + const grid = this.add.graphics().setDepth(-10); + grid.lineStyle(1, 0x173044, 0.36); + for (let x = 0; x <= GAME_WIDTH; x += 50) { + grid.lineBetween(x, 0, x, WORLD_HEIGHT); } - for (let y = 0; y <= GAME_HEIGHT; y += 48) { + for (let y = 0; y <= WORLD_HEIGHT; y += 50) { grid.lineBetween(0, y, GAME_WIDTH, y); } - const wave = this.add.graphics(); - wave.lineStyle(2, 0x22d3ee, 0.16); - wave.beginPath(); - for (let x = 0; x <= GAME_WIDTH; x += 8) { - const y = 165 + Math.sin(x / 38) * 22; - x === 0 ? wave.moveTo(x, y) : wave.lineTo(x, y); - } - wave.strokePath(); - } - - createWorld() { - this.platforms = this.physics.add.staticGroup(); - this.hazards = this.physics.add.staticGroup(); - this.phasePlatforms = []; - - this.addHazard(GAME_WIDTH / 2, GAME_HEIGHT - 4, GAME_WIDTH, 8); - this.add.text(28, 24, `0${this.levelIndex + 1} / 03`, { - color: "#22d3ee", - fontFamily: "Roboto Mono, monospace", - fontSize: "14px", - fontStyle: "bold", - }); - this.add.text(28, 48, LEVEL_NAMES[this.levelIndex].toUpperCase(), { - color: "#f8fafc", - fontFamily: "Arial, sans-serif", - fontSize: "22px", - fontStyle: "bold", + const waves = this.add.graphics().setDepth(-9); + [2840, 1880, 780].forEach((baseline, index) => { + waves.lineStyle(2, index === 1 ? 0x8b5cf6 : 0x22d3ee, 0.18); + waves.beginPath(); + for (let x = 0; x <= GAME_WIDTH; x += 8) { + const y = baseline + Math.sin(x / 38) * 22; + x === 0 ? waves.moveTo(x, y) : waves.lineTo(x, y); + } + waves.strokePath(); }); + } - if (this.levelIndex === 0) { - this.buildDetectorLevel(); - } else if (this.levelIndex === 1) { - this.buildSuperpositionLevel(); - } else { - this.buildEntanglementLevel(); + createCharacterTextures() { + if (this.textures.exists("qd-mascot-idle-a")) { + return; } - this.player = this.add.rectangle(this.spawn.x, this.spawn.y, 28, 34, 0xf8fafc); - this.player.setStrokeStyle(3, 0x22d3ee, 1); - this.physics.add.existing(this.player); - this.player.body.setCollideWorldBounds(true); - this.player.body.setMaxVelocity(290, 720); - this.player.body.setDragX(900); + const makeFrame = (key, pose = {}) => { + const { + headY = 10, + bodyY = 40, + blink = false, + mouth = "smile", + leftArm = [20, 44, 10, 54], + rightArm = [44, 44, 54, 54], + leftLeg = [27, 59, 22, 70], + rightLeg = [37, 59, 42, 70], + } = pose; + const graphics = this.make.graphics({ x: 0, y: 0, add: false }); + + graphics.fillStyle(0x22d3ee, 0.12); + graphics.fillCircle(32, headY + 20, 28); + + graphics.lineStyle(3, 0x8b5cf6, 1); + graphics.lineBetween(32, headY + 2, 32, headY - 5); + graphics.fillStyle(0x8b5cf6, 1); + graphics.fillCircle(32, headY - 7, 4); + graphics.fillStyle(0xf8fafc, 1); + graphics.fillCircle(32, headY - 7, 1.5); + + graphics.lineStyle(5, 0x22d3ee, 1); + graphics.lineBetween(...leftArm); + graphics.lineBetween(...rightArm); + graphics.fillStyle(0xf8fafc, 1); + graphics.fillCircle(leftArm[2], leftArm[3], 4); + graphics.fillCircle(rightArm[2], rightArm[3], 4); + + graphics.lineStyle(6, 0x8b5cf6, 1); + graphics.lineBetween(...leftLeg); + graphics.lineBetween(...rightLeg); + graphics.fillStyle(0xf8fafc, 1); + graphics.fillRoundedRect(leftLeg[2] - 7, leftLeg[3] - 2, 14, 6, 3); + graphics.fillRoundedRect(rightLeg[2] - 7, rightLeg[3] - 2, 14, 6, 3); + + graphics.fillStyle(0x0b2230, 1); + graphics.lineStyle(3, 0x8b5cf6, 1); + graphics.fillRoundedRect(20, bodyY, 24, 22, 7); + graphics.strokeRoundedRect(20, bodyY, 24, 22, 7); + graphics.fillStyle(0x35e0b8, 1); + graphics.fillTriangle(32, bodyY + 5, 37, bodyY + 11, 32, bodyY + 17); + graphics.fillTriangle(32, bodyY + 5, 27, bodyY + 11, 32, bodyY + 17); + + graphics.lineStyle(3, 0x22d3ee, 1); + graphics.fillStyle(0x07131d, 1); + graphics.fillRoundedRect(12, headY, 40, 37, 13); + graphics.strokeRoundedRect(12, headY, 40, 37, 13); + graphics.fillStyle(0x0d2d3d, 1); + graphics.fillRoundedRect(17, headY + 8, 30, 20, 8); + + graphics.fillStyle(0xf8fafc, 1); + if (blink) { + graphics.fillRect(22, headY + 17, 7, 2); + graphics.fillRect(35, headY + 17, 7, 2); + } else { + graphics.fillRoundedRect(22, headY + 13, 7, 9, 3); + graphics.fillRoundedRect(35, headY + 13, 7, 9, 3); + graphics.fillStyle(0x22d3ee, 1); + graphics.fillCircle(26, headY + 17, 2); + graphics.fillCircle(39, headY + 17, 2); + } - this.physics.add.collider(this.player, this.platforms); - this.physics.add.overlap(this.player, this.hazards, () => this.failLevel()); - this.physics.add.overlap(this.player, this.goal, () => this.finishLevel()); + graphics.lineStyle(2, 0x8bdcf3, 1); + if (mouth === "open") { + graphics.strokeCircle(32, headY + 27, 3); + } else if (mouth === "flat") { + graphics.lineBetween(27, headY + 27, 37, headY + 27); + } else { + graphics.beginPath(); + graphics.moveTo(27, headY + 26); + graphics.lineTo(32, headY + 29); + graphics.lineTo(37, headY + 26); + graphics.strokePath(); + } - this.instruction = this.add.text(GAME_WIDTH / 2, GAME_HEIGHT - 26, this.levelInstruction(), { - color: "#a8bac9", - fontFamily: "Roboto Mono, monospace", - fontSize: "12px", - align: "center", - }).setOrigin(0.5); - } + graphics.generateTexture(key, 64, 76); + graphics.destroy(); + }; + + makeFrame("qd-mascot-idle-a"); + makeFrame("qd-mascot-idle-b", { headY: 11, bodyY: 41 }); + makeFrame("qd-mascot-blink", { blink: true }); + makeFrame("qd-mascot-run-a", { + headY: 11, + leftArm: [20, 44, 12, 36], + rightArm: [44, 44, 55, 51], + leftLeg: [27, 59, 18, 68], + rightLeg: [37, 59, 47, 70], + }); + makeFrame("qd-mascot-run-b", { + headY: 9, + leftArm: [20, 44, 10, 51], + rightArm: [44, 44, 53, 36], + leftLeg: [27, 59, 25, 71], + rightLeg: [37, 59, 39, 67], + }); + makeFrame("qd-mascot-run-c", { + headY: 11, + leftArm: [20, 44, 9, 52], + rightArm: [44, 44, 52, 36], + leftLeg: [27, 59, 17, 70], + rightLeg: [37, 59, 46, 68], + }); + makeFrame("qd-mascot-rise", { + headY: 7, + bodyY: 38, + mouth: "open", + leftArm: [20, 42, 10, 24], + rightArm: [44, 42, 54, 24], + leftLeg: [27, 57, 21, 64], + rightLeg: [37, 57, 43, 64], + }); + makeFrame("qd-mascot-fall", { + headY: 9, + bodyY: 39, + mouth: "open", + leftArm: [20, 44, 7, 43], + rightArm: [44, 44, 57, 43], + leftLeg: [27, 59, 23, 72], + rightLeg: [37, 59, 41, 72], + }); + makeFrame("qd-mascot-land", { + headY: 17, + bodyY: 45, + mouth: "flat", + leftArm: [20, 49, 8, 52], + rightArm: [44, 49, 56, 52], + leftLeg: [27, 64, 19, 69], + rightLeg: [37, 64, 45, 69], + }); - createKeyboard() { - this.cursors = this.input.keyboard.createCursorKeys(); - this.keys = this.input.keyboard.addKeys({ - left: Phaser.Input.Keyboard.KeyCodes.A, - right: Phaser.Input.Keyboard.KeyCodes.D, - jump: Phaser.Input.Keyboard.KeyCodes.W, - measure: Phaser.Input.Keyboard.KeyCodes.M, - restart: Phaser.Input.Keyboard.KeyCodes.R, - space: Phaser.Input.Keyboard.KeyCodes.SPACE, + this.anims.create({ + key: "qd-mascot-idle", + frames: [ + { key: "qd-mascot-idle-a" }, + { key: "qd-mascot-idle-b" }, + { key: "qd-mascot-idle-a" }, + { key: "qd-mascot-blink" }, + ], + frameRate: 2, + repeat: -1, + }); + this.anims.create({ + key: "qd-mascot-run", + frames: [ + { key: "qd-mascot-run-a" }, + { key: "qd-mascot-run-b" }, + { key: "qd-mascot-run-c" }, + { key: "qd-mascot-run-b" }, + ], + frameRate: 11, + repeat: -1, }); } - addPlatform(x, y, width, height = 22, color = 0x183047) { - const platform = this.add.rectangle(x, y, width, height, color, 1); - platform.setStrokeStyle(1, 0x4c718c, 0.8); + createTower() { + this.platforms = this.physics.add.staticGroup(); + this.hazards = this.physics.add.staticGroup(); + this.phasePlatforms = []; + + this.addHazard(GAME_WIDTH / 2, WORLD_HEIGHT - 8, GAME_WIDTH, 16); + this.addPlatform(130, 3160, 260, 76, "checkpoint"); + this.addPlatform(270, 3000, 220, 22, "crumble"); + this.addPlatform(520, 2860, 220); + this.addPlatform(280, 2720, 220, 22, "crumble"); + this.addPlatform(520, 2580, 220); + this.addPlatform(280, 2440, 220, 22, "crumble"); + this.addPlatform(400, 2300, 650, 26, "checkpoint"); + + this.addPhasePlatform(180, 2160, 190, 0); + this.addPlatform(440, 2020, 190); + this.addPhasePlatform(620, 1880, 190, 1); + this.addPlatform(390, 1740, 190); + this.addPhasePlatform(175, 1600, 190, 0); + this.addPlatform(420, 1460, 190); + this.addPhasePlatform(620, 1320, 190, 1); + this.addPlatform(400, 1260, 650, 26, "checkpoint"); + + this.addPhasePlatform(180, 1100, 190, 0, true); + this.addPlatform(420, 960, 180); + this.addPhasePlatform(620, 820, 190, 1, true); + this.addPlatform(420, 680, 180); + this.addPhasePlatform(180, 540, 190, 0, true); + this.addPlatform(420, 400, 180); + this.addPhasePlatform(610, 270, 190, 1, true); + this.addPlatform(410, 140, 260, 24, "summit"); + this.addGoal(410, 78); + } + + addPlatform(x, y, width, height = 22, kind = "neutral") { + const colors = { + neutral: 0x173149, + crumble: 0x24445a, + checkpoint: 0x123c43, + summit: 0x174f45, + }; + const platform = this.add.rectangle(x, y, width, height, colors[kind] ?? colors.neutral, 1); + platform.setStrokeStyle(kind === "checkpoint" ? 2 : 1, kind === "checkpoint" ? 0x35e0b8 : 0x5a8099, 0.9); + platform.setData("kind", kind); this.platforms.add(platform); platform.body.updateFromGameObject(); + + if (kind === "crumble") { + this.add.rectangle(x, y - 7, width - 20, 2, 0xff6b8a, 0.42); + } + if (kind === "checkpoint") { + this.add.text(x, y - 28, "CHECKPOINT", { + color: "#35e0b8", + fontFamily: "Roboto Mono, monospace", + fontSize: "9px", + resolution: 2, + }).setOrigin(0.5); + } return platform; } - addPhasePlatform(x, y, width, requiredPhase) { + addPhasePlatform(x, y, width, requiredPhase, entangled = false) { const color = requiredPhase === 0 ? 0x22d3ee : 0x8b5cf6; const platform = this.add.rectangle(x, y, width, 20, color, 0.9); platform.setStrokeStyle(2, color, 1); + platform.setData("kind", "phase"); this.platforms.add(platform); platform.body.updateFromGameObject(); this.phasePlatforms.push({ platform, requiredPhase, color }); + + const label = entangled ? `E${requiredPhase}` : `|${requiredPhase}>`; + this.add.text(x, y - 25, label, { + color: `#${color.toString(16).padStart(6, "0")}`, + fontFamily: "Roboto Mono, monospace", + fontSize: "10px", + fontStyle: "bold", + resolution: 2, + }).setOrigin(0.5); return platform; } - addHazard(x, y, width, height = 22) { + addHazard(x, y, width, height = 20) { const hazard = this.add.rectangle(x, y, width, height, 0xff4f78, 0.82); hazard.setStrokeStyle(2, 0xff9caf, 0.9); this.hazards.add(hazard); @@ -138,167 +340,294 @@ class QuantumDevilScene extends Phaser.Scene { } addGoal(x, y) { - const glow = this.add.circle(x, y, 31, 0x22d3ee, 0.12); - this.tweens.add({ targets: glow, alpha: 0.42, scale: 1.22, yoyo: true, repeat: -1, duration: 850 }); - const goal = this.add.rectangle(x, y, 34, 58, 0x071019, 1); - goal.setStrokeStyle(3, 0x22d3ee, 1); + const glow = this.add.circle(x, y, 38, 0x35e0b8, 0.12); + this.tweens.add({ targets: glow, alpha: 0.44, scale: 1.2, yoyo: true, repeat: -1, duration: 800 }); + const goal = this.add.rectangle(x, y, 42, 70, 0x071019, 1); + goal.setStrokeStyle(3, 0x35e0b8, 1); this.physics.add.existing(goal, true); this.goal = goal; - this.add.text(x, y - 48, "EXIT", { - color: "#22d3ee", + this.add.text(x, y - 56, "SUMMIT", { + color: "#35e0b8", fontFamily: "Roboto Mono, monospace", - fontSize: "10px", + fontSize: "11px", fontStyle: "bold", + resolution: 2, }).setOrigin(0.5); } - buildDetectorLevel() { - this.spawn = { x: 70, y: 440 }; - this.addPlatform(130, 500, 260, 80); - this.collapsePlatform = this.addPlatform(370, 478, 150, 22, 0x24425b); - this.addPlatform(705, 500, 510, 80); - this.addGoal(892, 430); - this.detectorTriggered = false; - this.detectorLine = this.add.rectangle(300, 430, 3, 115, 0x22d3ee, 0.42); - this.add.text(283, 360, "DET", { - color: "#22d3ee", - fontFamily: "Roboto Mono, monospace", - fontSize: "10px", + createPlayer() { + const spawn = CHECKPOINTS[this.checkpointZone]; + this.playerGlow = this.add.circle(spawn.x, spawn.y, 34, 0x22d3ee, 0.1).setDepth(8); + this.player = this.physics.add.sprite(spawn.x, spawn.y, "qd-mascot-idle-a").setDepth(10); + this.player.body.setSize(38, 58).setOffset(13, 14); + this.player.setScale(MASCOT_SCALE); + this.player.body.setCollideWorldBounds(true); + this.player.body.setMaxVelocity(310, 760); + this.player.body.setDragX(1050); + this.player.play("qd-mascot-idle"); + + this.physics.add.collider(this.player, this.platforms, (player, platform) => { + this.handlePlatformContact(player, platform); }); + this.physics.add.overlap(this.player, this.hazards, () => this.failRun()); + this.physics.add.overlap(this.player, this.goal, () => this.finishRun()); } - buildSuperpositionLevel() { - this.spawn = { x: 70, y: 440 }; - this.phase = 0; - this.addPlatform(105, 500, 210, 80); - this.addPlatform(840, 500, 240, 80); - this.addHazard(465, 524, 510, 24); - this.addPhasePlatform(320, 388, 170, 1); - this.addPhasePlatform(545, 388, 170, 1); - this.addPhasePlatform(320, 285, 170, 0); - this.addPhasePlatform(545, 285, 170, 0); - this.addGoal(885, 430); - this.applyPhase(); + spawnMotionBurst(kind) { + const isLanding = kind === "land"; + const color = isLanding ? 0x8b5cf6 : 0x22d3ee; + const count = isLanding ? 7 : 5; + for (let index = 0; index < count; index += 1) { + const direction = index % 2 === 0 ? -1 : 1; + const particle = this.add.circle( + this.player.x + Phaser.Math.Between(-10, 10), + this.player.y + 22, + Phaser.Math.Between(2, 4), + color, + 0.72, + ).setDepth(9); + this.tweens.add({ + targets: particle, + x: particle.x + direction * Phaser.Math.Between(10, 28), + y: particle.y + (isLanding ? Phaser.Math.Between(2, 10) : Phaser.Math.Between(12, 24)), + alpha: 0, + scale: 0.3, + duration: Phaser.Math.Between(220, 360), + ease: "Quad.easeOut", + onComplete: () => particle.destroy(), + }); + } } - buildEntanglementLevel() { - this.spawn = { x: 70, y: 440 }; - this.phase = 0; - this.addPlatform(110, 500, 220, 80); - this.addPlatform(480, 480, 180, 40); - this.addPlatform(850, 500, 220, 80); - this.addPhasePlatform(305, 440, 170, 0); - this.addPhasePlatform(655, 440, 170, 1); - this.add.text(400, 344, "ENTANGLED PAIR", { - color: "#8bdcf3", - fontFamily: "Roboto Mono, monospace", - fontSize: "11px", + createKeyboard() { + this.cursors = this.input.keyboard.createCursorKeys(); + this.keys = this.input.keyboard.addKeys({ + left: Phaser.Input.Keyboard.KeyCodes.A, + right: Phaser.Input.Keyboard.KeyCodes.D, + jump: Phaser.Input.Keyboard.KeyCodes.W, + measure: Phaser.Input.Keyboard.KeyCodes.M, + restart: Phaser.Input.Keyboard.KeyCodes.R, + space: Phaser.Input.Keyboard.KeyCodes.SPACE, }); - this.addGoal(900, 430); - this.applyPhase(); } - levelInstruction() { - if (this.levelIndex === 0) { - return "The detector changes the floor. Keep moving."; + createProgressRail() { + this.add.rectangle(GAME_WIDTH - 22, GAME_HEIGHT / 2, 3, GAME_HEIGHT - 84, 0x5a8099, 0.38) + .setScrollFactor(0) + .setDepth(30); + this.progressMarker = this.add.rectangle(GAME_WIDTH - 22, GAME_HEIGHT - 44, 10, 24, 0x22d3ee, 1) + .setScrollFactor(0) + .setDepth(31); + this.add.text(GAME_WIDTH - 22, 20, "TOP", { + color: "#8ba2b5", + fontFamily: "Roboto Mono, monospace", + fontSize: "8px", + resolution: 2, + }).setOrigin(0.5).setScrollFactor(0).setDepth(31); + } + + configureCamera() { + this.cameras.main.setZoom(RENDER_SCALE); + this.cameras.main.setBounds(0, 0, GAME_WIDTH, WORLD_HEIGHT); + this.cameras.main.startFollow(this.player, true, 0.08, 0.1, 0, 70); + this.cameras.main.setDeadzone(GAME_WIDTH * 0.42, GAME_HEIGHT * 0.34); + this.cameras.main.centerOn(GAME_WIDTH / 2, this.player.y - 90); + } + + handlePlatformContact(player, platform) { + if (platform.getData("kind") !== "crumble" || platform.getData("crumbling")) { + return; } - if (this.levelIndex === 1) { - return "Press M to collapse the bridge into the reachable path."; + if (!(player.body.blocked.down || player.body.touching.down) || player.y > platform.y) { + return; } - return "The bridges are entangled. Cross one, measure, then cross the other."; + + platform.setData("crumbling", true); + platform.setFillStyle(0xff4f78, 0.78); + this.time.delayedCall(900, () => { + this.tweens.add({ + targets: platform, + alpha: 0, + y: platform.y + 28, + duration: 230, + onComplete: () => { + platform.body.enable = false; + }, + }); + }); } - applyPhase() { + applyPhase(flash = true) { this.phasePlatforms.forEach(({ platform, requiredPhase, color }) => { const active = requiredPhase === this.phase; platform.body.enable = active; - platform.setFillStyle(color, active ? 0.9 : 0.12); - platform.setStrokeStyle(active ? 3 : 1, color, active ? 1 : 0.42); + platform.setFillStyle(color, active ? 0.92 : 0.1); + platform.setStrokeStyle(active ? 3 : 1, color, active ? 1 : 0.36); }); - this.cameras.main.flash(90, this.phase ? 139 : 34, this.phase ? 92 : 211, this.phase ? 246 : 238, false); - this.emitState(); + if (flash) { + this.cameras.main.flash(90, this.phase ? 139 : 34, this.phase ? 92 : 211, this.phase ? 246 : 238, false); + } + this.emitState(true); } measure() { - if (this.completed || this.dying || this.levelIndex === 0) { + if (this.completed || this.dying || this.zoneIndex === 0) { return; } this.phase = this.phase === 0 ? 1 : 0; this.applyPhase(); } - triggerDetector() { - if (this.detectorTriggered || !this.collapsePlatform) { - return; + updateZoneAndCheckpoint() { + let nextZone = 0; + if (this.player.y < 1280) { + nextZone = 2; + } else if (this.player.y < 2320) { + nextZone = 1; + } + + if (nextZone > this.checkpointZone) { + this.checkpointZone = nextZone; + this.phase = 0; + this.applyPhase(); + } + if (nextZone !== this.zoneIndex) { + this.zoneIndex = nextZone; + this.emitState(true); } - this.detectorTriggered = true; - this.detectorLine.setFillStyle(0xff4f78, 0.75); - this.tweens.add({ - targets: this.collapsePlatform, - alpha: 0, - y: this.collapsePlatform.y + 24, - duration: 360, - onComplete: () => { - this.collapsePlatform.body.enable = false; - }, - }); } - failLevel() { + failRun() { if (this.dying || this.completed) { return; } this.dying = true; this.deaths += 1; this.player.body.enable = false; - this.player.setFillStyle(0xff4f78, 1); - this.cameras.main.shake(180, 0.012); - this.time.delayedCall(360, () => { - this.scene.restart({ levelIndex: this.levelIndex, deaths: this.deaths, phase: 0 }); + this.player.setTint(0xff4f78); + this.cameras.main.shake(170, 0.012); + this.time.delayedCall(350, () => { + this.scene.restart({ checkpointZone: this.checkpointZone, deaths: this.deaths }); }); } - finishLevel() { + finishRun() { if (this.dying || this.completed) { return; } - this.dying = true; + this.zoneIndex = 2; + this.checkpointZone = 2; + this.completed = true; + this.dying = false; this.player.body.enable = false; - this.cameras.main.flash(180, 34, 211, 238, false); - if (this.levelIndex < LEVEL_NAMES.length - 1) { - this.time.delayedCall(420, () => { - this.scene.restart({ levelIndex: this.levelIndex + 1, deaths: this.deaths, phase: 0 }); + this.physics.pause(); + this.cameras.main.stopFollow(); + this.cameras.main.centerOn(GAME_WIDTH / 2, GAME_HEIGHT / 2); + this.emitState(true); + this.playThunderStrike(() => this.showCompletion()); + } + + playThunderStrike(onComplete) { + const camera = this.cameras.main; + const targetX = this.player.x; + const targetY = this.player.y; + const startY = -80; + + camera.flash(150, 210, 245, 255, false); + camera.shake(320, 0.018); + + [ + { width: 10, color: 0x22d3ee, alpha: 0.18 }, + { width: 5, color: 0x8bdcf3, alpha: 0.72 }, + { width: 2, color: 0xffffff, alpha: 1 }, + ].forEach(({ width, color, alpha }, layer) => { + const bolt = this.add.graphics().setDepth(60 + layer); + bolt.lineStyle(width, color, alpha); + bolt.beginPath(); + bolt.moveTo(targetX + Phaser.Math.Between(-24, 24), startY); + const segments = 9; + for (let index = 1; index < segments; index += 1) { + const progress = index / segments; + const x = Phaser.Math.Linear(targetX, targetX + Phaser.Math.Between(-44, 44), 1 - progress); + bolt.lineTo(x, Phaser.Math.Linear(startY, targetY, progress)); + } + bolt.lineTo(targetX, targetY); + bolt.strokePath(); + this.tweens.add({ + targets: bolt, + alpha: 0, + duration: 320, + delay: layer * 28, + onComplete: () => bolt.destroy(), + }); + }); + + for (let index = 0; index < 12; index += 1) { + const spark = this.add.circle(targetX, targetY, Phaser.Math.Between(2, 5), 0x8bdcf3, 0.9) + .setDepth(64); + const angle = Phaser.Math.FloatBetween(Math.PI, Math.PI * 2); + const distance = Phaser.Math.Between(24, 74); + this.tweens.add({ + targets: spark, + x: targetX + Math.cos(angle) * distance, + y: targetY + Math.sin(angle) * distance, + alpha: 0, + scale: 0.2, + duration: Phaser.Math.Between(260, 430), + onComplete: () => spark.destroy(), }); - return; } - this.completed = true; - this.dying = false; - this.physics.pause(); - this.add.rectangle(GAME_WIDTH / 2, GAME_HEIGHT / 2, 560, 210, 0x071019, 0.96) - .setStrokeStyle(2, 0x22d3ee, 1); - this.add.text(GAME_WIDTH / 2, GAME_HEIGHT / 2 - 42, "EXPERIMENT COMPLETE", { + this.time.delayedCall(360, onComplete); + } + + showCompletion() { + const coherence = Math.max(0, 1000 - this.deaths * 60); + const centerX = this.cameras.main.midPoint.x; + const centerY = this.cameras.main.midPoint.y; + + this.add.rectangle(centerX, centerY, 570, 220, 0x061019, 0.97) + .setStrokeStyle(2, 0x35e0b8, 1) + .setDepth(50); + this.add.text(centerX, centerY - 46, "SUMMIT REACHED", { color: "#f8fafc", fontFamily: "Arial, sans-serif", - fontSize: "30px", + fontSize: "31px", fontStyle: "bold", - }).setOrigin(0.5); - this.add.text(GAME_WIDTH / 2, GAME_HEIGHT / 2 + 15, `Retries: ${this.deaths} · Press R to replay`, { - color: "#8bdcf3", + resolution: 2, + }).setOrigin(0.5).setDepth(51); + this.add.text(centerX, centerY + 15, `Coherence ${coherence} · Retries ${this.deaths}`, { + color: "#8be8d1", fontFamily: "Roboto Mono, monospace", fontSize: "14px", - }).setOrigin(0.5); - this.emitState(); + resolution: 2, + }).setOrigin(0.5).setDepth(51); + this.add.text(centerX, centerY + 55, "Press R to climb again", { + color: "#8ba2b5", + fontFamily: "Roboto Mono, monospace", + fontSize: "11px", + resolution: 2, + }).setOrigin(0.5).setDepth(51); } - emitState() { - this.callbacks.onState?.({ - level: this.levelIndex + 1, - levelName: LEVEL_NAMES[this.levelIndex], + emitState(force = false) { + const playerY = this.player?.y ?? START_Y; + const altitude = Math.max(0, Math.min(100, Math.round(((START_Y - playerY) / (START_Y - 78)) * 100))); + const score = Math.max(0, (this.completed ? 1000 : altitude * 10) - this.deaths * 60); + const state = { + zone: this.zoneIndex + 1, + zoneName: ZONE_NAMES[this.zoneIndex], phase: `|${this.phase}>`, deaths: this.deaths, + altitude, + score, completed: this.completed, - }); + }; + const key = `${state.zone}-${state.phase}-${state.deaths}-${state.altitude}-${state.score}-${state.completed}`; + if (force || key !== this.lastStatusKey) { + this.lastStatusKey = key; + this.callbacks.onState?.(state); + } } receiveInput(action, pressed = true) { @@ -309,14 +638,17 @@ class QuantumDevilScene extends Phaser.Scene { } else if (pressed && action === "measure") { this.measure(); } else if (pressed && action === "restart") { - this.scene.restart({ levelIndex: this.completed ? 0 : this.levelIndex, deaths: this.deaths, phase: 0 }); + this.scene.restart({ + checkpointZone: this.completed ? 0 : this.checkpointZone, + deaths: this.completed ? 0 : this.deaths, + }); } } update() { if (!this.player?.body || this.completed || this.dying) { if (Phaser.Input.Keyboard.JustDown(this.keys?.restart)) { - this.scene.restart({ levelIndex: this.completed ? 0 : this.levelIndex, deaths: this.deaths, phase: 0 }); + this.scene.restart({ checkpointZone: 0, deaths: 0 }); } return; } @@ -326,29 +658,79 @@ class QuantumDevilScene extends Phaser.Scene { if (movingLeft === movingRight) { this.player.body.setAccelerationX(0); } else { - this.player.body.setAccelerationX(movingLeft ? -1200 : 1200); + this.player.body.setAccelerationX(movingLeft ? -1400 : 1400); + this.player.setFlipX(movingLeft); } const grounded = this.player.body.blocked.down || this.player.body.touching.down; const keyboardJump = Phaser.Input.Keyboard.JustDown(this.cursors.up) || Phaser.Input.Keyboard.JustDown(this.keys.jump) || Phaser.Input.Keyboard.JustDown(this.keys.space); - if ((keyboardJump || this.pendingJump) && grounded) { - this.player.body.setVelocityY(-540); + if (grounded) { + this.lastGroundedAt = this.time.now; + } + if (keyboardJump || this.pendingJump) { + this.jumpBufferedUntil = this.time.now + 220; + } + const canUseCoyoteTime = this.time.now - this.lastGroundedAt <= 150; + if (this.jumpBufferedUntil >= this.time.now && canUseCoyoteTime) { + this.player.body.setVelocityY(-620); + this.player.anims.stop(); + this.player.setTexture("qd-mascot-rise"); + this.player.setScale(MASCOT_SCALE * 0.94, MASCOT_SCALE * 1.07); + this.spawnMotionBurst("jump"); + this.jumpBufferedUntil = 0; + this.lastGroundedAt = 0; } this.pendingJump = false; + const justLanded = grounded && !this.wasGrounded && this.previousVelocityY > 180; + if (justLanded) { + this.landingUntil = this.time.now + 115; + this.player.anims.stop(); + this.player.setTexture("qd-mascot-land"); + this.player.setScale(MASCOT_SCALE * 1.08, MASCOT_SCALE * 0.9); + this.spawnMotionBurst("land"); + } + + if (!grounded) { + this.player.anims.stop(); + this.player.setTexture(this.player.body.velocity.y < 80 ? "qd-mascot-rise" : "qd-mascot-fall"); + this.player.setScale( + MASCOT_SCALE * (this.player.body.velocity.y < 80 ? 0.94 : 1), + MASCOT_SCALE * (this.player.body.velocity.y < 80 ? 1.07 : 1.02), + ); + } else if (this.time.now < this.landingUntil) { + this.player.anims.stop(); + this.player.setTexture("qd-mascot-land"); + } else if (Math.abs(this.player.body.velocity.x) > 28) { + this.player.setScale(MASCOT_SCALE); + this.player.play("qd-mascot-run", true); + } else { + this.player.setScale(MASCOT_SCALE); + this.player.play("qd-mascot-idle", true); + } + if (Phaser.Input.Keyboard.JustDown(this.keys.measure)) { this.measure(); } if (Phaser.Input.Keyboard.JustDown(this.keys.restart)) { - this.scene.restart({ levelIndex: this.levelIndex, deaths: this.deaths, phase: 0 }); + this.scene.restart({ checkpointZone: this.checkpointZone, deaths: this.deaths }); } - if (this.levelIndex === 0 && this.player.x > 300) { - this.triggerDetector(); - } - if (this.player.y > GAME_HEIGHT - 4) { - this.failLevel(); + + this.playerGlow.setPosition(this.player.x, this.player.y).setAlpha(grounded ? 0.1 : 0.2); + this.updateZoneAndCheckpoint(); + + const progress = Phaser.Math.Clamp((START_Y - this.player.y) / (START_Y - 78), 0, 1); + this.progressMarker.y = GAME_HEIGHT - 44 - progress * (GAME_HEIGHT - 96); + this.progressMarker.setFillStyle(this.zoneIndex === 2 ? 0x35e0b8 : this.phase ? 0x8b5cf6 : 0x22d3ee, 1); + this.emitState(); + + this.wasGrounded = grounded; + this.previousVelocityY = this.player.body.velocity.y; + + if (this.player.y > this.cameras.main.scrollY + GAME_HEIGHT + 115) { + this.failRun(); } } } @@ -358,14 +740,14 @@ export function createQuantumDevilGame(container, callbacks = {}) { const game = new Phaser.Game({ type: Phaser.AUTO, parent: container, - width: GAME_WIDTH, - height: GAME_HEIGHT, + width: GAME_WIDTH * RENDER_SCALE, + height: GAME_HEIGHT * RENDER_SCALE, transparent: false, - backgroundColor: "#05070b", + backgroundColor: "#03070b", physics: { default: "arcade", arcade: { - gravity: { y: 1000 }, + gravity: { y: 1150 }, debug: false, }, }, @@ -376,6 +758,7 @@ export function createQuantumDevilGame(container, callbacks = {}) { render: { antialias: true, pixelArt: false, + roundPixels: true, }, scene, }); diff --git a/site/src/quantum-devil/quantum-devil.css b/site/src/quantum-devil/quantum-devil.css index 06422c8..1c9fa84 100644 --- a/site/src/quantum-devil/quantum-devil.css +++ b/site/src/quantum-devil/quantum-devil.css @@ -29,7 +29,7 @@ } .qd-dialog { - width: min(1000px, calc(100vw - 32px)); + width: min(900px, calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - 32px); overflow: hidden; @@ -107,7 +107,7 @@ .qd-status { display: grid; - grid-template-columns: auto 1fr auto auto; + grid-template-columns: auto 1fr auto auto auto auto; gap: 18px; align-items: center; border-bottom: 1px solid rgba(255, 255, 255, 0.12); @@ -129,7 +129,7 @@ .qd-viewport { position: relative; width: 100%; - aspect-ratio: 16 / 9; + aspect-ratio: 4 / 3; overflow: hidden; background: #05070b; } @@ -142,6 +142,7 @@ .qd-game-host canvas { display: block; + image-rendering: auto; touch-action: none; } @@ -258,7 +259,8 @@ padding: 9px 12px; } - .qd-status span:last-child { + .qd-status span:nth-of-type(2), + .qd-status span:nth-last-child(-n + 2) { display: none; }