855 lines
26 KiB
HTML
855 lines
26 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="fr" data-theme="dark">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
|
<title>T-Rex Dino Runner - AP Manageur</title>
|
|
<style>
|
|
* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; }
|
|
|
|
:root, html[data-theme="dark"] {
|
|
--bg: #071326;
|
|
--card-bg: #0d1d36;
|
|
--panel-box: #132746;
|
|
--border: #223c68;
|
|
--text: #eef4ff;
|
|
--muted: #9aa8c5;
|
|
--blue: #5ca7ff;
|
|
--blue-btn-text: #071326;
|
|
--canvas-day: #0f2444;
|
|
--canvas-night: #050d1a;
|
|
--dino-color: #eef4ff;
|
|
--dino-eye: #0f2444;
|
|
--cactus-color: #34d399;
|
|
--ptero-color: #ff6b6b;
|
|
--ground-color: #5ca7ff;
|
|
--ground-bump: #38bdf8;
|
|
--cloud-color: #223c68;
|
|
--star-color: #eef4ff;
|
|
}
|
|
html[data-theme="light"] {
|
|
--bg: #f2f5fa;
|
|
--card-bg: #ffffff;
|
|
--panel-box: #e9eef7;
|
|
--border: #d2dcec;
|
|
--text: #15203a;
|
|
--muted: #5b6b8c;
|
|
--blue: #1e6ef0;
|
|
--blue-btn-text: #ffffff;
|
|
--canvas-day: #f8fafc;
|
|
--canvas-night: #1e293b;
|
|
--dino-color: #334155;
|
|
--dino-eye: #f8fafc;
|
|
--cactus-color: #16a34a;
|
|
--ptero-color: #ef4444;
|
|
--ground-color: #64748b;
|
|
--ground-bump: #94a3b8;
|
|
--cloud-color: #cbd5e1;
|
|
--star-color: #f1f5f9;
|
|
}
|
|
html[data-theme="winxp"] {
|
|
--bg: #ece9d8;
|
|
--card-bg: #ece9d8;
|
|
--panel-box: #ffffff;
|
|
--border: #7f9db9;
|
|
--text: #000000;
|
|
--muted: #444444;
|
|
--blue: #0055ea;
|
|
--blue-btn-text: #ffffff;
|
|
--canvas-day: #ffffff;
|
|
--canvas-night: #0a246a;
|
|
--dino-color: #111111;
|
|
--dino-eye: #ffffff;
|
|
--cactus-color: #198754;
|
|
--ptero-color: #cc0000;
|
|
--ground-color: #7f9db9;
|
|
--ground-bump: #555555;
|
|
--cloud-color: #dcdcdc;
|
|
--star-color: #ffffdd;
|
|
font-family: 'Tahoma', sans-serif !important;
|
|
}
|
|
html[data-theme="macos"][data-macos-mode="light"],
|
|
html[data-theme="macos"]:not([data-macos-mode="dark"]) {
|
|
--bg: #f5f5f7;
|
|
--card-bg: #ffffff;
|
|
--panel-box: #f2f2f7;
|
|
--border: rgba(0, 0, 0, 0.12);
|
|
--text: #1d1d1f;
|
|
--muted: #86868b;
|
|
--blue: #0071e3;
|
|
--blue-btn-text: #ffffff;
|
|
--canvas-day: #ffffff;
|
|
--canvas-night: #2c2c2e;
|
|
--dino-color: #1d1d1f;
|
|
--dino-eye: #ffffff;
|
|
--cactus-color: #34c759;
|
|
--ptero-color: #ff3b30;
|
|
--ground-color: #8e8e93;
|
|
--ground-bump: #636366;
|
|
--cloud-color: #e5e5ea;
|
|
--star-color: #ffffff;
|
|
}
|
|
html[data-theme="macos"][data-macos-mode="dark"] {
|
|
--bg: #1e1e1e;
|
|
--card-bg: #2d2d2d;
|
|
--panel-box: #3a3a3c;
|
|
--border: rgba(255, 255, 255, 0.15);
|
|
--text: #f5f5f7;
|
|
--muted: #98989d;
|
|
--blue: #0a84ff;
|
|
--blue-btn-text: #ffffff;
|
|
--canvas-day: #252527;
|
|
--canvas-night: #141416;
|
|
--dino-color: #f5f5f7;
|
|
--dino-eye: #252527;
|
|
--cactus-color: #30d158;
|
|
--ptero-color: #ff453a;
|
|
--ground-color: #636366;
|
|
--ground-bump: #8e8e93;
|
|
--cloud-color: #3a3a3c;
|
|
--star-color: #ffffff;
|
|
}
|
|
html[data-theme="futuristic"] {
|
|
--bg: #050811;
|
|
--card-bg: #091124;
|
|
--panel-box: #0f1c3a;
|
|
--border: #00f0ff;
|
|
--text: #e6f6ff;
|
|
--muted: #64b5f6;
|
|
--blue: #00f0ff;
|
|
--blue-btn-text: #050811;
|
|
--canvas-day: #030818;
|
|
--canvas-night: #01040a;
|
|
--dino-color: #00f0ff;
|
|
--dino-eye: #030818;
|
|
--cactus-color: #c084fc;
|
|
--ptero-color: #f43f5e;
|
|
--ground-color: #00f0ff;
|
|
--ground-bump: #38bdf8;
|
|
--cloud-color: #1e293b;
|
|
--star-color: #00f0ff;
|
|
}
|
|
html[data-theme="hacker"] {
|
|
--bg: #000000;
|
|
--card-bg: #051206;
|
|
--panel-box: #0a1f0c;
|
|
--border: #00ff41;
|
|
--text: #00ff41;
|
|
--muted: #008f11;
|
|
--blue: #00ff41;
|
|
--blue-btn-text: #000000;
|
|
--canvas-day: #020d04;
|
|
--canvas-night: #000000;
|
|
--dino-color: #00ff41;
|
|
--dino-eye: #020d04;
|
|
--cactus-color: #00bb30;
|
|
--ptero-color: #ff0055;
|
|
--ground-color: #00ff41;
|
|
--ground-bump: #00ff41;
|
|
--cloud-color: #00330d;
|
|
--star-color: #00ff41;
|
|
}
|
|
|
|
body {
|
|
background: var(--bg);
|
|
color: var(--text);
|
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, monospace;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
min-height: 100vh;
|
|
overflow: hidden;
|
|
padding: 10px;
|
|
transition: background 0.3s ease, color 0.3s ease;
|
|
}
|
|
.game-card {
|
|
background: var(--card-bg);
|
|
border: 1px solid var(--border);
|
|
border-radius: 14px;
|
|
padding: 16px;
|
|
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 20px rgba(92, 167, 255, 0.12);
|
|
position: relative;
|
|
max-width: 700px;
|
|
width: 100%;
|
|
transition: all 0.3s ease;
|
|
}
|
|
.header-bar {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 12px;
|
|
font-size: 14px;
|
|
color: var(--muted);
|
|
}
|
|
.scores {
|
|
font-size: 18px;
|
|
font-weight: 700;
|
|
letter-spacing: 2px;
|
|
color: var(--blue);
|
|
font-family: monospace;
|
|
}
|
|
.scores .hi {
|
|
color: var(--muted);
|
|
margin-right: 12px;
|
|
}
|
|
.canvas-wrap {
|
|
position: relative;
|
|
background: var(--canvas-day);
|
|
border: 2px solid var(--border);
|
|
border-radius: 8px;
|
|
overflow: hidden;
|
|
transition: background 0.6s ease, border-color 0.3s ease;
|
|
}
|
|
body.night-mode .canvas-wrap {
|
|
background: var(--canvas-night);
|
|
}
|
|
canvas {
|
|
display: block;
|
|
width: 100%;
|
|
height: 220px;
|
|
cursor: pointer;
|
|
}
|
|
.controls-hint {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-top: 12px;
|
|
font-size: 12px;
|
|
color: var(--muted);
|
|
flex-wrap: wrap;
|
|
gap: 8px;
|
|
}
|
|
.controls-hint kbd {
|
|
background: var(--panel-box);
|
|
border: 1px solid var(--border);
|
|
color: var(--text);
|
|
padding: 2px 6px;
|
|
border-radius: 4px;
|
|
font-size: 11px;
|
|
}
|
|
.overlay-message {
|
|
position: absolute;
|
|
inset: 0;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
background: rgba(7, 19, 38, 0.85);
|
|
backdrop-filter: blur(3px);
|
|
z-index: 10;
|
|
gap: 12px;
|
|
}
|
|
.overlay-message h2 {
|
|
font-size: 22px;
|
|
color: #ff6b6b;
|
|
letter-spacing: 3px;
|
|
}
|
|
.restart-btn {
|
|
background: var(--blue);
|
|
color: var(--blue-btn-text);
|
|
border: 0;
|
|
padding: 8px 20px;
|
|
border-radius: 6px;
|
|
font-weight: 700;
|
|
font-size: 14px;
|
|
cursor: pointer;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
|
|
transition: opacity 0.15s ease;
|
|
}
|
|
.restart-btn:hover { opacity: 0.9; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="game-card">
|
|
<div class="header-bar">
|
|
<div style="display:flex;align-items:center;gap:4px">
|
|
🦖 <strong id="dinoTitleText">Chrome T-Rex Runner</strong>
|
|
<span id="dinoLevelBadge" style="font-size:11px;padding:2px 8px;border-radius:12px;background:var(--panel-box);border:1px solid var(--border);color:var(--blue);margin-left:8px;font-weight:700;transition:transform 0.2s ease">Niveau 1</span>
|
|
</div>
|
|
<div class="scores">
|
|
<span class="hi">HI <span id="hiScore">00000</span></span>
|
|
<span id="currentScore">00000</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="canvas-wrap" id="canvasWrap">
|
|
<canvas id="dinoCanvas" width="640" height="220"></canvas>
|
|
<div id="gameOverlay" class="overlay-message" style="display:none">
|
|
<h2 id="dinoGameOverText">G A M E O V E R</h2>
|
|
<button id="dinoRestartBtn" class="restart-btn" onclick="resetGame()">🔄 REJOUER (Espace)</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="controls-hint" id="dinoControlsHint">
|
|
<div id="dinoHintJump"><kbd>Espace</kbd> ou <kbd>⬆️</kbd> : Sauter</div>
|
|
<div id="dinoHintDuck"><kbd>⬇️</kbd> : Se baisser / descente rapide</div>
|
|
<div id="dinoHintTouch">Toucher l'écran pour sauter</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// Theme & i18n Management
|
|
function setTheme(theme, macosMode) {
|
|
if (!theme) theme = 'dark';
|
|
document.documentElement.dataset.theme = theme;
|
|
if (theme === 'macos' && macosMode) {
|
|
document.documentElement.dataset.macosMode = macosMode;
|
|
} else {
|
|
delete document.documentElement.dataset.macosMode;
|
|
}
|
|
}
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
setTheme(urlParams.get('theme') || 'dark', urlParams.get('macosMode'));
|
|
|
|
// Dictionnaire i18n
|
|
const I18N_DINO = {
|
|
fr: {
|
|
title: "Chrome T-Rex Runner",
|
|
game_over: "G A M E O V E R",
|
|
restart_btn: "🔄 REJOUER (Espace)",
|
|
hint_jump: "<kbd>Espace</kbd> ou <kbd>⬆️</kbd> : Sauter",
|
|
hint_duck: "<kbd>⬇️</kbd> : Se baisser / descente rapide",
|
|
hint_touch: "Toucher l'écran pour sauter"
|
|
},
|
|
en: {
|
|
title: "Chrome T-Rex Runner",
|
|
game_over: "G A M E O V E R",
|
|
restart_btn: "🔄 REPLAY (Space)",
|
|
hint_jump: "<kbd>Space</kbd> or <kbd>⬆️</kbd>: Jump",
|
|
hint_duck: "<kbd>⬇️</kbd>: Duck / Fast drop",
|
|
hint_touch: "Tap screen to jump"
|
|
}
|
|
};
|
|
|
|
let currentDinoLang = 'fr';
|
|
let lastLevel = 1;
|
|
|
|
function applyDinoLang(lang) {
|
|
currentDinoLang = (lang && (lang.startsWith('en') ? 'en' : 'fr')) || 'fr';
|
|
const dict = I18N_DINO[currentDinoLang] || I18N_DINO.fr;
|
|
const tEl = document.getElementById('dinoTitleText');
|
|
const goEl = document.getElementById('dinoGameOverText');
|
|
const rbEl = document.getElementById('dinoRestartBtn');
|
|
const hjEl = document.getElementById('dinoHintJump');
|
|
const hdEl = document.getElementById('dinoHintDuck');
|
|
const htEl = document.getElementById('dinoHintTouch');
|
|
const badge = document.getElementById('dinoLevelBadge');
|
|
if (tEl) tEl.textContent = dict.title;
|
|
if (goEl) goEl.innerHTML = dict.game_over;
|
|
if (rbEl) rbEl.textContent = dict.restart_btn;
|
|
if (hjEl) hjEl.innerHTML = dict.hint_jump;
|
|
if (hdEl) hdEl.innerHTML = dict.hint_duck;
|
|
if (htEl) htEl.textContent = dict.hint_touch;
|
|
if (badge) badge.textContent = (currentDinoLang.startsWith('en') ? 'Level ' : 'Niveau ') + lastLevel;
|
|
}
|
|
applyDinoLang(urlParams.get('lang'));
|
|
|
|
window.addEventListener('message', e => {
|
|
if (e.data && e.data.type === 'themeChange') {
|
|
setTheme(e.data.theme, e.data.macosMode);
|
|
}
|
|
if (e.data && e.data.type === 'langChange') {
|
|
applyDinoLang(e.data.lang);
|
|
}
|
|
});
|
|
|
|
function getThemeProp(name, fallback) {
|
|
const val = getComputedStyle(document.documentElement).getPropertyValue(name).trim();
|
|
return val || fallback;
|
|
}
|
|
|
|
// Audio synthesizer
|
|
let audioCtx = null;
|
|
function playTone(type) {
|
|
try {
|
|
if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
|
if (audioCtx.state === 'suspended') audioCtx.resume();
|
|
const osc = audioCtx.createOscillator();
|
|
const gain = audioCtx.createGain();
|
|
osc.connect(gain);
|
|
gain.connect(audioCtx.destination);
|
|
const now = audioCtx.currentTime;
|
|
|
|
if (type === 'jump') {
|
|
osc.type = 'square';
|
|
osc.frequency.setValueAtTime(450, now);
|
|
osc.frequency.exponentialRampToValueAtTime(700, now + 0.08);
|
|
gain.gain.setValueAtTime(0.04, now);
|
|
gain.gain.exponentialRampToValueAtTime(0.001, now + 0.08);
|
|
osc.start(now); osc.stop(now + 0.08);
|
|
} else if (type === 'hit') {
|
|
osc.type = 'sawtooth';
|
|
osc.frequency.setValueAtTime(140, now);
|
|
osc.frequency.linearRampToValueAtTime(60, now + 0.25);
|
|
gain.gain.setValueAtTime(0.08, now);
|
|
gain.gain.exponentialRampToValueAtTime(0.001, now + 0.25);
|
|
osc.start(now); osc.stop(now + 0.25);
|
|
} else if (type === 'score') {
|
|
osc.type = 'sine';
|
|
osc.frequency.setValueAtTime(587.33, now);
|
|
osc.frequency.setValueAtTime(880, now + 0.08);
|
|
gain.gain.setValueAtTime(0.06, now);
|
|
gain.gain.exponentialRampToValueAtTime(0.001, now + 0.18);
|
|
osc.start(now); osc.stop(now + 0.18);
|
|
}
|
|
} catch (e) {}
|
|
}
|
|
|
|
const canvas = document.getElementById('dinoCanvas');
|
|
const ctx = canvas.getContext('2d');
|
|
const hiScoreEl = document.getElementById('hiScore');
|
|
const currentScoreEl = document.getElementById('currentScore');
|
|
const overlay = document.getElementById('gameOverlay');
|
|
const canvasWrap = document.getElementById('canvasWrap');
|
|
|
|
const GROUND_Y = 180;
|
|
let highScore = parseInt(localStorage.getItem('ap_dino_hi') || '0', 10);
|
|
hiScoreEl.textContent = String(highScore).padStart(5, '0');
|
|
|
|
let gameStarted = false;
|
|
let gameOver = false;
|
|
let score = 0;
|
|
let gameSpeed = 6;
|
|
let nextObstacleTimer = 90; // Période de grâce au lancement
|
|
let isNight = false;
|
|
|
|
// Dinosaur
|
|
const dino = {
|
|
x: 40,
|
|
y: GROUND_Y - 44,
|
|
width: 44,
|
|
height: 44,
|
|
vy: 0,
|
|
jumpForce: -11.5,
|
|
gravity: 0.65,
|
|
isGrounded: true,
|
|
isDucking: false,
|
|
legFrame: 0,
|
|
legTimer: 0
|
|
};
|
|
|
|
// Obstacles
|
|
let obstacles = [];
|
|
let clouds = [
|
|
{ x: 120, y: 50, speed: 0.8 },
|
|
{ x: 380, y: 70, speed: 0.6 },
|
|
{ x: 550, y: 40, speed: 0.7 }
|
|
];
|
|
let stars = [];
|
|
for (let i = 0; i < 25; i++) {
|
|
stars.push({
|
|
x: Math.random() * 640,
|
|
y: Math.random() * 120 + 10,
|
|
r: Math.random() * 1.5 + 0.5
|
|
});
|
|
}
|
|
|
|
let groundOffset = 0;
|
|
|
|
function jump() {
|
|
if (!gameStarted) {
|
|
gameStarted = true;
|
|
}
|
|
if (gameOver) {
|
|
resetGame();
|
|
return;
|
|
}
|
|
if (dino.isGrounded && !dino.isDucking) {
|
|
dino.vy = dino.jumpForce;
|
|
dino.isGrounded = false;
|
|
playTone('jump');
|
|
}
|
|
}
|
|
|
|
function duck(isDucking) {
|
|
if (!gameStarted || gameOver) return;
|
|
dino.isDucking = isDucking;
|
|
if (isDucking) {
|
|
dino.height = 28;
|
|
if (!dino.isGrounded) {
|
|
dino.vy += 4; // Fast fall
|
|
}
|
|
} else {
|
|
dino.height = 44;
|
|
}
|
|
}
|
|
|
|
function resetGame() {
|
|
gameOver = false;
|
|
gameStarted = true;
|
|
score = 0;
|
|
gameSpeed = 6;
|
|
lastLevel = 1;
|
|
nextObstacleTimer = 90; // Période de grâce de 1.5s à chaque reprise
|
|
obstacles = [];
|
|
dino.y = GROUND_Y - 44;
|
|
dino.vy = 0;
|
|
dino.isGrounded = true;
|
|
dino.isDucking = false;
|
|
dino.height = 44;
|
|
overlay.style.display = 'none';
|
|
document.body.classList.remove('night-mode');
|
|
isNight = false;
|
|
const badge = document.getElementById('dinoLevelBadge');
|
|
if (badge) badge.textContent = (currentDinoLang.startsWith('en') ? 'Level 1' : 'Niveau 1');
|
|
}
|
|
|
|
function spawnObstacle() {
|
|
// Les ptérodactyles apparaissent dès 280 points (plus palpitant)
|
|
const allowPtero = score > 280;
|
|
const pteroChance = score > 600 ? 0.35 : 0.25;
|
|
const type = (allowPtero && Math.random() < pteroChance) ? 'ptero' : 'cactus';
|
|
|
|
if (type === 'cactus') {
|
|
let isBig = false;
|
|
let count = 1;
|
|
|
|
// Difficulté progressive équitable
|
|
if (score < 120) {
|
|
// Niveau 1 : 1 seul petit cactus (accessible)
|
|
isBig = false;
|
|
count = 1;
|
|
} else if (score < 300) {
|
|
// Niveau 2 : 1 cactus petit ou grand
|
|
isBig = Math.random() < 0.45;
|
|
count = 1;
|
|
} else if (score < 550) {
|
|
// Niveau 3 : 1 ou 2 cactus
|
|
isBig = Math.random() < 0.45;
|
|
count = Math.random() < 0.6 ? 1 : 2;
|
|
} else {
|
|
// Niveaux 4 & 5 : jusqu'à 3 petits ou 2 grands
|
|
isBig = Math.random() < 0.45;
|
|
count = isBig ? (Math.random() < 0.65 ? 1 : 2) : (Math.floor(Math.random() * 3) + 1);
|
|
}
|
|
|
|
const w = (isBig ? 24 : 16) * count;
|
|
const h = isBig ? 44 : 32;
|
|
obstacles.push({
|
|
type: 'cactus',
|
|
x: canvas.width + 20,
|
|
y: GROUND_Y - h,
|
|
width: w,
|
|
height: h,
|
|
isBig: isBig
|
|
});
|
|
} else {
|
|
// Ptérodactyles : 3 hauteurs distinctes (basse = sauter, moyenne = se baisser obligatoirement, haute = passer dessous)
|
|
const heights = [GROUND_Y - 32, GROUND_Y - 55, GROUND_Y - 78];
|
|
const h = heights[Math.floor(Math.random() * heights.length)];
|
|
obstacles.push({
|
|
type: 'ptero',
|
|
x: canvas.width + 20,
|
|
y: h,
|
|
width: 40,
|
|
height: 28,
|
|
frame: 0,
|
|
frameTimer: 0
|
|
});
|
|
}
|
|
}
|
|
|
|
function checkCollision(r1, r2) {
|
|
const p = 8; // Marge de tolérance équitable pour les collisions
|
|
return (
|
|
r1.x + p < r2.x + r2.width &&
|
|
r1.x + r1.width - p > r2.x &&
|
|
r1.y + p < r2.y + r2.height &&
|
|
r1.y + r1.height - p > r2.y
|
|
);
|
|
}
|
|
|
|
function drawPixelDino(x, y, w, h, isDucking, legFrame, isDead) {
|
|
const dinoColor = getThemeProp('--dino-color', '#eef4ff');
|
|
const eyeColor = isNight ? getThemeProp('--canvas-night', '#050d1a') : getThemeProp('--canvas-day', '#0f2444');
|
|
ctx.fillStyle = dinoColor;
|
|
|
|
if (isDucking && dino.isGrounded) {
|
|
// Ducking body
|
|
ctx.fillRect(x, y + 18, 54, 22);
|
|
// Head low
|
|
ctx.fillRect(x + 40, y + 10, 18, 14);
|
|
// Eye
|
|
ctx.fillStyle = eyeColor;
|
|
ctx.fillRect(x + 48, y + 12, 3, 3);
|
|
ctx.fillStyle = dinoColor;
|
|
// Legs
|
|
if (legFrame === 0) {
|
|
ctx.fillRect(x + 10, y + 36, 4, 8);
|
|
ctx.fillRect(x + 24, y + 36, 4, 8);
|
|
} else {
|
|
ctx.fillRect(x + 14, y + 36, 4, 8);
|
|
ctx.fillRect(x + 28, y + 36, 4, 8);
|
|
}
|
|
return;
|
|
}
|
|
|
|
// Normal standing / running dino
|
|
// Head
|
|
ctx.fillRect(x + 22, y, 22, 16);
|
|
ctx.fillRect(x + 18, y + 6, 6, 10);
|
|
// Eye
|
|
ctx.fillStyle = eyeColor;
|
|
ctx.fillRect(x + 26, y + 3, isDead ? 5 : 3, 3);
|
|
if (isDead) {
|
|
ctx.fillRect(x + 28, y + 2, 2, 5);
|
|
}
|
|
ctx.fillStyle = dinoColor;
|
|
|
|
// Snout / mouth
|
|
ctx.fillRect(x + 36, y + 8, 8, 6);
|
|
|
|
// Body
|
|
ctx.fillRect(x + 10, y + 16, 22, 20);
|
|
ctx.fillRect(x + 6, y + 20, 6, 12);
|
|
ctx.fillRect(x, y + 22, 6, 8); // Tail
|
|
|
|
// Arm
|
|
ctx.fillRect(x + 28, y + 22, 8, 3);
|
|
ctx.fillRect(x + 33, y + 24, 3, 4);
|
|
|
|
// Legs
|
|
if (!dino.isGrounded) {
|
|
ctx.fillRect(x + 12, y + 36, 4, 8);
|
|
ctx.fillRect(x + 22, y + 36, 4, 8);
|
|
} else if (legFrame === 0) {
|
|
ctx.fillRect(x + 12, y + 36, 4, 8);
|
|
ctx.fillRect(x + 22, y + 36, 4, 4);
|
|
} else {
|
|
ctx.fillRect(x + 12, y + 36, 4, 4);
|
|
ctx.fillRect(x + 22, y + 36, 4, 8);
|
|
}
|
|
}
|
|
|
|
function drawCactus(x, y, w, h) {
|
|
ctx.fillStyle = getThemeProp('--cactus-color', '#34d399');
|
|
// Main stem
|
|
ctx.fillRect(x + w * 0.35, y, w * 0.3, h);
|
|
// Branches
|
|
if (w > 20) {
|
|
ctx.fillRect(x, y + h * 0.25, w * 0.35, h * 0.15);
|
|
ctx.fillRect(x, y + h * 0.1, w * 0.15, h * 0.25);
|
|
ctx.fillRect(x + w * 0.65, y + h * 0.4, w * 0.35, h * 0.15);
|
|
ctx.fillRect(x + w * 0.85, y + h * 0.25, w * 0.15, h * 0.25);
|
|
}
|
|
}
|
|
|
|
function drawPterodactyl(p) {
|
|
ctx.fillStyle = getThemeProp('--ptero-color', '#ff6b6b');
|
|
const x = p.x, y = p.y;
|
|
// Body
|
|
ctx.fillRect(x + 10, y + 8, 16, 8);
|
|
// Head & Beak
|
|
ctx.fillRect(x, y + 10, 10, 4);
|
|
ctx.fillRect(x + 4, y + 6, 6, 8);
|
|
// Wings
|
|
if (p.frame === 0) {
|
|
ctx.fillRect(x + 14, y, 6, 8); // Up wing
|
|
} else {
|
|
ctx.fillRect(x + 14, y + 16, 6, 10); // Down wing
|
|
}
|
|
}
|
|
|
|
function drawCloud(c) {
|
|
ctx.fillStyle = getThemeProp('--cloud-color', '#223c68');
|
|
ctx.beginPath();
|
|
ctx.arc(c.x, c.y, 10, 0, Math.PI * 2);
|
|
ctx.arc(c.x + 10, c.y - 6, 12, 0, Math.PI * 2);
|
|
ctx.arc(c.x + 22, c.y, 10, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
}
|
|
|
|
function update() {
|
|
if (gameStarted && !gameOver) {
|
|
score += 0.2;
|
|
const currentIntScore = Math.floor(score);
|
|
currentScoreEl.textContent = String(currentIntScore).padStart(5, '0');
|
|
|
|
// Calcul dynamique du niveau (1 à 5)
|
|
let currentLevel = 1;
|
|
if (score >= 900) currentLevel = 5;
|
|
else if (score >= 600) currentLevel = 4;
|
|
else if (score >= 350) currentLevel = 3;
|
|
else if (score >= 150) currentLevel = 2;
|
|
|
|
if (currentLevel !== lastLevel) {
|
|
lastLevel = currentLevel;
|
|
const badge = document.getElementById('dinoLevelBadge');
|
|
if (badge) {
|
|
badge.textContent = (currentDinoLang.startsWith('en') ? 'Level ' : 'Niveau ') + currentLevel;
|
|
badge.style.transform = 'scale(1.25)';
|
|
setTimeout(() => { if (badge) badge.style.transform = 'scale(1)'; }, 350);
|
|
}
|
|
playTone('score');
|
|
}
|
|
|
|
// Vitesse progressive qui monte au fur et à mesure (de 6.0 à 13.5 max)
|
|
gameSpeed = Math.min(13.5, 6.0 + Math.sqrt(score) * 0.26);
|
|
|
|
// High score
|
|
if (currentIntScore > highScore) {
|
|
highScore = currentIntScore;
|
|
hiScoreEl.textContent = String(highScore).padStart(5, '0');
|
|
localStorage.setItem('ap_dino_hi', highScore);
|
|
}
|
|
|
|
// Alternance Jour / Nuit tous les 600 points
|
|
const nightCycle = Math.floor(score / 600) % 2 === 1;
|
|
if (nightCycle !== isNight) {
|
|
isNight = nightCycle;
|
|
document.body.classList.toggle('night-mode', isNight);
|
|
}
|
|
|
|
// Son de palier tous les 100 points
|
|
if (currentIntScore > 0 && currentIntScore % 100 === 0 && Math.floor((score - 0.2)) % 100 !== 0) {
|
|
playTone('score');
|
|
}
|
|
|
|
// Dino physics
|
|
dino.y += dino.vy;
|
|
dino.vy += dino.gravity;
|
|
|
|
if (dino.y >= GROUND_Y - dino.height) {
|
|
dino.y = GROUND_Y - dino.height;
|
|
dino.vy = 0;
|
|
dino.isGrounded = true;
|
|
}
|
|
|
|
// Dino animation legs
|
|
dino.legTimer++;
|
|
if (dino.legTimer > 5) {
|
|
dino.legFrame = (dino.legFrame === 0) ? 1 : 0;
|
|
dino.legTimer = 0;
|
|
}
|
|
|
|
// Décompte de l'obstacle : 1 frame par itération pour un timing stable
|
|
nextObstacleTimer -= 1;
|
|
if (nextObstacleTimer <= 0) {
|
|
spawnObstacle();
|
|
// Intervalle équitable proportionnel à la vitesse (garantit toujours >= 330px d'espace entre les obstacles)
|
|
const minFrames = Math.max(38, Math.round(330 / gameSpeed));
|
|
const randomVariance = Math.floor(Math.random() * (Math.max(20, Math.round(180 / gameSpeed))));
|
|
nextObstacleTimer = minFrames + randomVariance;
|
|
}
|
|
|
|
// Move obstacles
|
|
for (let i = obstacles.length - 1; i >= 0; i--) {
|
|
const obs = obstacles[i];
|
|
obs.x -= gameSpeed;
|
|
|
|
if (obs.type === 'ptero') {
|
|
obs.frameTimer = (obs.frameTimer || 0) + 1;
|
|
if (obs.frameTimer > 12) {
|
|
obs.frame = (obs.frame === 0) ? 1 : 0;
|
|
obs.frameTimer = 0;
|
|
}
|
|
}
|
|
|
|
// Collision detection
|
|
if (checkCollision(dino, obs)) {
|
|
gameOver = true;
|
|
playTone('hit');
|
|
overlay.style.display = 'flex';
|
|
}
|
|
|
|
// Offscreen removal
|
|
if (obs.x + obs.width < -10) {
|
|
obstacles.splice(i, 1);
|
|
}
|
|
}
|
|
|
|
// Move clouds
|
|
clouds.forEach(c => {
|
|
c.x -= c.speed;
|
|
if (c.x < -40) c.x = canvas.width + 20;
|
|
});
|
|
|
|
// Ground scroll
|
|
groundOffset = (groundOffset + gameSpeed) % 40;
|
|
}
|
|
|
|
// DRAW
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
|
|
// Stars in night mode
|
|
if (isNight) {
|
|
ctx.fillStyle = getThemeProp('--star-color', '#eef4ff');
|
|
stars.forEach(s => {
|
|
ctx.beginPath();
|
|
ctx.arc(s.x, s.y, s.r, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
});
|
|
// Moon
|
|
ctx.fillStyle = '#f3f4f6';
|
|
ctx.beginPath();
|
|
ctx.arc(560, 40, 16, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
ctx.fillStyle = getThemeProp('--canvas-night', '#050d1a');
|
|
ctx.beginPath();
|
|
ctx.arc(553, 37, 13, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
}
|
|
|
|
// Clouds
|
|
clouds.forEach(drawCloud);
|
|
|
|
// Ground Line
|
|
ctx.strokeStyle = getThemeProp('--ground-color', '#5ca7ff');
|
|
ctx.lineWidth = 2;
|
|
ctx.beginPath();
|
|
ctx.moveTo(0, GROUND_Y);
|
|
ctx.lineTo(canvas.width, GROUND_Y);
|
|
ctx.stroke();
|
|
|
|
// Ground texture bumps
|
|
ctx.fillStyle = getThemeProp('--ground-bump', '#38bdf8');
|
|
for (let x = -groundOffset; x < canvas.width; x += 30) {
|
|
ctx.fillRect(x + 5, GROUND_Y + 4, 8, 2);
|
|
ctx.fillRect(x + 18, GROUND_Y + 9, 4, 1.5);
|
|
}
|
|
|
|
// Obstacles
|
|
obstacles.forEach(obs => {
|
|
if (obs.type === 'cactus') drawCactus(obs.x, obs.y, obs.width, obs.height);
|
|
else if (obs.type === 'ptero') drawPterodactyl(obs);
|
|
});
|
|
|
|
// Dino
|
|
drawPixelDino(dino.x, dino.y, dino.width, dino.height, dino.isDucking, dino.legFrame, gameOver);
|
|
|
|
requestAnimationFrame(update);
|
|
}
|
|
|
|
// Input handlers
|
|
window.addEventListener('keydown', e => {
|
|
if ([' ', 'ArrowUp'].includes(e.key)) {
|
|
e.preventDefault();
|
|
jump();
|
|
} else if (e.key === 'ArrowDown') {
|
|
e.preventDefault();
|
|
duck(true);
|
|
}
|
|
});
|
|
|
|
window.addEventListener('keyup', e => {
|
|
if (e.key === 'ArrowDown') {
|
|
duck(false);
|
|
}
|
|
});
|
|
|
|
canvas.addEventListener('pointerdown', e => {
|
|
e.preventDefault();
|
|
jump();
|
|
});
|
|
|
|
update();
|
|
</script>
|
|
</body>
|
|
</html>
|