1249 lines
42 KiB
HTML
1249 lines
42 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="fr">
|
||
<head>
|
||
<meta charset="UTF-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||
<title>Spot the Queen</title>
|
||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@700;800;900&display=swap" rel="stylesheet">
|
||
<style>
|
||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||
|
||
body {
|
||
background: #08031a;
|
||
font-family: 'Nunito', system-ui, sans-serif;
|
||
color: #fff;
|
||
overflow: hidden;
|
||
height: 100vh;
|
||
width: 100vw;
|
||
user-select: none;
|
||
}
|
||
|
||
#container { position: relative; width: 100vw; height: 100vh; overflow: hidden; }
|
||
|
||
/* ── Screen shake ── */
|
||
@keyframes shake {
|
||
0%,100% { transform: translate(0,0) rotate(0deg); }
|
||
10% { transform: translate(-12px, 6px) rotate(-1.8deg); }
|
||
22% { transform: translate( 12px,-6px) rotate( 1.8deg); }
|
||
34% { transform: translate(-8px, 4px) rotate(-1.1deg); }
|
||
46% { transform: translate( 8px, -4px) rotate( 1.1deg); }
|
||
58% { transform: translate(-5px, 3px) rotate(-.6deg); }
|
||
70% { transform: translate( 5px, -3px) rotate( .6deg); }
|
||
85% { transform: translate(-2px, 1px) rotate(-.2deg); }
|
||
}
|
||
#container.shake { animation: shake .48s cubic-bezier(.36,.07,.19,.97) both; }
|
||
|
||
/* ── Flash overlay ── */
|
||
#flash {
|
||
position: absolute; inset: 0;
|
||
pointer-events: none; z-index: 28;
|
||
opacity: 0;
|
||
}
|
||
@keyframes doFlash {
|
||
0% { opacity: .6; }
|
||
100% { opacity: 0; }
|
||
}
|
||
#flash.flashing { animation: doFlash .38s ease-out both; }
|
||
|
||
/* ── Canvas ── */
|
||
#game-canvas {
|
||
position: absolute; inset: 0;
|
||
cursor: crosshair; display: none;
|
||
}
|
||
|
||
/* ── Screens ── */
|
||
.screen {
|
||
position: absolute; inset: 0;
|
||
display: flex; flex-direction: column;
|
||
align-items: center; justify-content: center;
|
||
z-index: 30;
|
||
}
|
||
|
||
#start-screen, #end-screen {
|
||
background: radial-gradient(ellipse at 50% 38%, #1c0a48 0%, #08031a 100%);
|
||
}
|
||
|
||
@keyframes titleFloat {
|
||
0% { transform: translateY(0) scale(1); text-shadow: 0 0 40px rgba(255,214,0,.55), 0 3px 0 #7a4800, 0 0 100px rgba(255,120,0,.25); }
|
||
40% { transform: translateY(-8px) scale(1.04); text-shadow: 0 0 60px rgba(255,214,0,.75), 0 3px 0 #7a4800, 0 0 140px rgba(255,120,0,.40); }
|
||
100% { transform: translateY(0) scale(1); text-shadow: 0 0 40px rgba(255,214,0,.55), 0 3px 0 #7a4800, 0 0 100px rgba(255,120,0,.25); }
|
||
}
|
||
.title {
|
||
font-size: clamp(2.8rem, 7vw, 5rem);
|
||
font-weight: 900;
|
||
color: #FFD600;
|
||
text-shadow: 0 0 40px rgba(255,214,0,.55), 0 3px 0 #7a4800, 0 0 100px rgba(255,120,0,.25);
|
||
letter-spacing: .04em;
|
||
margin-bottom: .5rem;
|
||
animation: titleFloat 3.2s ease-in-out infinite;
|
||
display: inline-block;
|
||
}
|
||
|
||
.tagline {
|
||
color: #9070a0;
|
||
font-size: 1rem;
|
||
font-weight: 700;
|
||
text-align: center;
|
||
max-width: 440px;
|
||
line-height: 1.9;
|
||
margin-bottom: 2.5rem;
|
||
}
|
||
|
||
.btn {
|
||
background: linear-gradient(150deg, #FFD600, #ff8c00);
|
||
color: #1a0800;
|
||
border: none;
|
||
padding: .9rem 3.2rem;
|
||
font-size: 1.2rem;
|
||
font-family: inherit;
|
||
font-weight: 900;
|
||
border-radius: 99px;
|
||
cursor: pointer;
|
||
box-shadow: 0 4px 28px rgba(255,180,0,.55), 0 1px 0 rgba(255,255,255,.3) inset;
|
||
transition: transform .12s, box-shadow .12s;
|
||
letter-spacing: .02em;
|
||
}
|
||
.btn:hover { transform: translateY(-3px) scale(1.05); box-shadow: 0 8px 36px rgba(255,180,0,.75), 0 1px 0 rgba(255,255,255,.3) inset; }
|
||
.btn:active { transform: translateY(0) scale(.97); }
|
||
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none !important; box-shadow: none; }
|
||
|
||
/* ── HUD ── */
|
||
#hud {
|
||
position: absolute; top: 0; left: 0; right: 0;
|
||
padding: 8px 18px;
|
||
display: none; align-items: center; gap: 14px;
|
||
background: linear-gradient(to bottom, rgba(0,0,0,.72) 0%, transparent 100%);
|
||
pointer-events: none; z-index: 10;
|
||
}
|
||
|
||
.hud-chip {
|
||
background: rgba(0,0,0,.55);
|
||
border: 1.5px solid rgba(255,214,0,.18);
|
||
border-radius: 99px;
|
||
padding: 3px 14px 4px;
|
||
display: flex; flex-direction: column;
|
||
align-items: center;
|
||
}
|
||
.hud-lbl { font-size: .58rem; color: #ffa000; letter-spacing: .12em; text-transform: uppercase; font-weight: 900; }
|
||
.hud-val { font-size: .95rem; color: #ffe066; font-weight: 900; line-height: 1.25; }
|
||
|
||
#lives-row { display: flex; gap: 3px; }
|
||
.life { font-size: 1.2rem; transition: opacity .3s, filter .3s, transform .3s; }
|
||
.life.lost { opacity: .15; filter: grayscale(1); transform: scale(.65); }
|
||
|
||
@keyframes lifePop {
|
||
0% { transform: scale(1.7) rotate(-20deg); filter: brightness(2); }
|
||
45% { transform: scale(.75) rotate(12deg); }
|
||
100% { transform: scale(.65) rotate(0deg); }
|
||
}
|
||
.life.popping { animation: lifePop .38s ease-out forwards; }
|
||
|
||
#timer-wrap { flex: 1; display: flex; align-items: center; gap: 10px; }
|
||
#timer-track {
|
||
flex: 1; height: 8px;
|
||
background: rgba(255,255,255,.1);
|
||
border-radius: 99px; overflow: hidden;
|
||
}
|
||
#timer-fill { height: 100%; background: #FFD600; border-radius: 99px; transition: background .35s; }
|
||
#timer-num { font-size: .95rem; color: #ffe066; font-weight: 900; min-width: 28px; text-align: right; transition: color .35s; }
|
||
|
||
@keyframes timerPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.3); } }
|
||
@keyframes timerBarBlink { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
|
||
#timer-num.warn { color: #FF2255; animation: timerPulse .55s ease-in-out infinite; }
|
||
#timer-num.urgent { color: #FF2255; animation: timerPulse .28s ease-in-out infinite; }
|
||
#timer-fill.urgent { animation: timerBarBlink .28s ease-in-out infinite; }
|
||
#timer-wrap.urgent { filter: drop-shadow(0 0 10px rgba(255,34,85,.75)); }
|
||
|
||
/* ── No-Queen button ── */
|
||
#no-queen-btn {
|
||
position: absolute; bottom: 22px; left: 50%;
|
||
transform: translateX(-50%);
|
||
background: rgba(8,3,26,.88);
|
||
color: #FFD600;
|
||
border: 2px solid #FFD600;
|
||
padding: .7rem 2.6rem;
|
||
font-size: .95rem;
|
||
font-family: inherit; font-weight: 900;
|
||
border-radius: 99px;
|
||
cursor: pointer; z-index: 10; display: none;
|
||
box-shadow: 0 2px 14px rgba(255,214,0,.2);
|
||
transition: background .16s, transform .12s, box-shadow .12s;
|
||
}
|
||
#no-queen-btn:hover {
|
||
background: rgba(255,214,0,.14);
|
||
transform: translateX(-50%) translateY(-3px);
|
||
box-shadow: 0 6px 24px rgba(255,214,0,.45);
|
||
}
|
||
|
||
/* ── Feedback overlay ── */
|
||
#feedback {
|
||
position: absolute; inset: 0;
|
||
display: flex; align-items: center; justify-content: center;
|
||
z-index: 20; pointer-events: none;
|
||
opacity: 0; transition: opacity .14s;
|
||
}
|
||
#feedback.visible { opacity: 1; }
|
||
|
||
.fb-card {
|
||
padding: 2.2rem 4rem;
|
||
border-radius: 22px;
|
||
text-align: center;
|
||
}
|
||
.fb-card.ok {
|
||
background: linear-gradient(155deg, #00b84a, #007a2e);
|
||
border: 3px solid #00ff88;
|
||
box-shadow: 0 10px 50px rgba(0,0,0,.55), 0 0 70px rgba(0,255,100,.2);
|
||
}
|
||
.fb-card.bad {
|
||
background: linear-gradient(155deg, #e8303a, #a81020);
|
||
border: 3px solid #ff4455;
|
||
box-shadow: 0 10px 50px rgba(0,0,0,.55), 0 0 70px rgba(255,50,60,.2);
|
||
}
|
||
|
||
@keyframes fbBounce {
|
||
0% { transform: scale(.35) translateY(50px); opacity: 0; }
|
||
55% { transform: scale(1.1) translateY(-10px); opacity: 1; }
|
||
75% { transform: scale(.95) translateY(3px); }
|
||
100% { transform: scale(1) translateY(0); }
|
||
}
|
||
.fb-card.animate { animation: fbBounce .42s cubic-bezier(.18,1.2,.4,1) both; }
|
||
|
||
.fb-icon { font-size: 4.5rem; display: block; line-height: 1; }
|
||
.fb-title { font-size: 2rem; font-weight: 900; color: #fff; margin-top: .35rem; letter-spacing: .01em; }
|
||
.fb-sub { font-size: 1rem; color: rgba(255,255,255,.85); margin-top: .3rem; font-weight: 700; }
|
||
|
||
/* ── Floating text (score pop / miss) ── */
|
||
@keyframes floatUp {
|
||
0% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
|
||
18% { opacity: 1; transform: translateX(-50%) translateY(-14px) scale(1.18); }
|
||
100% { opacity: 0; transform: translateX(-50%) translateY(-100px) scale(.85); }
|
||
}
|
||
.float-txt {
|
||
position: absolute; pointer-events: none; z-index: 26;
|
||
font-family: inherit; font-weight: 900; font-size: 1.9rem;
|
||
transform: translateX(-50%);
|
||
animation: floatUp 1.1s ease-out both;
|
||
text-shadow: 0 2px 12px rgba(0,0,0,.6);
|
||
}
|
||
.float-txt.good { color: #FFD600; text-shadow: 0 2px 12px rgba(0,0,0,.5), 0 0 24px rgba(255,214,0,.5); }
|
||
.float-txt.bad { color: #FF4455; text-shadow: 0 2px 12px rgba(0,0,0,.5), 0 0 24px rgba(255,60,70,.5); }
|
||
|
||
/* ── Bee showcase (start screen) ── */
|
||
#bee-showcase {
|
||
display: flex; gap: 14px;
|
||
margin-bottom: 1rem;
|
||
}
|
||
.bee-card {
|
||
background: rgba(0,0,0,.45);
|
||
border: 1.5px solid rgba(255,214,0,.14);
|
||
border-radius: 14px;
|
||
padding: 12px 20px 10px;
|
||
display: flex; flex-direction: column;
|
||
align-items: center; gap: 5px;
|
||
min-width: 96px;
|
||
}
|
||
.bee-card.queen-card {
|
||
border-color: rgba(255,214,0,.5);
|
||
background: rgba(255,180,0,.07);
|
||
}
|
||
.bee-card img {
|
||
height: 56px; width: auto;
|
||
object-fit: contain;
|
||
image-rendering: crisp-edges;
|
||
}
|
||
.bee-card-name { font-size: .82rem; font-weight: 900; color: #ffe066; }
|
||
.bee-card-pct { font-size: .7rem; font-weight: 700; color: #705030; }
|
||
|
||
.no-queen-note {
|
||
font-size: .78rem; font-weight: 700; color: #706050;
|
||
text-align: center; max-width: 430px;
|
||
padding: 8px 16px;
|
||
background: rgba(255,200,0,.05);
|
||
border: 1px solid rgba(255,200,0,.1);
|
||
border-radius: 8px;
|
||
margin-bottom: 1.8rem;
|
||
line-height: 1.6;
|
||
}
|
||
.no-queen-note em { color: #c09060; font-style: normal; }
|
||
.no-queen-note strong { color: #ffd060; }
|
||
|
||
/* ── Difficulty selector ── */
|
||
#difficulty-select {
|
||
display: flex; flex-direction: column;
|
||
align-items: center; gap: 7px;
|
||
margin-bottom: 1.2rem;
|
||
}
|
||
.diff-label {
|
||
font-size: .62rem; color: #906040; letter-spacing: .22em;
|
||
text-transform: uppercase; font-weight: 900;
|
||
}
|
||
.diff-options { display: flex; gap: 10px; }
|
||
.diff-btn {
|
||
background: rgba(0,0,0,.4);
|
||
border: 2px solid rgba(255,214,0,.18);
|
||
color: #c09060;
|
||
padding: .48rem 1.4rem;
|
||
font-family: inherit; font-size: .82rem; font-weight: 900;
|
||
border-radius: 12px; cursor: pointer;
|
||
transition: border-color .15s, background .15s, color .15s;
|
||
text-align: center; line-height: 1.5;
|
||
}
|
||
.diff-btn small { display: block; font-size: .68rem; font-weight: 700; color: #604030; }
|
||
.diff-btn.active {
|
||
border-color: #FFD600;
|
||
background: rgba(255,214,0,.1);
|
||
color: #ffe066;
|
||
}
|
||
.diff-btn.active small { color: #b08050; }
|
||
.diff-btn:hover:not(.active) {
|
||
border-color: rgba(255,214,0,.4);
|
||
background: rgba(255,214,0,.05);
|
||
color: #d0a070;
|
||
}
|
||
|
||
/* ── End screen ── */
|
||
#end-screen { gap: 0; display: none; }
|
||
.end-lbl { font-size: .78rem; color: #ffa000; letter-spacing: .22em; text-transform: uppercase; font-weight: 900; }
|
||
.end-score {
|
||
font-size: clamp(4.5rem, 11vw, 8rem); font-weight: 900;
|
||
color: #FFD600;
|
||
text-shadow: 0 0 60px rgba(255,214,0,.6), 0 3px 0 #7a4800;
|
||
line-height: 1; margin: .3rem 0;
|
||
}
|
||
.end-pts { font-size: .95rem; color: #a07050; font-weight: 800; margin-bottom: 1.6rem; }
|
||
.end-details { color: #806050; font-size: .9rem; font-weight: 700; text-align: center; line-height: 2.2; margin-bottom: 2rem; }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div id="container">
|
||
|
||
<div id="flash"></div>
|
||
<canvas id="game-canvas"></canvas>
|
||
|
||
<div id="hud">
|
||
<div class="hud-chip">
|
||
<span class="hud-lbl">Cadre</span>
|
||
<span class="hud-val" id="h-frame">1 / 10</span>
|
||
</div>
|
||
<div class="hud-chip">
|
||
<span class="hud-lbl">Vies</span>
|
||
<div id="lives-row">
|
||
<span class="life" id="l0">🐝</span>
|
||
<span class="life" id="l1">🐝</span>
|
||
<span class="life" id="l2">🐝</span>
|
||
</div>
|
||
</div>
|
||
<div id="timer-wrap">
|
||
<div id="timer-track"><div id="timer-fill"></div></div>
|
||
<span id="timer-num">30</span>
|
||
</div>
|
||
<div class="hud-chip">
|
||
<span class="hud-lbl">Score</span>
|
||
<span class="hud-val" id="h-score">0</span>
|
||
</div>
|
||
</div>
|
||
|
||
<button id="no-queen-btn">Pas de Reine</button>
|
||
|
||
<div id="feedback">
|
||
<div class="fb-card" id="fb-card">
|
||
<span class="fb-icon" id="fb-icon"></span>
|
||
<div class="fb-title" id="fb-title"></div>
|
||
<div class="fb-sub" id="fb-sub"></div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="screen" id="start-screen">
|
||
<div class="title">Spot the Queen</div>
|
||
<div class="tagline">
|
||
Trouvez la Reine parmi des centaines d'abeilles.<br>
|
||
10 cadres · 30 secondes · 3 essais par cadre
|
||
</div>
|
||
|
||
<div id="bee-showcase">
|
||
<div class="bee-card">
|
||
<img id="bee-worker-preview" alt="ouvrière" />
|
||
<div class="bee-card-name">Ouvrière</div>
|
||
<div class="bee-card-pct">≈ 90 %</div>
|
||
</div>
|
||
<div class="bee-card">
|
||
<img id="bee-drone-preview" alt="mâle" />
|
||
<div class="bee-card-name">Mâle</div>
|
||
<div class="bee-card-pct">≈ 10 %</div>
|
||
</div>
|
||
<div class="bee-card queen-card">
|
||
<img id="bee-queen-preview" alt="reine" />
|
||
<div class="bee-card-name">♛ La Reine</div>
|
||
<div class="bee-card-pct">À trouver !</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="difficulty-select">
|
||
<div class="diff-label">Difficulté</div>
|
||
<div class="diff-options">
|
||
<button class="diff-btn" data-mode="easy">Facile<small>Reine marquée ●</small></button>
|
||
<button class="diff-btn active" data-mode="normal">Normal<small>Reine non marquée</small></button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="no-queen-note">
|
||
⚠ Dans certains cadres, il n'y a <em>aucune Reine</em>.
|
||
Utilisez <strong>Pas de Reine</strong> si vous en êtes certain·e.
|
||
</div>
|
||
|
||
<button class="btn" id="start-btn">Commencer</button>
|
||
</div>
|
||
|
||
<div class="screen" id="end-screen">
|
||
<div class="end-lbl">Partie terminée</div>
|
||
<div class="end-score" id="end-score">0</div>
|
||
<div class="end-pts">points</div>
|
||
<div class="end-details" id="end-details"></div>
|
||
<button class="btn" id="replay-btn">Rejouer</button>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<script>
|
||
'use strict';
|
||
|
||
// ─────────────────────────────────────────────────────
|
||
// Config
|
||
// ─────────────────────────────────────────────────────
|
||
const CFG = {
|
||
NUM_BEES_MIN: 500, // abeilles au 1er cadre
|
||
NUM_BEES_MAX: 2500, // abeilles au dernier cadre (progression linéaire)
|
||
BEE_SPEED: 0.35, // multiplicateur global de vitesse (1.0 = vitesse d'origine)
|
||
BEE_SCALE: 0.20, // taille des abeilles (1.0 = taille d'origine)
|
||
|
||
// Chemins vers les PNG des individus. null = placeholder canvas.
|
||
// Exemple : IMAGES: { worker: 'assets/worker.png', drone: 'assets/drone.png', queen: 'assets/queen.png' }
|
||
IMAGES: {
|
||
worker: "https://flusin.ovh/spot-the-queen/ouvriere.png",
|
||
drone: "https://flusin.ovh/spot-the-queen/male.png",
|
||
queen: "https://flusin.ovh/spot-the-queen/reine.png",
|
||
},
|
||
|
||
// Rotation à appliquer aux PNG pour qu'ils pointent vers la droite (+X), axe du déplacement.
|
||
// 90 = PNG tête en haut (ton cas)
|
||
// 0 = PNG tête à droite (pas de correction nécessaire)
|
||
// -90 = PNG tête en bas
|
||
// 180 = PNG tête à gauche
|
||
IMAGE_ROTATION: 90,
|
||
|
||
SOUNDS: {
|
||
enabled: true,
|
||
ambientVolume: 0.12, // volume musique d'ambiance (0–1)
|
||
sfxVolume: 0.55, // volume effets sonores (0–1)
|
||
// Chemins vers les fichiers audio. null = son généré par synthèse Web Audio.
|
||
// ex: ambient: 'assets/ambient.mp3'
|
||
startScreen: "https://flusin.ovh/spot-the-queen/home.mp3", // musique écran d'accueil (pas de placeholder généré)
|
||
ambient: "https://flusin.ovh/spot-the-queen/ambiant.mp3",
|
||
success: null,
|
||
failure: null,
|
||
},
|
||
|
||
QUEEN_PROB: 0.90,
|
||
LIVES: 3,
|
||
FRAME_SECS: 30,
|
||
NUM_FRAMES: 10,
|
||
HIT_RADIUS: 46,
|
||
FEEDBACK_MS: 1700,
|
||
};
|
||
|
||
// ─────────────────────────────────────────────────────
|
||
// Difficulty
|
||
// ─────────────────────────────────────────────────────
|
||
let easyMode = false;
|
||
const DOT_COLORS = ['#ffffff', '#ff2020', '#ffd600', '#00ee55', '#2090ff'];
|
||
|
||
// ─────────────────────────────────────────────────────
|
||
// Canvas & context
|
||
// ─────────────────────────────────────────────────────
|
||
const canvas = document.getElementById('game-canvas');
|
||
const ctx = canvas.getContext('2d');
|
||
|
||
// ─────────────────────────────────────────────────────
|
||
// Background — honeycomb drawn once to offscreen canvas
|
||
// ─────────────────────────────────────────────────────
|
||
let bgImg = null;
|
||
|
||
function resizeCanvas() {
|
||
canvas.width = window.innerWidth;
|
||
canvas.height = window.innerHeight;
|
||
buildBackground();
|
||
}
|
||
|
||
window.addEventListener('resize', resizeCanvas);
|
||
resizeCanvas();
|
||
|
||
function buildBackground() {
|
||
const oc = document.createElement('canvas');
|
||
oc.width = canvas.width; oc.height = canvas.height;
|
||
const bc = oc.getContext('2d');
|
||
|
||
bc.fillStyle = '#1e0d00';
|
||
bc.fillRect(0, 0, oc.width, oc.height);
|
||
|
||
const R = 26;
|
||
const colW = R * Math.sqrt(3);
|
||
const rowH = R * 1.5;
|
||
const cols = Math.ceil(oc.width / colW) + 2;
|
||
const rows = Math.ceil(oc.height / rowH) + 2;
|
||
const PAL = ['#271100','#2f1500','#251000','#2d1400'];
|
||
const rng = mulberry32(0xdeadbeef);
|
||
|
||
for (let r = -1; r < rows; r++) {
|
||
for (let c = -1; c < cols; c++) {
|
||
const cx = c * colW + (r % 2 === 0 ? 0 : colW * .5);
|
||
const cy = r * rowH;
|
||
bc.beginPath();
|
||
for (let i = 0; i < 6; i++) {
|
||
const a = (Math.PI / 3) * i;
|
||
const px = cx + R * Math.cos(a);
|
||
const py = cy + R * Math.sin(a);
|
||
i === 0 ? bc.moveTo(px, py) : bc.lineTo(px, py);
|
||
}
|
||
bc.closePath();
|
||
bc.fillStyle = PAL[(rng() * PAL.length) | 0];
|
||
bc.fill();
|
||
bc.strokeStyle = 'rgba(0,0,0,.55)';
|
||
bc.lineWidth = 1.2;
|
||
bc.stroke();
|
||
}
|
||
}
|
||
bgImg = oc;
|
||
}
|
||
|
||
function mulberry32(seed) {
|
||
return function () {
|
||
seed |= 0; seed = seed + 0x6D2B79F5 | 0;
|
||
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
|
||
t = t + Math.imul(t ^ (t >>> 7), 61 | t) ^ t;
|
||
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
||
};
|
||
}
|
||
|
||
// ─────────────────────────────────────────────────────
|
||
// Sprite pre-rendering (drawImage is much faster than paths/frame)
|
||
// ─────────────────────────────────────────────────────
|
||
const SPR = {};
|
||
|
||
// scale optionnel : CFG.BEE_SCALE par défaut, mais 4.0 pour les previews UI
|
||
function makeSprite(type, scale = CFG.BEE_SCALE) {
|
||
const specs = {
|
||
worker: { w:24, h:13, bx:13, by:6.5, rx:9, ry:4.8, fill:'#d4a010', stripes:3, headR:2.8, wingA:.42 },
|
||
drone: { w:28, h:16, bx:15, by:8, rx:11, ry:6.5, fill:'#7a4c10', stripes:2, headR:3.8, wingA:.38 },
|
||
queen: { w:38, h:14, bx:20, by:7, rx:16, ry:5.2, fill:'#e07814', stripes:4, headR:3.2, wingA:.52 },
|
||
};
|
||
const s = specs[type];
|
||
const sc = scale;
|
||
const oc = document.createElement('canvas');
|
||
oc.width = Math.ceil(s.w * sc);
|
||
oc.height = Math.ceil(s.h * sc);
|
||
const c = oc.getContext('2d');
|
||
c.scale(sc, sc);
|
||
|
||
// Wings (behind body)
|
||
c.fillStyle = `rgba(210,238,255,${s.wingA})`;
|
||
c.beginPath(); c.ellipse(s.bx - 3, s.by - 3, s.rx * .6, 3.8, -.22, 0, Math.PI*2); c.fill();
|
||
c.beginPath(); c.ellipse(s.bx + 3, s.by - 3, s.rx * .6, 3.8, .22, 0, Math.PI*2); c.fill();
|
||
|
||
// Body
|
||
c.fillStyle = s.fill;
|
||
c.beginPath(); c.ellipse(s.bx, s.by, s.rx, s.ry, 0, 0, Math.PI*2); c.fill();
|
||
|
||
// Stripes
|
||
c.fillStyle = 'rgba(18,7,0,.82)';
|
||
const spc = (s.rx * 1.3) / (s.stripes + 1);
|
||
for (let i = 1; i <= s.stripes; i++) {
|
||
const sx = s.bx - s.rx * .65 + i * spc;
|
||
const hh = s.ry * Math.sqrt(Math.max(0, 1 - ((sx - s.bx) / s.rx) ** 2));
|
||
c.fillRect(sx - 1, s.by - hh, 2, hh * 2);
|
||
}
|
||
|
||
// Head
|
||
c.fillStyle = '#180700';
|
||
c.beginPath(); c.arc(s.headR + 1, s.by, s.headR, 0, Math.PI*2); c.fill();
|
||
|
||
// Queen crown dot
|
||
if (type === 'queen') {
|
||
c.fillStyle = '#ffe040';
|
||
c.beginPath(); c.arc(s.bx, s.by, 3.8, 0, Math.PI*2); c.fill();
|
||
}
|
||
|
||
return oc;
|
||
}
|
||
|
||
function loadSprites(onReady) {
|
||
const types = ['worker', 'drone', 'queen'];
|
||
let pending = types.length;
|
||
const done = () => { if (--pending === 0) onReady(); };
|
||
|
||
types.forEach(type => {
|
||
const path = CFG.IMAGES[type];
|
||
if (path) {
|
||
const img = new Image();
|
||
img.onload = () => {
|
||
const sc = CFG.BEE_SCALE;
|
||
const rad = CFG.IMAGE_ROTATION * (Math.PI / 180);
|
||
const swap = Math.abs(Math.round(CFG.IMAGE_ROTATION) % 180) === 90;
|
||
const srcW = img.naturalWidth, srcH = img.naturalHeight;
|
||
// Pour ±90°, largeur et hauteur s'échangent
|
||
const dstW = Math.ceil((swap ? srcH : srcW) * sc);
|
||
const dstH = Math.ceil((swap ? srcW : srcH) * sc);
|
||
const oc = document.createElement('canvas');
|
||
oc.width = dstW;
|
||
oc.height = dstH;
|
||
const c = oc.getContext('2d');
|
||
c.translate(dstW / 2, dstH / 2);
|
||
c.rotate(rad);
|
||
c.scale(sc, sc);
|
||
c.drawImage(img, -srcW / 2, -srcH / 2);
|
||
SPR[type] = oc;
|
||
done();
|
||
};
|
||
img.onerror = () => {
|
||
console.warn(`[STQ] PNG introuvable : "${path}" → placeholder utilisé pour "${type}".`);
|
||
SPR[type] = makeSprite(type);
|
||
done();
|
||
};
|
||
img.src = path;
|
||
} else {
|
||
SPR[type] = makeSprite(type);
|
||
done();
|
||
}
|
||
});
|
||
}
|
||
|
||
// Désactive "Commencer" pendant le chargement (quasi-instantané en local)
|
||
document.getElementById('start-btn').disabled = true;
|
||
loadSprites(() => {
|
||
document.getElementById('start-btn').disabled = false;
|
||
_populateBeeShowcase();
|
||
});
|
||
|
||
function _populateBeeShowcase() {
|
||
['worker', 'drone', 'queen'].forEach(type => {
|
||
const el = document.getElementById(`bee-${type}-preview`);
|
||
if (!el) return;
|
||
if (CFG.IMAGES[type]) {
|
||
// PNG fourni : affichage direct avec rotation CSS
|
||
el.src = CFG.IMAGES[type];
|
||
el.style.transform = `rotate(${CFG.IMAGE_ROTATION}deg)`;
|
||
} else {
|
||
// Placeholder : re-render à échelle lisible (4×) pour la vitrine
|
||
el.src = makeSprite(type, 4.0).toDataURL();
|
||
}
|
||
});
|
||
}
|
||
|
||
// ─────────────────────────────────────────────────────
|
||
// Bee
|
||
// ─────────────────────────────────────────────────────
|
||
class Bee {
|
||
constructor(x, y, type, layer) {
|
||
this.x = x; this.y = y;
|
||
this.type = type;
|
||
this.layer = layer;
|
||
this.dotColor = type === 'queen' ? DOT_COLORS[(Math.random() * DOT_COLORS.length) | 0] : null;
|
||
|
||
const BASE = { worker: 1.3, drone: 1.0, queen: 0.6 };
|
||
this.spd = BASE[type] * (.65 + Math.random() * .7) * CFG.BEE_SPEED;
|
||
this.ang = Math.random() * Math.PI * 2;
|
||
this.vx = Math.cos(this.ang) * this.spd;
|
||
this.vy = Math.sin(this.ang) * this.spd;
|
||
this.rot = this.ang;
|
||
this.tick = (Math.random() * 90) | 0;
|
||
this.next = 55 + (Math.random() * 85) | 0;
|
||
}
|
||
|
||
update(W, H) {
|
||
if (++this.tick >= this.next) {
|
||
this.tick = 0;
|
||
this.next = 55 + (Math.random() * 85) | 0;
|
||
this.ang += (Math.random() - .5) * Math.PI * 1.6;
|
||
this.vx = Math.cos(this.ang) * this.spd;
|
||
this.vy = Math.sin(this.ang) * this.spd;
|
||
}
|
||
// micro-jitter
|
||
this.vx += (Math.random() - .5) * .055;
|
||
this.vy += (Math.random() - .5) * .055;
|
||
// speed cap
|
||
const s = Math.hypot(this.vx, this.vy);
|
||
if (s > this.spd * 1.6) { this.vx *= this.spd / s; this.vy *= this.spd / s; }
|
||
|
||
this.x += this.vx;
|
||
this.y += this.vy;
|
||
|
||
// Bounce off safe zone (inside HUD top + button bottom)
|
||
const MX = 38, MY = 72, MB = H - 88;
|
||
if (this.x < MX) { this.vx = Math.abs(this.vx); this.ang = Math.atan2(this.vy, this.vx); }
|
||
if (this.x > W - MX) { this.vx = -Math.abs(this.vx); this.ang = Math.atan2(this.vy, this.vx); }
|
||
if (this.y < MY) { this.vy = Math.abs(this.vy); this.ang = Math.atan2(this.vy, this.vx); }
|
||
if (this.y > MB) { this.vy = -Math.abs(this.vy); this.ang = Math.atan2(this.vy, this.vx); }
|
||
|
||
// Smooth visual rotation
|
||
let dA = Math.atan2(this.vy, this.vx) - this.rot;
|
||
if (dA > Math.PI) dA -= Math.PI * 2;
|
||
if (dA < -Math.PI) dA += Math.PI * 2;
|
||
this.rot += dA * .1;
|
||
}
|
||
|
||
draw() {
|
||
const sp = SPR[this.type];
|
||
ctx.save();
|
||
ctx.translate(this.x, this.y);
|
||
ctx.rotate(this.rot);
|
||
ctx.drawImage(sp, -sp.width * .5, -sp.height * .5);
|
||
if (easyMode && this.dotColor) {
|
||
// PNG sprites (IMAGE_ROTATION=90): head faces +X. Placeholder: head faces -X.
|
||
// 30% from head in original portrait image = sp.width*0.20 from center after 90° rotation.
|
||
const hx = CFG.IMAGES.queen ? sp.width * 0.20 : -sp.width * 0.20;
|
||
ctx.beginPath(); ctx.arc(hx, 0, 3, 0, Math.PI * 2);
|
||
ctx.fillStyle = this.dotColor; ctx.fill();
|
||
ctx.strokeStyle = this.dotColor; ctx.lineWidth = 1.5; ctx.stroke();
|
||
}
|
||
ctx.restore();
|
||
}
|
||
}
|
||
|
||
// ─────────────────────────────────────────────────────
|
||
// Game state & logic
|
||
// ─────────────────────────────────────────────────────
|
||
const G = (() => {
|
||
|
||
// state
|
||
let bees = [], queen = null, hasQueen = false;
|
||
let lives = 3, score = 0, frameIdx = 0, results = [];
|
||
let timeLeft = CFG.FRAME_SECS;
|
||
let locked = false;
|
||
let rafBees = null, rafTimer = null, timerLast = 0;
|
||
let reveal = null; // {x,y} — shows ring around queen when revealed
|
||
|
||
// ── Effects ──
|
||
const elContainer = document.getElementById('container');
|
||
const elFlash = document.getElementById('flash');
|
||
|
||
function screenShake() {
|
||
elContainer.classList.remove('shake');
|
||
void elContainer.offsetWidth;
|
||
elContainer.classList.add('shake');
|
||
}
|
||
|
||
function screenFlash(color) {
|
||
elFlash.style.background = color;
|
||
elFlash.classList.remove('flashing');
|
||
void elFlash.offsetWidth;
|
||
elFlash.classList.add('flashing');
|
||
}
|
||
|
||
function floatTxt(text, x, y, good) {
|
||
const el = document.createElement('div');
|
||
el.className = 'float-txt ' + (good ? 'good' : 'bad');
|
||
el.textContent = text;
|
||
el.style.left = x + 'px';
|
||
el.style.top = y + 'px';
|
||
elContainer.appendChild(el);
|
||
el.addEventListener('animationend', () => el.remove());
|
||
}
|
||
|
||
function animLifeLost(idx) {
|
||
const el = document.getElementById(`l${idx}`);
|
||
el.classList.remove('popping');
|
||
void el.offsetWidth;
|
||
el.classList.add('popping');
|
||
}
|
||
|
||
// ── DOM refs ──
|
||
const elHUD = document.getElementById('hud');
|
||
const elNoQ = document.getElementById('no-queen-btn');
|
||
const elStart = document.getElementById('start-screen');
|
||
const elEnd = document.getElementById('end-screen');
|
||
const elFB = document.getElementById('feedback');
|
||
const elCard = document.getElementById('fb-card');
|
||
const elFrame = document.getElementById('h-frame');
|
||
const elScore = document.getElementById('h-score');
|
||
const elTimerF = document.getElementById('timer-fill');
|
||
const elTimerN = document.getElementById('timer-num');
|
||
const elTimerW = document.getElementById('timer-wrap');
|
||
|
||
// ── Screen helpers ──
|
||
function enterGame() {
|
||
elStart.style.display = 'none';
|
||
elEnd.style.display = 'none';
|
||
elHUD.style.display = 'flex';
|
||
elNoQ.style.display = 'block';
|
||
canvas.style.display = 'block';
|
||
}
|
||
|
||
function exitGame(toScreen) {
|
||
elHUD.style.display = 'none';
|
||
elNoQ.style.display = 'none';
|
||
toScreen.style.display = 'flex';
|
||
}
|
||
|
||
// ── HUD ──
|
||
function hudUpdate() {
|
||
elFrame.textContent = `${frameIdx + 1} / ${CFG.NUM_FRAMES}`;
|
||
elScore.textContent = score;
|
||
for (let i = 0; i < 3; i++)
|
||
document.getElementById(`l${i}`).classList.toggle('lost', i >= lives);
|
||
}
|
||
|
||
function timerUI() {
|
||
const pct = timeLeft / CFG.FRAME_SECS;
|
||
const warn = timeLeft <= 10;
|
||
const urgent = timeLeft <= 5;
|
||
elTimerF.style.width = (pct * 100) + '%';
|
||
elTimerF.style.background = urgent ? '#FF2255' : warn ? '#ffaa00' : '#FFD600';
|
||
elTimerN.textContent = Math.ceil(timeLeft);
|
||
elTimerN.classList.toggle('warn', warn && !urgent);
|
||
elTimerN.classList.toggle('urgent', urgent);
|
||
elTimerF.classList.toggle('urgent', urgent);
|
||
elTimerW.classList.toggle('urgent', urgent);
|
||
}
|
||
|
||
// ── Bees ──
|
||
function spawnBees() {
|
||
bees = []; queen = null;
|
||
hasQueen = Math.random() < CFG.QUEEN_PROB;
|
||
const W = canvas.width, H = canvas.height;
|
||
const t = CFG.NUM_FRAMES > 1 ? frameIdx / (CFG.NUM_FRAMES - 1) : 1;
|
||
const numBees = Math.round(CFG.NUM_BEES_MIN + (CFG.NUM_BEES_MAX - CFG.NUM_BEES_MIN) * t);
|
||
|
||
for (let i = 0; i < numBees; i++) {
|
||
const type = Math.random() < .9 ? 'worker' : 'drone';
|
||
const layer = (Math.random() * 2) | 0;
|
||
bees.push(new Bee(
|
||
60 + Math.random() * (W - 120),
|
||
90 + Math.random() * (H - 210),
|
||
type, layer
|
||
));
|
||
}
|
||
|
||
if (hasQueen) {
|
||
const layer = (Math.random() * 2) | 0;
|
||
queen = new Bee(
|
||
80 + Math.random() * (W - 160),
|
||
90 + Math.random() * (H - 210),
|
||
'queen', layer
|
||
);
|
||
bees.push(queen);
|
||
}
|
||
|
||
// Sort by layer once; draw order stays correct for whole frame
|
||
bees.sort((a, b) => a.layer - b.layer);
|
||
}
|
||
|
||
// ── Render loop ──
|
||
function renderLoop() {
|
||
rafBees = requestAnimationFrame(renderLoop);
|
||
const W = canvas.width, H = canvas.height;
|
||
|
||
ctx.drawImage(bgImg, 0, 0);
|
||
|
||
if (!locked) bees.forEach(b => b.update(W, H));
|
||
bees.forEach(b => b.draw());
|
||
|
||
// Queen reveal : spotlight + golden ring
|
||
if (reveal) {
|
||
const pulse = .5 + .5 * Math.sin(Date.now() / 140);
|
||
ctx.save();
|
||
|
||
// Radial vignette — darken everything outside queen zone
|
||
const grad = ctx.createRadialGradient(reveal.x, reveal.y, 70, reveal.x, reveal.y, Math.max(W, H));
|
||
grad.addColorStop(0, 'rgba(0,0,0,0)');
|
||
grad.addColorStop(0.35,'rgba(0,0,0,.55)');
|
||
grad.addColorStop(1, 'rgba(0,0,0,.82)');
|
||
ctx.fillStyle = grad;
|
||
ctx.fillRect(0, 0, W, H);
|
||
|
||
// Golden pulsing ring
|
||
ctx.shadowColor = '#ffd600';
|
||
ctx.shadowBlur = 20 + pulse * 18;
|
||
ctx.strokeStyle = `rgba(255,214,0,${.65 + pulse * .35})`;
|
||
ctx.lineWidth = 4 + pulse * 2;
|
||
ctx.beginPath();
|
||
ctx.arc(reveal.x, reveal.y, 54 + pulse * 10, 0, Math.PI * 2);
|
||
ctx.stroke();
|
||
ctx.shadowBlur = 0;
|
||
|
||
// Crown label
|
||
ctx.font = 'bold 900 15px Nunito, sans-serif';
|
||
ctx.textAlign = 'center';
|
||
ctx.textBaseline = 'middle';
|
||
ctx.shadowColor = 'rgba(0,0,0,.9)';
|
||
ctx.shadowBlur = 8;
|
||
ctx.fillStyle = `rgba(255,220,0,${.85 + pulse * .15})`;
|
||
ctx.fillText('♛ REINE', reveal.x, reveal.y - 75);
|
||
ctx.restore();
|
||
}
|
||
}
|
||
|
||
// ── Timer (RAF-based for precision) ──
|
||
function startTimer() {
|
||
timeLeft = CFG.FRAME_SECS;
|
||
resumeTimer();
|
||
}
|
||
|
||
function resumeTimer() {
|
||
timerLast = performance.now();
|
||
timerTick(timerLast);
|
||
}
|
||
|
||
function stopTimer() { cancelAnimationFrame(rafTimer); }
|
||
|
||
function timerTick(now) {
|
||
if (!locked) {
|
||
const dt = (now - timerLast) / 1000;
|
||
timeLeft = Math.max(0, timeLeft - dt);
|
||
timerUI();
|
||
if (timeLeft <= 0) { onTimeout(); return; }
|
||
}
|
||
timerLast = now;
|
||
rafTimer = requestAnimationFrame(timerTick);
|
||
}
|
||
|
||
// ── Feedback ──
|
||
function showFeedback(ok, icon, title, sub, advance, revealQueen) {
|
||
locked = true;
|
||
stopTimer();
|
||
|
||
if (!ok) screenShake();
|
||
screenFlash(ok ? 'rgba(0,230,90,.15)' : 'rgba(255,30,55,.25)');
|
||
if (ok) AUDIO.playSuccess(); else AUDIO.playFailure();
|
||
|
||
if (revealQueen && queen) reveal = { x: queen.x, y: queen.y };
|
||
|
||
elCard.className = 'fb-card ' + (ok ? 'ok' : 'bad');
|
||
// Restart animation
|
||
elCard.classList.remove('animate');
|
||
void elCard.offsetWidth;
|
||
elCard.classList.add('animate');
|
||
|
||
document.getElementById('fb-icon').textContent = icon;
|
||
document.getElementById('fb-title').textContent = title;
|
||
document.getElementById('fb-sub').textContent = sub;
|
||
elFB.classList.add('visible');
|
||
|
||
setTimeout(() => {
|
||
elFB.classList.remove('visible');
|
||
reveal = null;
|
||
if (advance) nextFrame();
|
||
else { locked = false; resumeTimer(); }
|
||
}, CFG.FEEDBACK_MS);
|
||
}
|
||
|
||
// ── Click on canvas ──
|
||
function onCanvasClick(cx, cy) {
|
||
if (locked) return;
|
||
|
||
if (hasQueen) {
|
||
if (Math.hypot(cx - queen.x, cy - queen.y) <= CFG.HIT_RADIUS) {
|
||
const pts = calcScore();
|
||
score += pts;
|
||
results.push({ found: true, pts });
|
||
floatTxt(`+${pts}`, cx, cy, true);
|
||
hudUpdate();
|
||
showFeedback(true, '👑', 'La Reine !', `+${pts} points`, true, false);
|
||
} else {
|
||
const lost = lives - 1;
|
||
animLifeLost(lost);
|
||
if (--lives <= 0) {
|
||
results.push({ found: false, pts: 0 });
|
||
floatTxt('✗', cx, cy, false);
|
||
hudUpdate();
|
||
showFeedback(false, '💀', 'Raté !', 'La Reine est révélée…', true, true);
|
||
} else {
|
||
floatTxt('✗', cx, cy, false);
|
||
hudUpdate();
|
||
showFeedback(false, '❌', 'Pas la Reine !', livesStr(), false, false);
|
||
}
|
||
}
|
||
} else {
|
||
// No queen — any click is wrong
|
||
const lost = lives - 1;
|
||
animLifeLost(lost);
|
||
if (--lives <= 0) {
|
||
results.push({ found: false, pts: 0 });
|
||
floatTxt('✗', cx, cy, false);
|
||
hudUpdate();
|
||
showFeedback(false, '💀', 'Pas de Reine ici !', 'Plus d\'essais', true, false);
|
||
} else {
|
||
floatTxt('✗', cx, cy, false);
|
||
hudUpdate();
|
||
showFeedback(false, '❌', 'Pas la Reine !', livesStr(), false, false);
|
||
}
|
||
}
|
||
}
|
||
|
||
// ── No Queen button ──
|
||
function onNoQueen() {
|
||
if (locked) return;
|
||
if (!hasQueen) {
|
||
const pts = 80 + Math.floor(timeLeft) * 2;
|
||
score += pts;
|
||
results.push({ found: true, pts, noQ: true });
|
||
hudUpdate();
|
||
showFeedback(true, '🎯', 'Correct !', `Pas de Reine — +${pts} pts`, true, false);
|
||
} else {
|
||
results.push({ found: false, pts: 0, noQ: true });
|
||
showFeedback(false, '💀', 'Il y avait une Reine !', 'La Reine est révélée…', true, true);
|
||
}
|
||
}
|
||
|
||
// ── Timeout ──
|
||
function onTimeout() {
|
||
if (locked) return;
|
||
results.push({ found: false, pts: 0, timeout: true });
|
||
if (hasQueen)
|
||
showFeedback(false, '⏰', 'Temps écoulé !', 'La Reine est révélée…', true, true);
|
||
else
|
||
showFeedback(false, '⏰', 'Temps écoulé !', 'Aucune Reine dans ce cadre', true, false);
|
||
}
|
||
|
||
// ── Scoring ──
|
||
function calcScore() {
|
||
// lives: 3 = found 1st try (+60), 2 = 2nd (+30), 1 = 3rd (+0)
|
||
return 100 + (lives - 1) * 30 + Math.floor(timeLeft) * 2;
|
||
}
|
||
|
||
function livesStr() {
|
||
return `${lives} essai${lives > 1 ? 's' : ''} restant${lives > 1 ? 's' : ''}`;
|
||
}
|
||
|
||
// ── Frame cycle ──
|
||
function startFrame() {
|
||
lives = CFG.LIVES;
|
||
locked = false;
|
||
reveal = null;
|
||
spawnBees();
|
||
hudUpdate();
|
||
timerUI();
|
||
startTimer();
|
||
}
|
||
|
||
function nextFrame() {
|
||
if (++frameIdx >= CFG.NUM_FRAMES) { endGame(); return; }
|
||
startFrame();
|
||
}
|
||
|
||
// ── Start / End ──
|
||
function startGame() {
|
||
frameIdx = 0; score = 0; results = [];
|
||
|
||
enterGame();
|
||
AUDIO.stopScreenMusic();
|
||
AUDIO.startAmbient();
|
||
|
||
// Start render loop (only once)
|
||
if (!rafBees) renderLoop();
|
||
|
||
startFrame();
|
||
}
|
||
|
||
function endGame() {
|
||
stopTimer();
|
||
cancelAnimationFrame(rafBees); rafBees = null;
|
||
|
||
const found = results.filter(r => r.found).length;
|
||
document.getElementById('end-score').textContent = score;
|
||
document.getElementById('end-details').innerHTML =
|
||
`Reines trouvées : <strong style="color:#f5a020">${found} / ${CFG.NUM_FRAMES}</strong><br>` +
|
||
`Score total : <strong style="color:#f5a020">${score} points</strong>`;
|
||
|
||
AUDIO.stopAmbient();
|
||
canvas.style.display = 'none';
|
||
exitGame(elEnd);
|
||
}
|
||
|
||
return { startGame, onCanvasClick, onNoQueen };
|
||
})();
|
||
|
||
// ─────────────────────────────────────────────────────
|
||
// Audio
|
||
// ─────────────────────────────────────────────────────
|
||
const AUDIO = (() => {
|
||
let ctx = null;
|
||
let ambient = null; // HTMLAudioElement (fichier) ou { oscs, lfo } (synthèse)
|
||
let screenMusic = null; // HTMLAudioElement pour la musique d'accueil
|
||
|
||
function init() {
|
||
if (ctx) return;
|
||
ctx = new (window.AudioContext || window.webkitAudioContext)();
|
||
}
|
||
|
||
// ── Ambiance ──
|
||
function startAmbient() {
|
||
if (!CFG.SOUNDS.enabled) return;
|
||
stopAmbient();
|
||
if (CFG.SOUNDS.ambient) {
|
||
const el = new Audio(CFG.SOUNDS.ambient);
|
||
el.loop = true;
|
||
el.volume = CFG.SOUNDS.ambientVolume;
|
||
el.play().catch(() => {});
|
||
ambient = el;
|
||
} else {
|
||
ambient = _ambientSynth();
|
||
}
|
||
}
|
||
|
||
function stopAmbient() {
|
||
if (!ambient) return;
|
||
if (ambient instanceof HTMLAudioElement) {
|
||
ambient.pause();
|
||
} else {
|
||
try { ambient.oscs.forEach(o => o.stop()); } catch (_) {}
|
||
try { ambient.lfo.stop(); } catch (_) {}
|
||
}
|
||
ambient = null;
|
||
}
|
||
|
||
// ── Effets ──
|
||
function playSuccess() {
|
||
if (!CFG.SOUNDS.enabled || !ctx) return;
|
||
if (CFG.SOUNDS.success) {
|
||
const el = new Audio(CFG.SOUNDS.success);
|
||
el.volume = CFG.SOUNDS.sfxVolume;
|
||
el.play().catch(() => {});
|
||
} else {
|
||
_successSynth();
|
||
}
|
||
}
|
||
|
||
function playFailure() {
|
||
if (!CFG.SOUNDS.enabled || !ctx) return;
|
||
if (CFG.SOUNDS.failure) {
|
||
const el = new Audio(CFG.SOUNDS.failure);
|
||
el.volume = CFG.SOUNDS.sfxVolume;
|
||
el.play().catch(() => {});
|
||
} else {
|
||
_failureSynth();
|
||
}
|
||
}
|
||
|
||
// ── Synthèse : ambiance (bourdonnement de colonie) ──
|
||
function _ambientSynth() {
|
||
const master = ctx.createGain();
|
||
master.gain.value = CFG.SOUNDS.ambientVolume;
|
||
|
||
const filter = ctx.createBiquadFilter();
|
||
filter.type = 'lowpass';
|
||
filter.frequency.value = 850;
|
||
filter.Q.value = 1.8;
|
||
filter.connect(master);
|
||
master.connect(ctx.destination);
|
||
|
||
// Oscillateurs légèrement désaccordés → chorus de ruche
|
||
const defs = [
|
||
{ f: 244, g: 0.14 }, { f: 247, g: 0.11 },
|
||
{ f: 241, g: 0.09 }, { f: 488, g: 0.04 },
|
||
];
|
||
const oscs = defs.map(({ f, g }) => {
|
||
const osc = ctx.createOscillator();
|
||
const gn = ctx.createGain();
|
||
osc.type = 'sawtooth';
|
||
osc.frequency.value = f;
|
||
gn.gain.value = g;
|
||
osc.connect(gn); gn.connect(filter);
|
||
osc.start(); return osc;
|
||
});
|
||
|
||
// Trémolo lent ~7 Hz → effet de nuage d'abeilles
|
||
const lfo = ctx.createOscillator();
|
||
const lfoG = ctx.createGain();
|
||
lfo.frequency.value = 7;
|
||
lfoG.gain.value = 0.22;
|
||
lfo.connect(lfoG); lfoG.connect(master.gain);
|
||
lfo.start();
|
||
|
||
return { oscs, lfo };
|
||
}
|
||
|
||
// ── Synthèse : succès (arpège ascendant do-mi-sol) ──
|
||
function _successSynth() {
|
||
const t = ctx.currentTime;
|
||
[523.25, 659.25, 783.99].forEach((freq, i) => {
|
||
const osc = ctx.createOscillator();
|
||
const env = ctx.createGain();
|
||
osc.type = 'sine';
|
||
osc.frequency.value = freq;
|
||
const s = t + i * 0.12;
|
||
env.gain.setValueAtTime(0, s);
|
||
env.gain.linearRampToValueAtTime(CFG.SOUNDS.sfxVolume * 0.5, s + 0.02);
|
||
env.gain.exponentialRampToValueAtTime(0.001, s + 0.65);
|
||
osc.connect(env); env.connect(ctx.destination);
|
||
osc.start(s); osc.stop(s + 0.7);
|
||
});
|
||
}
|
||
|
||
// ── Synthèse : échec (descente grave) ──
|
||
function _failureSynth() {
|
||
const t = ctx.currentTime;
|
||
const osc = ctx.createOscillator();
|
||
const env = ctx.createGain();
|
||
osc.type = 'square';
|
||
osc.frequency.setValueAtTime(210, t);
|
||
osc.frequency.exponentialRampToValueAtTime(55, t + 0.28);
|
||
env.gain.setValueAtTime(CFG.SOUNDS.sfxVolume * 0.32, t);
|
||
env.gain.exponentialRampToValueAtTime(0.001, t + 0.32);
|
||
osc.connect(env); env.connect(ctx.destination);
|
||
osc.start(t); osc.stop(t + 0.36);
|
||
}
|
||
|
||
// ── Musique écran d'accueil ──
|
||
function startScreenMusic() {
|
||
if (!CFG.SOUNDS.enabled || !CFG.SOUNDS.startScreen) return;
|
||
stopScreenMusic();
|
||
screenMusic = new Audio(CFG.SOUNDS.startScreen);
|
||
screenMusic.loop = true;
|
||
screenMusic.volume = CFG.SOUNDS.ambientVolume;
|
||
screenMusic.play().catch(() => {});
|
||
}
|
||
|
||
function stopScreenMusic() {
|
||
if (!screenMusic) return;
|
||
screenMusic.pause();
|
||
screenMusic = null;
|
||
}
|
||
|
||
return { init, startAmbient, stopAmbient, playSuccess, playFailure, startScreenMusic, stopScreenMusic };
|
||
})();
|
||
|
||
// ─────────────────────────────────────────────────────
|
||
// Input
|
||
// ─────────────────────────────────────────────────────
|
||
document.querySelectorAll('.diff-btn').forEach(btn => {
|
||
btn.addEventListener('click', () => {
|
||
document.querySelectorAll('.diff-btn').forEach(b => b.classList.remove('active'));
|
||
btn.classList.add('active');
|
||
easyMode = btn.dataset.mode === 'easy';
|
||
});
|
||
});
|
||
|
||
canvas.addEventListener('click', e => {
|
||
const r = canvas.getBoundingClientRect();
|
||
G.onCanvasClick(e.clientX - r.left, e.clientY - r.top);
|
||
});
|
||
|
||
document.getElementById('no-queen-btn').addEventListener('click', () => G.onNoQueen());
|
||
document.getElementById('start-btn').addEventListener('click', () => { AUDIO.init(); G.startGame(); });
|
||
document.getElementById('replay-btn').addEventListener('click', () => { AUDIO.init(); G.startGame(); });
|
||
|
||
// Musique écran d'accueil : tentative autoplay, sinon au premier geste utilisateur
|
||
AUDIO.startScreenMusic();
|
||
if (CFG.SOUNDS.startScreen) {
|
||
const _unlockScreenMusic = () => {
|
||
AUDIO.startScreenMusic();
|
||
document.removeEventListener('pointerdown', _unlockScreenMusic);
|
||
document.removeEventListener('keydown', _unlockScreenMusic);
|
||
};
|
||
document.addEventListener('pointerdown', _unlockScreenMusic, { once: true });
|
||
document.addEventListener('keydown', _unlockScreenMusic, { once: true });
|
||
}
|
||
</script>
|
||
</body>
|
||
</html>
|