Voici un jeu complet, extrêmement soigné, jouable directement dans votre navigateur.
html Copy code
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>Fraise Party - Casual AAA</title>
<link href="https://fonts.googleapis.com/css2?family=Fredoka+One&family=Nunito:wght@700;900&display=swap" rel="stylesheet">
<style>
:root {
--primary: #ff4a75;
--primary-dark: #e02f5a;
--accent: #ffd15c;
--bg-sky: #e1f5fe;
}
* {
box-sizing: border-box;
user-select: none;
-webkit-user-select: none;
}
body, html {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow: hidden;
background-color: #111;
font-family: 'Nunito', sans-serif;
display: flex;
justify-content: center;
align-items: center;
}
/* Conteneur du jeu pour garder un aspect ratio de qualité */
#game-container {
position: relative;
width: 100%;
max-width: 480px;
height: 100%;
max-height: 850px;
aspect-ratio: 9/16;
background: var(--bg-sky);
box-shadow: 0 10px 30px rgba(0,0,0,0.5);
overflow: hidden;
border-radius: 16px;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: none;
}
/* UI Overlays */
.overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
transition: all 0.4s ease;
z-index: 10;
padding: 20px;
text-align: center;
}
.overlay.hidden {
opacity: 0;
pointer-events: none;
transform: scale(1.1);
}
h1 {
font-family: 'Fredoka One', cursive;
font-size: 3.2rem;
color: var(--primary);
margin: 0 0 10px 0;
text-shadow: 0 4px 0 #fff, 0 8px 20px rgba(255, 74, 117, 0.4);
animation: bounce 2s infinite ease-in-out;
}
@keyframes bounce {
0%, 100% { transform: translateY(0) rotate(-2deg); }
50% { transform: translateY(-10px) rotate(2deg); }
}
p {
font-size: 1.2rem;
color: #5c6b73;
margin: 0 0 30px 0;
font-weight: 700;
}
.btn {
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
color: white;
border: none;
padding: 16px 40px;
font-size: 1.5rem;
font-family: 'Fredoka One', cursive;
border-radius: 50px;
cursor: pointer;
box-shadow: 0 8px 0 #b31d41, 0 15px 25px rgba(255, 74, 117, 0.4);
transition: all 0.1s ease;
transform: translateY(0);
}
.btn:active {
transform: translateY(6px);
box-shadow: 0 2px 0 #b31d41, 0 5px 10px rgba(255, 74, 117, 0.4);
}
/* Stats en jeu */
#hud {
position: absolute;
top: 20px;
left: 0;
width: 100%;
padding: 0 20px;
display: flex;
justify-content: space-between;
align-items: center;
pointer-events: none;
z-index: 5;
}
.hud-item {
background: rgba(255, 255, 255, 0.85);
padding: 8px 16px;
border-radius: 20px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
border: 2px solid rgba(255, 255, 255, 0.4);
display: flex;
align-items: center;
gap: 8px;
font-family: 'Fredoka One', cursive;
font-size: 1.2rem;
}
#score-display { color: var(--primary); }
#lives-display { color: #ff3333; }
/* Game Over Screen */
#game-over-screen {
background: rgba(18, 18, 24, 0.4);
}
#game-over-screen h2 {
font-family: 'Fredoka One', cursive;
font-size: 3rem;
color: #fff;
margin: 0;
text-shadow: 0 4px 10px rgba(0,0,0,0.5);
}
.score-box {
background: white;
padding: 20px;
border-radius: 24px;
margin: 20px 0;
width: 80%;
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.score-box div {
font-size: 1.1rem;
color: #7f8c8d;
text-transform: uppercase;
letter-spacing: 1px;
}
.score-box .final-score {
font-size: 3rem;
font-family: 'Fredoka One', cursive;
color: var(--primary);
}
.best-score {
font-size: 1.2rem !important;
color: var(--accent) !important;
background: #2c3e50;
display: inline-block;
padding: 4px 12px;
border-radius: 12px;
margin-top: 5px;
}
</style>
</head>
<body>
<div id="game-container">
<!-- HUD (Score et Vies) -->
<div id="hud">
<div class="hud-item" id="score-display">🍓 <span id="score-val">0</span></div>
<div class="hud-item" id="lives-display">❤️ <span id="lives-val">3</span></div>
</div>
<!-- Écran d'accueil -->
<div id="start-screen" class="overlay">
<h1>Fraise Party</h1>
<p>Attrape les fraises sucrées !<br>Évite les devoirs stressants ! 📝</p>
<button class="btn" id="start-btn">JOUER !</button>
</div>
<!-- Écran de Game Over -->
<div id="game-over-screen" class="overlay hidden">
<h2>Fin de Partie !</h2>
<div class="score-box">
<div>Score Obtenu</div>
<div class="final-score" id="end-score">0</div>
<div class="best-score" id="best-score">Record : 0</div>
</div>
<button class="btn" id="restart-btn">REJOUER</button>
</div>
<canvas id="gameCanvas"></canvas>
</div>
<script>
// --- CONFIGURATION DU JEU ---
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
// Résolution interne fixe pour garantir le même gameplay sur tous les écrans
const GAME_WIDTH = 450;
const GAME_HEIGHT = 800;
canvas.width = GAME_WIDTH;
canvas.height = GAME_HEIGHT;
// Synthétiseur Audio Intégré (Web Audio API) pour un son AAA sans fichiers externes
const AudioFX = {
ctx: null,
init() {
this.ctx = new (window.AudioContext || window.webkitAudioContext)();
},
playCollect() {
if (!this.ctx) return;
let osc = this.ctx.createOscillator();
let gain = this.ctx.createGain();
osc.connect(gain);
gain.connect(this.ctx.destination);
osc.type = 'sine';
osc.frequency.setValueAtTime(400, this.ctx.currentTime);
osc.frequency.exponentialRampToValueAtTime(1200, this.ctx.currentTime + 0.15);
gain.gain.setValueAtTime(0.3, this.ctx.currentTime);
gain.gain.linearRampToValueAtTime(0.01, this.ctx.currentTime + 0.15);
osc.start();
osc.stop(this.ctx.currentTime + 0.15);
},
playHit() {
if (!this.ctx) return;
let osc = this.ctx.createOscillator();
let gain = this.ctx.createGain();
osc.connect(gain);
gain.connect(this.ctx.destination);
osc.type = 'sawtooth';
osc.frequency.setValueAtTime(150, this.ctx.currentTime);
osc.frequency.linearRampToValueAtTime(40, this.ctx.currentTime + 0.3);
gain.gain.setValueAtTime(0.4, this.ctx.currentTime);
gain.gain.linearRampToValueAtTime(0.01, this.ctx.currentTime + 0.3);
osc.start();
osc.stop(this.ctx.currentTime + 0.3);
},
playGameOver() {
if (!this.ctx) return;
let osc = this.ctx.createOscillator();
let gain = this.ctx.createGain();
osc.connect(gain);
gain.connect(this.ctx.destination);
osc.type = 'triangle';
osc.frequency.setValueAtTime(300, this.ctx.currentTime);
osc.frequency.linearRampToValueAtTime(80, this.ctx.currentTime + 0.8);
gain.gain.setValueAtTime(0.5, this.ctx.currentTime);
gain.gain.linearRampToValueAtTime(0.01, this.ctx.currentTime + 0.8);
osc.start();
osc.stop(this.ctx.currentTime + 0.8);
}
};
// --- VARIABLES DU JEU ---
let gameState = 'START'; // START, PLAYING, GAMEOVER
let score = 0;
let lives = 3;
let speedMultiplier = 1;
let screenShake = 0;
let particles = [];
let items = [];
let floatingTexts = [];
// --- LE PERSONNAGE (La Petite Fille) ---
const player = {
x: GAME_WIDTH / 2,
y: GAME_HEIGHT - 120,
width: 80,
height: 100,
targetX: GAME_WIDTH / 2,
speed: 0.2, // Pour une interpolation fluide (easing)
squashX: 1,
squashY: 1,
update() {
// Déplacement fluide vers la cible (souris/toucher)
let dx = this.targetX - this.x;
this.x += dx * this.speed;
// Limites de l'écran
if (this.x < this.width/2) this.x = this.width/2;
if (this.x > GAME_WIDTH - this.width/2) this.x = GAME_WIDTH - this.width/2;
// Retour progressif à la forme normale (squash & stretch)
this.squashX += (1 - this.squashX) * 0.1;
this.squashY += (1 - this.squashY) * 0.1;
},
draw() {
ctx.save();
ctx.translate(this.x, this.y);
ctx.scale(this.squashX, this.squashY);
// Ombre au sol
ctx.beginPath();
ctx.fillStyle = 'rgba(0,0,0,0.15)';
ctx.ellipse(0, 55, 35, 10, 0, 0, Math.PI * 2);
ctx.fill();
// 1. Les cheveux (arrière)
ctx.fillStyle = '#ff7b90';
ctx.beginPath();
ctx.arc(-25, -10, 20, 0, Math.PI*2);
ctx.arc(25, -10, 20, 0, Math.PI*2);
ctx.fill();
// 2. Robe rouge
ctx.fillStyle = '#ff4a75';
ctx.beginPath();
ctx.moveTo(-25, 50);
ctx.lineTo(25, 50);
ctx.lineTo(15, 10);
ctx.lineTo(-15, 10);
ctx.closePath();
ctx.fill();
// Col blanc de la robe
ctx.fillStyle = '#ffffff';
ctx.beginPath();
ctx.arc(0, 12, 8, 0, Math.PI);
ctx.fill();
// 3. Tête (visage)
ctx.fillStyle = '#ffd8b3';
ctx.beginPath();
ctx.arc(0, -10, 28, 0, Math.PI * 2);
ctx.fill();
// 4. Cheveux (frange devant)
ctx.fillStyle = '#ff5e7e';
ctx.beginPath();
ctx.arc(0, -22, 28, Math.PI, 0);
ctx.fill();
// Couettes/Chignons
ctx.beginPath();
ctx.arc(-28, -25, 14, 0, Math.PI*2);
ctx.arc(28, -25, 14, 0, Math.PI*2);
ctx.fill();
// Noeuds jaunes dans les cheveux
ctx.fillStyle = '#ffd15c';
ctx.beginPath();
ctx.arc(-28, -15, 6, 0, Math.PI*2);
ctx.arc(28, -15, 6, 0, Math.PI*2);
ctx.fill();
// 5. Visage (Yeux brillants et Joues roses)
ctx.fillStyle = '#ff9aa2'; // Joues
ctx.beginPath();
ctx.arc(-15, -4, 6, 0, Math.PI*2);
ctx.arc(15, -4, 6, 0, Math.PI*2);
ctx.fill();
ctx.fillStyle = '#2c3e50'; // Yeux
ctx.beginPath();
ctx.arc(-10, -10, 4, 0, Math.PI*2);
ctx.arc(10, -10, 4, 0, Math.PI*2);
ctx.fill();
// Reflet blanc dans les yeux (Effet mignon AAA)
ctx.fillStyle = '#ffffff';
ctx.beginPath();
ctx.arc(-11, -12, 1.5, 0, Math.PI*2);
ctx.arc(9, -12, 1.5, 0, Math.PI*2);
ctx.fill();
// Bouche souriante
ctx.strokeStyle = '#2c3e50';
ctx.lineWidth = 2.5;
ctx.beginPath();
ctx.arc(0, -2, 6, 0, Math.PI);
ctx.stroke();
// 6. Panier pour attraper les fraises
ctx.fillStyle = '#d7ccc8';
ctx.beginPath();
ctx.roundRect(-30, 20, 60, 25, 8);
ctx.fill();
// Texture panier tressé
ctx.strokeStyle = '#8d6e63';
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(-20, 20); ctx.lineTo(-20, 45);
ctx.moveTo(0, 20); ctx.lineTo(0, 45);
ctx.moveTo(20, 20); ctx.lineTo(20, 45);
ctx.moveTo(-30, 32); ctx.lineTo(30, 32);
ctx.stroke();
ctx.restore();
},
triggerSquash() {
this.squashX = 1.3;
this.squashY = 0.7;
}
};
// --- CLASSES DES OBJETS TOMBANTS ---
class FallingItem {
constructor() {
this.x = Math.random() * (GAME_WIDTH - 60) + 30;
this.y = -50;
this.type = Math.random() < 0.65 ? 'strawberry' : 'homework';
this.size = this.type === 'strawberry' ? 36 : 45;
this.speed = (Math.random() * 3 + 4) * speedMultiplier;
this.angle = Math.random() * Math.PI * 2;
this.spin = (Math.random() - 0.5) * 0.05;
}
update() {
this.y += this.speed;
this.angle += this.spin;
}
draw() {
ctx.save();
ctx.translate(this.x, this.y);
ctx.rotate(this.angle);
// Ombre portée de l'objet
ctx.shadowColor = 'rgba(0, 0, 0, 0.1)';
ctx.shadowBlur = 8;
ctx.shadowOffsetY = 10;
if (this.type === 'strawberry') {
// --- DESSIN FRAISE (Vectoriel Poli) ---
// Corps rouge
ctx.fillStyle = '#ff3366';
ctx.beginPath();
ctx.moveTo(0, 20);
ctx.bezierCurveTo(-22, 10, -22, -18, 0, -20);
ctx.bezierCurveTo(22, -18, 22, 10, 0, 20);
ctx.fill();
// Feuilles vertes
ctx.fillStyle = '#4caf50';
ctx.beginPath();
ctx.moveTo(0, -18);
ctx.lineTo(-12, -26);
ctx.lineTo(-4, -18);
ctx.lineTo(0, -28);
ctx.lineTo(4, -18);
ctx.lineTo(12, -26);
ctx.closePath();
ctx.fill();
// Petits grains jaunes
ctx.fillStyle = '#ffeb3b';
const seeds = [
{x: -6, y: -5}, {x: 6, y: -5}, {x: 0, y: 3},
{x: -8, y: 5}, {x: 8, y: 5}, {x: 0, y: 11}
];
seeds.forEach(s => {
ctx.beginPath();
ctx.arc(s.x, s.y, 1.5, 0, Math.PI*2);
ctx.fill();
});
} else {
// --- DESSIN DEVOIR / FEUILLE DE CONTROLE ---
// Feuille blanche de travers
ctx.fillStyle = '#ffffff';
ctx.strokeStyle = '#b0bec5';
ctx.lineWidth = 2;
ctx.beginPath();
ctx.roundRect(-18, -24, 36, 48, 4);
ctx.fill();
ctx.stroke();
// Lignes de texte simulées
ctx.strokeStyle = '#cfd8dc';
ctx.lineWidth = 2;
for(let i = -12; i <= 12; i += 8) {
ctx.beginPath();
ctx.moveTo(-10, i);
ctx.lineTo(10, i);
ctx.stroke();
}
// Grosse note rouge fâchée "F" ou "0/20"
ctx.fillStyle = '#d32f2f';
ctx.font = 'bold 16px Arial';
ctx.fillText('F', 4, 18);
// Un petit trait rouge de correction
ctx.strokeStyle = '#d32f2f';
ctx.lineWidth = 1.5;
ctx.beginPath();
ctx.arc(8, 13, 8, 0, Math.PI*2);
ctx.stroke();
}
ctx.restore();
}
}
// --- SYSTÈME DE PARTICULES (Effets visuels juteux) ---
class Particle {
constructor(x, y, color) {
this.x = x;
this.y = y;
this.color = color;
this.radius = Math.random() * 5 + 3;
this.vx = (Math.random() - 0.5) * 8;
this.vy = (Math.random() - 0.5) * 8 - 3;
this.alpha = 1;
this.gravity = 0.15;
}
update() {
this.x += this.vx;
this.y += this.vy;
this.vy += this.gravity;
this.alpha -= 0.02;
}
draw() {
ctx.save();
ctx.globalAlpha = this.alpha;
ctx.fillStyle = this.color;
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
}
}
// Textes flottants (ex: +10)
class FloatingText {
constructor(x, y, text, color) {
this.x = x;
this.y = y;
this.text = text;
this.color = color;
this.vy = -2;
this.alpha = 1;
}
update() {
this.y += this.vy;
this.alpha -= 0.02;
}
draw() {
ctx.save();
ctx.globalAlpha = this.alpha;
ctx.fillStyle = this.color;
ctx.font = 'bold 24px "Fredoka One", cursive';
ctx.textAlign = 'center';
ctx.fillText(this.text, this.x, this.y);
ctx.restore();
}
}
// --- BOUCLE DE JEU ET LOGIQUE DE JEU ---
let spawnTimer = 0;
let spawnInterval = 60; // Toutes les 1 seconde à 60fps
function resetGame() {
score = 0;
lives = 3;
speedMultiplier = 1;
items = [];
particles = [];
floatingTexts = [];
player.x = GAME_WIDTH / 2;
player.targetX = GAME_WIDTH / 2;
document.getElementById('score-val').innerText = score;
document.getElementById('lives-val').innerText = lives;
}
function spawnItem() {
items.push(new FallingItem());
}
function checkCollision(rect1, rect2) {
// Collision circulaire simplifiée pour un meilleur feeling (plus indulgent)
const dist = Math.hypot(rect1.x - rect2.x, rect1.y - rect2.y);
return dist < (rect1.width/2 + rect2.size/2 - 10);
}
function explode(x, y, color, count = 12) {
for (let i = 0; i < count; i++) {
particles.push(new Particle(x, y, color));
}
}
function update() {
if (gameState !== 'PLAYING') return;
// Intensité de la secousse d'écran diminue
if (screenShake > 0) screenShake -= 0.1;
player.update();
// Augmentation progressive de la difficulté
speedMultiplier = 1 + (score / 150);
spawnInterval = Math.max(25, 60 - (score / 10));
// Gestion de l'apparition des items
spawnTimer++;
if (spawnTimer >= spawnInterval) {
spawnItem();
spawnTimer = 0;
}
// Update des objets tombants
for (let i = items.length - 1; i >= 0; i--) {
let item = items[i];
item.update();
// Collision avec le joueur (panier)
// On cible le haut du panier
let basketY = player.y + 20;
if (checkCollision({x: player.x, y: basketY, width: 60}, item)) {
if (item.type === 'strawberry') {
score += 10;
document.getElementById('score-val').innerText = score;
explode(item.x, item.y, '#ff4a75');
floatingTexts.push(new FloatingText(item.x, item.y - 20, '+10', '#ff4a75'));
AudioFX.playCollect();
player.triggerSquash();
} else {
// Touché par les devoirs !
lives--;
document.getElementById('lives-val').innerText = lives;
explode(item.x, item.y, '#90a4ae', 20);
floatingTexts.push(new FloatingText(player.x, player.y - 50, 'Aïe ! 📝', '#d32f2f'));
screenShake = 8; // Déclenche la secousse
AudioFX.playHit();
if (lives <= 0) {
gameOver();
}
}
items.splice(i, 1);
continue;
}
// Sortie de l'écran
if (item.y > GAME_HEIGHT + 50) {
items.splice(i, 1);
}
}
// Particules
for (let i = particles.length - 1; i >= 0; i--) {
particles[i].update();
if (particles[i].alpha <= 0) particles.splice(i, 1);
}
// Textes flottants
for (let i = floatingTexts.length - 1; i >= 0; i--) {
floatingTexts[i].update();
if (floatingTexts[i].alpha <= 0) floatingTexts.splice(i, 1);
}
}
// --- RENDU GRAPHIQUE ---
function draw() {
ctx.save();
// Application de l'effet de secousse d'écran (Screen Shake AAA)
if (screenShake > 0) {
let dx = (Math.random() - 0.5) * screenShake;
let dy = (Math.random() - 0.5) * screenShake;
ctx.translate(dx, dy);
}
// 1. Fond dégradé ciel doux
let skyGrad = ctx.createLinearGradient(0, 0, 0, GAME_HEIGHT);
skyGrad.addColorStop(0, '#e1f5fe');
skyGrad.addColorStop(1, '#b3e5fc');
ctx.fillStyle = skyGrad;
ctx.fillRect(0, 0, GAME_WIDTH, GAME_HEIGHT);
// Dessin de quelques nuages d'arrière-plan stylisés
ctx.fillStyle = 'rgba(255,255,255,0.5)';
ctx.beginPath();
ctx.arc(100, 150, 40, 0, Math.PI*2);
ctx.arc(140, 140, 50, 0, Math.PI*2);
ctx.arc(180, 150, 40, 0, Math.PI*2);
ctx.fill();
ctx.beginPath();
ctx.arc(320, 280, 30, 0, Math.PI*2);
ctx.arc(350, 270, 40, 0, Math.PI*2);
ctx.arc(380, 280, 30, 0, Math.PI*2);
ctx.fill();
// 2. Dessin des éléments de jeu
items.forEach(item => item.draw());
player.draw();
particles.forEach(p => p.draw());
floatingTexts.forEach(ft => ft.draw());
ctx.restore();
}
// --- BOUCLE PRINCIPALE (60 FPS attendu) ---
function gameLoop() {
update();
draw();
requestAnimationFrame(gameLoop);
}
// --- ÉVÉNEMENTS ET ENTRÉES CONTROLES ---
const container = document.getElementById('game-container');
function handleMove(clientX) {
if (gameState !== 'PLAYING') return;
const rect = canvas.getBoundingClientRect();
// Conversion de la position de l'écran vers la résolution logique interne
const scaleX = GAME_WIDTH / rect.width;
player.targetX = (clientX - rect.left) * scaleX;
}
// Contrôles Souris
window.addEventListener('mousemove', (e) => {
handleMove(e.clientX);
});
// Contrôles Tactiles (Mobile)
window.addEventListener('touchmove', (e) => {
if (e.touches.length > 0) {
handleMove(e.touches[0].clientX);
}
}, { passive: true });
// --- INTERFACES ET MENUS ---
const startScreen = document.getElementById('start-screen');
const gameOverScreen = document.getElementById('game-over-screen');
const startBtn = document.getElementById('start-btn');
const restartBtn = document.getElementById('restart-btn');
startBtn.addEventListener('click', () => {
AudioFX.init();
startScreen.classList.add('hidden');
gameState = 'PLAYING';
resetGame();
});
restartBtn.addEventListener('click', () => {
gameOverScreen.classList.add('hidden');
gameState = 'PLAYING';
resetGame();
});
function gameOver() {
gameState = 'GAMEOVER';
AudioFX.playGameOver();
// Sauvegarde du meilleur score
let best = localStorage.getItem('fraise_best_score') || 0;
if (score > best) {
best = score;
localStorage.setItem('fraise_best_score', best);
}
document.getElementById('end-score').innerText = score;
document.getElementById('best-score').innerText = "Record : " + best;
gameOverScreen.classList.remove('hidden');
}
// Lancement initial de la boucle d'affichage
gameLoop();
</script>
</body>
</html>