Compare commits

...

2 Commits

Author SHA1 Message Date
502a462ec5 amelior interface menu 2025-12-01 22:34:05 +01:00
f311d3f103 interface qui marche 2025-12-01 22:21:40 +01:00
3 changed files with 685 additions and 47 deletions

288
game.js
View File

@ -13,6 +13,18 @@ const finalLevelElement = document.getElementById('finalLevel');
const overlayRestartBtn = document.getElementById('overlayRestartBtn'); const overlayRestartBtn = document.getElementById('overlayRestartBtn');
const confirmUsernameBtn = document.getElementById('confirmUsernameBtn'); const confirmUsernameBtn = document.getElementById('confirmUsernameBtn');
// === GESTION DU MENU ===
const mainMenu = document.getElementById('mainMenu');
const gameWrapper = document.getElementById('gameWrapper');
const playBtn = document.getElementById('playBtn');
const scoresBtn = document.getElementById('scoresBtn');
const backToMenuBtn = document.getElementById('backToMenuBtn');
const leaderboardModal = document.getElementById('leaderboardModal');
const closeModalBtn = document.getElementById('closeModalBtn');
const menuLeaderboard = document.getElementById('menuLeaderboard');
const leaderboardContainer = document.getElementById('leaderboardContainer');
const closeLeaderboardBtn = document.getElementById('closeLeaderboardBtn');
let usernameConfirmed = false; let usernameConfirmed = false;
const CELL_SIZE = 20; const CELL_SIZE = 20;
@ -1085,6 +1097,7 @@ function saveScore() {
const topScores = scores.slice(0, 10); const topScores = scores.slice(0, 10);
localStorage.setItem('pacmanScores', JSON.stringify(topScores)); localStorage.setItem('pacmanScores', JSON.stringify(topScores));
updateLeaderboard(); updateLeaderboard();
updateBestScore(); // Mettre à jour le meilleur score dans le menu
} }
} }
@ -1240,6 +1253,277 @@ function animateScore() {
} }
animateScore(); animateScore();
updateLeaderboard(); // === FANTOMES ANIMES EN ARRIERE-PLAN DU MENU ===
initGame(); const menuCanvas = document.getElementById('menuBackgroundCanvas');
const menuCtx = menuCanvas.getContext('2d');
// Ajuster la taille du canvas
function resizeMenuCanvas() {
menuCanvas.width = window.innerWidth;
menuCanvas.height = window.innerHeight;
}
resizeMenuCanvas();
window.addEventListener('resize', resizeMenuCanvas);
// Classe pour les fantômes du menu
class MenuGhost {
constructor() {
this.x = Math.random() * menuCanvas.width;
this.y = Math.random() * menuCanvas.height;
this.speedX = (Math.random() - 0.5) * 2;
this.speedY = (Math.random() - 0.5) * 2;
this.size = 30 + Math.random() * 20;
this.color = ['#ff0000', '#ff00ff', '#00ffff', '#ffa500'][Math.floor(Math.random() * 4)];
this.animation = Math.random() * Math.PI * 2;
}
update() {
this.x += this.speedX;
this.y += this.speedY;
this.animation += 0.05;
// Rebondir sur les bords
if (this.x < 0 || this.x > menuCanvas.width) {
this.speedX *= -1;
}
if (this.y < 0 || this.y > menuCanvas.height) {
this.speedY *= -1;
}
// Garder dans les limites
this.x = Math.max(0, Math.min(menuCanvas.width, this.x));
this.y = Math.max(0, Math.min(menuCanvas.height, this.y));
}
draw() {
menuCtx.save();
menuCtx.translate(this.x, this.y);
const size = this.size;
const waveOffset = Math.sin(this.animation) * 2;
// Corps du fantôme
menuCtx.fillStyle = this.color;
menuCtx.strokeStyle = '#000000';
menuCtx.lineWidth = 2;
// Tête (demi-cercle)
menuCtx.beginPath();
menuCtx.arc(0, -size * 0.3, size * 0.5, Math.PI, 0, false);
menuCtx.fill();
menuCtx.stroke();
// Corps (rectangle)
menuCtx.fillRect(-size * 0.5, -size * 0.3, size * 1.0, size * 0.7);
menuCtx.strokeRect(-size * 0.5, -size * 0.3, size * 1.0, size * 0.7);
// Jambes ondulées
const waveHeight = size * 0.15;
const waveWidth = size * 0.2;
menuCtx.beginPath();
menuCtx.moveTo(-size * 0.5, size * 0.4);
for (let i = 0; i < 5; i++) {
const x = -size * 0.5 + i * waveWidth;
const y = size * 0.4 + (i % 2 === 0 ? 0 : waveHeight) + waveOffset;
menuCtx.lineTo(x, y);
}
menuCtx.lineTo(size * 0.5, size * 0.4);
menuCtx.lineTo(size * 0.5, size * 0.7);
menuCtx.lineTo(-size * 0.5, size * 0.7);
menuCtx.closePath();
menuCtx.fill();
menuCtx.stroke();
// Yeux
menuCtx.fillStyle = '#ffffff';
menuCtx.beginPath();
menuCtx.arc(-size * 0.2, -size * 0.1, size * 0.12, 0, Math.PI * 2);
menuCtx.arc(size * 0.2, -size * 0.1, size * 0.12, 0, Math.PI * 2);
menuCtx.fill();
menuCtx.fillStyle = '#000000';
menuCtx.beginPath();
menuCtx.arc(-size * 0.2, -size * 0.1, size * 0.06, 0, Math.PI * 2);
menuCtx.arc(size * 0.2, -size * 0.1, size * 0.06, 0, Math.PI * 2);
menuCtx.fill();
menuCtx.restore();
}
}
// Créer plusieurs fantômes
const menuGhosts = [];
const numGhosts = 6;
for (let i = 0; i < numGhosts; i++) {
menuGhosts.push(new MenuGhost());
}
// Animation du menu
let menuAnimationRunning = false;
let menuAnimationFrame = null;
function animateMenu() {
if (!menuAnimationRunning) return;
// Effacer le canvas avec un effet de traînée
menuCtx.fillStyle = 'rgba(10, 10, 10, 0.1)';
menuCtx.fillRect(0, 0, menuCanvas.width, menuCanvas.height);
// Mettre à jour et dessiner les fantômes
menuGhosts.forEach(ghost => {
ghost.update();
ghost.draw();
});
menuAnimationFrame = requestAnimationFrame(animateMenu);
}
// Démarrer l'animation seulement si le menu est visible
function startMenuAnimation() {
if (!menuAnimationRunning && mainMenu && mainMenu.style.display !== 'none') {
menuAnimationRunning = true;
animateMenu();
}
}
function stopMenuAnimation() {
menuAnimationRunning = false;
if (menuAnimationFrame) {
cancelAnimationFrame(menuAnimationFrame);
}
}
// Démarrer l'animation au chargement si le menu est visible
// Attendre que le DOM soit complètement chargé
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
if (mainMenu && mainMenu.style.display !== 'none') {
startMenuAnimation();
}
});
} else {
// DOM déjà chargé
if (mainMenu && mainMenu.style.display !== 'none') {
startMenuAnimation();
}
}
// Observer les changements de visibilité du menu
if (mainMenu) {
const menuObserver = new MutationObserver(() => {
if (mainMenu.style.display !== 'none') {
if (!menuAnimationRunning) {
startMenuAnimation();
}
} else {
stopMenuAnimation();
}
});
menuObserver.observe(mainMenu, { attributes: true, attributeFilter: ['style'] });
}
// === GESTION DU MENU ===
// Afficher le jeu
playBtn.addEventListener('click', () => {
mainMenu.style.display = 'none';
gameWrapper.style.display = 'block';
resetUsernameInput();
// Toujours initialiser le jeu quand on clique sur JOUER
gameRunning = false; // S'assurer que le jeu est arrêté
initGame();
});
// Retour au menu depuis le jeu
backToMenuBtn.addEventListener('click', () => {
if (confirm('Voulez-vous vraiment retourner au menu ? Votre partie en cours sera perdue.')) {
gameWrapper.style.display = 'none';
mainMenu.style.display = 'flex';
gameRunning = false;
updateBestScore(); // Mettre à jour le meilleur score
startMenuAnimation(); // Redémarrer l'animation des fantômes
}
});
// Afficher le classement depuis le menu
scoresBtn.addEventListener('click', () => {
updateMenuLeaderboard();
leaderboardModal.style.display = 'flex';
});
// Fermer le modal de classement
closeModalBtn.addEventListener('click', () => {
leaderboardModal.style.display = 'none';
});
// Fermer le classement dans le jeu
if (closeLeaderboardBtn) {
closeLeaderboardBtn.addEventListener('click', () => {
leaderboardContainer.style.display = 'none';
});
}
// Fermer le modal en cliquant à l'extérieur
leaderboardModal.addEventListener('click', (e) => {
if (e.target === leaderboardModal) {
leaderboardModal.style.display = 'none';
}
});
// Fonction pour mettre à jour le classement du menu
function updateMenuLeaderboard() {
const scores = getScores();
menuLeaderboard.innerHTML = '';
if (scores.length === 0) {
menuLeaderboard.innerHTML = '<div class="empty-leaderboard">Aucun score enregistré</div>';
return;
}
scores.forEach((entry, index) => {
const item = document.createElement('div');
item.className = 'leaderboard-item' + (index < 3 ? ' top' : '');
const rank = document.createElement('div');
rank.className = 'leaderboard-rank';
rank.textContent = (index + 1) + '.';
const name = document.createElement('div');
name.className = 'leaderboard-name';
name.textContent = entry.username;
const levelDiv = document.createElement('div');
levelDiv.className = 'leaderboard-level';
levelDiv.textContent = 'Niv. ' + (entry.level || 1);
const scoreDiv = document.createElement('div');
scoreDiv.className = 'leaderboard-score';
scoreDiv.textContent = entry.score;
item.appendChild(rank);
item.appendChild(name);
item.appendChild(levelDiv);
item.appendChild(scoreDiv);
menuLeaderboard.appendChild(item);
});
}
// Fonction pour mettre à jour le meilleur score dans le menu
function updateBestScore() {
const scores = getScores();
const bestScoreElement = document.getElementById('bestScoreValue');
if (scores.length > 0) {
const bestScore = scores[0].score;
const bestLevel = scores[0].level || 1;
bestScoreElement.textContent = `${bestScore} (Niv. ${bestLevel})`;
} else {
bestScoreElement.textContent = '0';
}
}
// Initialiser seulement le menu au chargement
updateMenuLeaderboard();
updateBestScore();

View File

@ -7,9 +7,35 @@
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
</head> </head>
<body> <body>
<!-- MENU PRINCIPAL -->
<div class="main-menu" id="mainMenu">
<canvas id="menuBackgroundCanvas"></canvas>
<div class="menu-container">
<h1>OULVIC</h1>
<p class="menu-subtitle">Évitez les fantômes et collectez les pastilles !</p>
<div class="best-score-display" id="bestScoreDisplay">
<span class="best-score-label">Meilleur Score:</span>
<span class="best-score-value" id="bestScoreValue">0</span>
</div>
<div class="menu-buttons">
<button class="menu-btn" id="playBtn">
<span class="btn-icon"></span> JOUER
</button>
<button class="menu-btn" id="scoresBtn">
<span class="btn-icon">🏆</span> CLASSEMENT
</button>
</div>
</div>
</div>
<!-- INTERFACE DE JEU (cachée au départ) -->
<div class="game-wrapper" id="gameWrapper" style="display: none;">
<div class="main-wrapper"> <div class="main-wrapper">
<div class="container"> <div class="container">
<h1>OULVIC</h1> <div class="game-header">
<button class="back-btn" id="backToMenuBtn">← Menu</button>
<h2>OULVIC</h2>
</div>
<div class="user-input-section"> <div class="user-input-section">
<label for="username">Nom d'utilisateur:</label> <label for="username">Nom d'utilisateur:</label>
<input type="text" id="username" placeholder="Entrez votre nom" maxlength="15"> <input type="text" id="username" placeholder="Entrez votre nom" maxlength="15">
@ -48,14 +74,32 @@
</div> </div>
</div> </div>
</div> </div>
<div class="leaderboard-container">
<!-- CLASSEMENT (caché par défaut) -->
<div class="leaderboard-container" id="leaderboardContainer" style="display: none;">
<div class="leaderboard-header">
<h2>Classement</h2> <h2>Classement</h2>
<button class="close-leaderboard-btn" id="closeLeaderboardBtn"></button>
</div>
<div id="leaderboard"></div> <div id="leaderboard"></div>
</div> </div>
</div> </div>
<footer> <footer>
<p>By Ludo and Syoul</p> <p>By Ludo and Syoul</p>
</footer> </footer>
</div>
<!-- MODAL CLASSEMENT (pour le menu) -->
<div class="leaderboard-modal" id="leaderboardModal" style="display: none;">
<div class="modal-content">
<div class="modal-header">
<h2>Classement</h2>
<button class="close-modal-btn" id="closeModalBtn"></button>
</div>
<div id="menuLeaderboard"></div>
</div>
</div>
<script src="game.js"></script> <script src="game.js"></script>
</body> </body>
</html> </html>

312
style.css
View File

@ -125,6 +125,282 @@ body::after {
100% { transform: scale(1); } 100% { transform: scale(1); }
} }
/* === MENU PRINCIPAL === */
.main-menu {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #0a0a0a;
background-image:
radial-gradient(circle at 20% 30%, rgba(255, 0, 0, 0.1) 0%, transparent 50%),
radial-gradient(circle at 80% 70%, rgba(0, 0, 255, 0.1) 0%, transparent 50%),
radial-gradient(circle at 50% 50%, rgba(128, 0, 128, 0.1) 0%, transparent 50%);
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1000;
overflow: hidden;
}
/* === CANVAS ARRIERE-PLAN MENU === */
#menuBackgroundCanvas {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
opacity: 0.3;
pointer-events: none;
}
.menu-container {
position: relative;
z-index: 2;
text-align: center;
background: rgba(0, 0, 0, 0.6);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
padding: 50px 40px;
border-radius: 20px;
border: 1px solid rgba(255, 215, 0, 0.3);
box-shadow:
0 10px 30px rgba(0, 0, 0, 0.8),
0 0 50px rgba(255, 0, 0, 0.2),
inset 0 0 30px rgba(255, 215, 0, 0.05);
animation: menuFadeIn 0.8s ease-out;
}
@keyframes menuFadeIn {
from {
opacity: 0;
transform: scale(0.9) translateY(-20px);
}
to {
opacity: 1;
transform: scale(1) translateY(0);
}
}
.menu-container h1 {
font-size: 3em;
margin-bottom: 20px;
letter-spacing: 5px;
animation: neonFlicker 3s infinite, rainbow 8s linear infinite;
}
.menu-subtitle {
font-size: 0.6em;
color: #ffd700;
margin-bottom: 25px;
text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
animation: subtitleGlow 2s ease-in-out infinite;
line-height: 1.6;
}
@keyframes subtitleGlow {
0%, 100% { opacity: 0.7; }
50% { opacity: 1; }
}
.best-score-display {
font-size: 0.7em;
color: #ffd700;
margin-bottom: 30px;
padding: 12px 25px;
background: rgba(255, 215, 0, 0.1);
border: 1px solid rgba(255, 215, 0, 0.3);
border-radius: 10px;
display: inline-block;
}
.best-score-label {
margin-right: 10px;
}
.best-score-value {
color: #00ff00;
font-size: 1.3em;
font-weight: bold;
text-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
}
.menu-buttons {
display: flex;
flex-direction: column;
gap: 20px;
align-items: center;
}
.menu-btn {
padding: 20px 50px;
font-size: 1em;
font-family: 'Press Start 2P', cursive;
background: linear-gradient(180deg, #ffd700 0%, #ff8c00 100%);
color: #000;
border: none;
border-radius: 15px;
cursor: pointer;
font-weight: bold;
transition: all 0.3s;
box-shadow: 0 5px 15px rgba(255, 215, 0, 0.4);
min-width: 250px;
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
animation: buttonPulse 2s ease-in-out infinite;
}
@keyframes buttonPulse {
0%, 100% {
box-shadow: 0 5px 15px rgba(255, 215, 0, 0.4);
}
50% {
box-shadow: 0 5px 25px rgba(255, 215, 0, 0.7);
}
}
.btn-icon {
font-size: 0.9em;
}
.menu-btn:hover {
background: linear-gradient(180deg, #ffed4e 0%, #ffa500 100%);
transform: translateY(-3px);
box-shadow:
0 8px 20px rgba(255, 215, 0, 0.6),
0 0 30px rgba(255, 215, 0, 0.4);
text-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
animation: none;
}
.menu-btn:active {
transform: translateY(0) scale(0.98);
}
/* === WRAPPER DE JEU === */
.game-wrapper {
min-height: 100vh;
}
/* === HEADER DU JEU === */
.game-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.game-header h2 {
font-size: 1.5em;
margin: 0;
flex: 1;
text-align: center;
letter-spacing: 3px;
animation: neonFlicker 3s infinite, rainbow 8s linear infinite;
}
.back-btn {
padding: 10px 20px;
font-size: 0.7em;
font-family: 'Press Start 2P', cursive;
background: rgba(255, 255, 255, 0.1);
color: #ffd700;
border: 2px solid #ffd700;
border-radius: 10px;
cursor: pointer;
transition: all 0.3s;
}
.back-btn:hover {
background: rgba(255, 215, 0, 0.2);
transform: translateX(-3px);
}
/* === MODAL CLASSEMENT === */
.leaderboard-modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.9);
display: flex;
justify-content: center;
align-items: center;
z-index: 2000;
animation: fadeIn 0.3s ease-out;
}
.modal-content {
background: rgba(0, 0, 0, 0.9);
padding: 30px;
border-radius: 20px;
border: 3px solid rgba(255, 215, 0, 0.4);
box-shadow:
0 10px 30px rgba(0, 0, 0, 0.8),
0 0 50px rgba(255, 0, 0, 0.2);
max-width: 500px;
width: 90%;
max-height: 80vh;
overflow-y: auto;
position: relative;
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.modal-header h2 {
color: #ffd700;
font-size: 1.5em;
margin: 0;
}
.close-modal-btn, .close-leaderboard-btn {
background: rgba(255, 0, 0, 0.3);
color: #fff;
border: 2px solid #ff0000;
border-radius: 50%;
width: 35px;
height: 35px;
font-size: 1.2em;
cursor: pointer;
transition: all 0.3s;
display: flex;
align-items: center;
justify-content: center;
font-family: 'Press Start 2P', cursive;
}
.close-modal-btn:hover, .close-leaderboard-btn:hover {
background: rgba(255, 0, 0, 0.5);
transform: scale(1.1);
}
#menuLeaderboard {
max-height: 60vh;
overflow-y: auto;
}
.leaderboard-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.leaderboard-header h2 {
margin: 0;
}
/* === LAYOUT === */ /* === LAYOUT === */
.main-wrapper { .main-wrapper {
display: flex; display: flex;
@ -340,7 +616,7 @@ h1 {
.leaderboard-container h2 { .leaderboard-container h2 {
color: #ffd700; color: #ffd700;
text-align: center; text-align: center;
margin-bottom: 20px; margin: 0;
font-size: 1.2em; font-size: 1.2em;
text-shadow: text-shadow:
0 0 10px rgba(255, 215, 0, 0.5), 0 0 10px rgba(255, 215, 0, 0.5),
@ -609,6 +885,35 @@ footer {
} }
@media (max-width: 700px) { @media (max-width: 700px) {
.menu-container {
padding: 30px 20px;
}
.menu-container h1 {
font-size: 2em;
}
.menu-subtitle {
font-size: 0.5em;
margin-bottom: 20px;
}
.best-score-display {
font-size: 0.6em;
padding: 10px 15px;
margin-bottom: 25px;
}
.best-score-value {
font-size: 1.1em;
}
.menu-btn {
min-width: 200px;
padding: 15px 30px;
font-size: 0.8em;
}
#gameCanvas { #gameCanvas {
width: 100%; width: 100%;
height: auto; height: auto;
@ -639,4 +944,9 @@ footer {
.final-score, .final-level { .final-score, .final-level {
font-size: 0.7em; font-size: 0.7em;
} }
.modal-content {
padding: 20px;
width: 95%;
}
} }