Spaces:
Running
Running
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Flapi Birb - Modern Flappy Bird Game</title> | |
| <style> | |
| * { | |
| margin: 0; | |
| padding: 0; | |
| box-sizing: border-box; | |
| } | |
| :root { | |
| --primary-color: #4ecdc4; | |
| --secondary-color: #44a08d; | |
| --accent-color: #f7b733; | |
| --danger-color: #ff6b6b; | |
| --dark-color: #2c3e50; | |
| --light-color: #ecf0f1; | |
| --shadow: 0 4px 6px rgba(0, 0, 0, 0.1); | |
| --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.2); | |
| } | |
| body { | |
| font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| min-height: 100vh; | |
| display: flex; | |
| flex-direction: column; | |
| align-items: center; | |
| justify-content: center; | |
| overflow: hidden; | |
| position: relative; | |
| } | |
| .header { | |
| position: absolute; | |
| top: 20px; | |
| left: 0; | |
| right: 0; | |
| text-align: center; | |
| z-index: 100; | |
| } | |
| .header a { | |
| color: white; | |
| text-decoration: none; | |
| font-size: 1.2rem; | |
| font-weight: bold; | |
| padding: 10px 20px; | |
| background: rgba(255, 255, 255, 0.2); | |
| border-radius: 50px; | |
| backdrop-filter: blur(10px); | |
| transition: all 0.3s ease; | |
| display: inline-flex; | |
| align-items: center; | |
| gap: 8px; | |
| } | |
| .header a:hover { | |
| background: rgba(255, 255, 255, 0.3); | |
| transform: translateY(-2px); | |
| } | |
| .game-container { | |
| background: linear-gradient(to bottom, #87CEEB 0%, #98D8E8 50%, #B0E0E6 100%); | |
| border-radius: 20px; | |
| box-shadow: var(--shadow-lg); | |
| padding: 20px; | |
| position: relative; | |
| max-width: 90vw; | |
| max-height: 80vh; | |
| overflow: hidden; | |
| } | |
| .game-canvas { | |
| border-radius: 15px; | |
| background: linear-gradient(to bottom, #87CEEB 0%, #98D8E8 100%); | |
| display: block; | |
| width: 100%; | |
| height: 100%; | |
| position: relative; | |
| overflow: hidden; | |
| } | |
| .bird { | |
| position: absolute; | |
| width: 40px; | |
| height: 30px; | |
| background: linear-gradient(135deg, #FFD700, #FFA500); | |
| border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; | |
| left: 100px; | |
| top: 50%; | |
| transform: translateY(-50%); | |
| transition: transform 0.1s ease; | |
| z-index: 10; | |
| box-shadow: var(--shadow); | |
| } | |
| .bird::before { | |
| content: ''; | |
| position: absolute; | |
| width: 15px; | |
| height: 10px; | |
| background: #FF6347; | |
| border-radius: 50%; | |
| top: 5px; | |
| left: 25px; | |
| box-shadow: inset -2px 0 0 #8B4513; | |
| } | |
| .bird::after { | |
| content: ''; | |
| position: absolute; | |
| width: 8px; | |
| height: 8px; | |
| background: white; | |
| border-radius: 50%; | |
| top: 8px; | |
| left: 30px; | |
| box-shadow: inset -2px 0 0 #87CEEB; | |
| } | |
| .pipe { | |
| position: absolute; | |
| background: linear-gradient(to bottom, #2ecc71, #27ae60); | |
| border-radius: 10px 10px 0 0; | |
| box-shadow: var(--shadow); | |
| } | |
| .pipe-top { | |
| border-radius: 10px 10px 0 0; | |
| } | |
| .pipe-bottom { | |
| border-radius: 0 0 10px 10px; | |
| background: linear-gradient(to top, #2ecc71, #27ae60); | |
| } | |
| .cloud { | |
| position: absolute; | |
| background: white; | |
| border-radius: 50%; | |
| opacity: 0.8; | |
| animation: float 20s infinite linear; | |
| } | |
| @keyframes float { | |
| from { transform: translateX(100vw); } | |
| to { transform: translateX(-100px); } | |
| } | |
| .score-display { | |
| position: absolute; | |
| top: 20px; | |
| left: 50%; | |
| transform: translateX(-50%); | |
| font-size: 2.5rem; | |
| font-weight: bold; | |
| color: white; | |
| text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3); | |
| z-index: 20; | |
| background: rgba(0, 0, 0, 0.2); | |
| padding: 10px 20px; | |
| border-radius: 50px; | |
| backdrop-filter: blur(10px); | |
| } | |
| .game-over { | |
| position: absolute; | |
| top: 50%; | |
| left: 50%; | |
| transform: translate(-50%, -50%); | |
| background: rgba(255, 255, 255, 0.95); | |
| padding: 30px; | |
| border-radius: 20px; | |
| text-align: center; | |
| box-shadow: var(--shadow-lg); | |
| z-index: 30; | |
| display: none; | |
| } | |
| .game-over h2 { | |
| color: var(--danger-color); | |
| margin-bottom: 20px; | |
| font-size: 2rem; | |
| } | |
| .game-over p { | |
| margin-bottom: 20px; | |
| font-size: 1.2rem; | |
| color: var(--dark-color); | |
| } | |
| .restart-btn { | |
| background: linear-gradient(135deg, var(--primary-color), var(--secondary-color)); | |
| color: white; | |
| border: none; | |
| padding: 15px 30px; | |
| font-size: 1.1rem; | |
| border-radius: 50px; | |
| cursor: pointer; | |
| transition: all 0.3s ease; | |
| box-shadow: var(--shadow); | |
| } | |
| .restart-btn:hover { | |
| transform: translateY(-3px); | |
| box-shadow: var(--shadow-lg); | |
| } | |
| .controls { | |
| position: absolute; | |
| bottom: 20px; | |
| left: 50%; | |
| transform: translateX(-50%); | |
| display: flex; | |
| gap: 20px; | |
| z-index: 20; | |
| } | |
| .control-btn { | |
| background: rgba(255, 255, 255, 0.9); | |
| border: none; | |
| padding: 15px 25px; | |
| border-radius: 50px; | |
| cursor: pointer; | |
| font-size: 1rem; | |
| font-weight: bold; | |
| color: var(--dark-color); | |
| transition: all 0.3s ease; | |
| box-shadow: var(--shadow); | |
| } | |
| .control-btn:hover { | |
| background: white; | |
| transform: translateY(-2px); | |
| box-shadow: var(--shadow-lg); | |
| } | |
| .start-screen { | |
| position: absolute; | |
| top: 0; | |
| left: 0; | |
| right: 0; | |
| bottom: 0; | |
| background: rgba(0, 0, 0, 0.7); | |
| display: flex; | |
| flex-direction: column; | |
| align-items: center; | |
| justify-content: center; | |
| z-index: 40; | |
| border-radius: 15px; | |
| } | |
| .start-screen h1 { | |
| color: white; | |
| font-size: 3rem; | |
| margin-bottom: 20px; | |
| text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3); | |
| } | |
| .start-screen p { | |
| color: white; | |
| margin-bottom: 30px; | |
| font-size: 1.2rem; | |
| } | |
| .start-btn { | |
| background: linear-gradient(135deg, var(--accent-color), #f39c12); | |
| color: white; | |
| border: none; | |
| padding: 20px 40px; | |
| font-size: 1.5rem; | |
| border-radius: 50px; | |
| cursor: pointer; | |
| transition: all 0.3s ease; | |
| box-shadow: var(--shadow-lg); | |
| } | |
| .start-btn:hover { | |
| transform: scale(1.05); | |
| box-shadow: 0 15px 20px rgba(0, 0, 0, 0.3); | |
| } | |
| .instructions { | |
| position: absolute; | |
| top: 50%; | |
| left: 50%; | |
| transform: translate(-50%, -50%); | |
| background: rgba(255, 255, 255, 0.9); | |
| padding: 20px; | |
| border-radius: 15px; | |
| text-align: center; | |
| max-width: 300px; | |
| z-index: 30; | |
| display: none; | |
| } | |
| .instructions h3 { | |
| color: var(--dark-color); | |
| margin-bottom: 15px; | |
| } | |
| .instructions p { | |
| color: var(--dark-color); | |
| margin-bottom: 10px; | |
| font-size: 1.1rem; | |
| } | |
| @media (max-width: 768px) { | |
| .game-container { | |
| padding: 10px; | |
| } | |
| .score-display { | |
| font-size: 2rem; | |
| padding: 8px 15px; | |
| } | |
| .game-over h2 { | |
| font-size: 1.5rem; | |
| } | |
| .game-over p { | |
| font-size: 1rem; | |
| } | |
| .restart-btn { | |
| padding: 12px 25px; | |
| font-size: 1rem; | |
| } | |
| .start-screen h1 { | |
| font-size: 2rem; | |
| } | |
| } | |
| @media (max-width: 480px) { | |
| .controls { | |
| flex-direction: column; | |
| gap: 10px; | |
| } | |
| .control-btn { | |
| padding: 12px 20px; | |
| font-size: 0.9rem; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="header"> | |
| <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank"> | |
| Built with anycoder | |
| </a> | |
| </div> | |
| <div class="game-container"> | |
| <div class="game-canvas" id="gameCanvas"> | |
| <div class="bird" id="bird"></div> | |
| <div class="score-display" id="scoreDisplay">0</div> | |
| <div class="start-screen" id="startScreen"> | |
| <h1>🐦 Flapi Birb</h1> | |
| <p>Tap or press SPACE to fly!</p> | |
| <button class="start-btn" id="startBtn">Start Game</button> | |
| </div> | |
| <div class="game-over" id="gameOver"> | |
| <h2>Game Over!</h2> | |
| <p>Your Score: <span id="finalScore">0</span></p> | |
| <button class="restart-btn" id="restartBtn">Play Again</button> | |
| </div> | |
| <div class="instructions" id="instructions"> | |
| <h3>How to Play</h3> | |
| <p>🎮 Press SPACE or tap the screen to make the bird fly</p> | |
| <p>🎯 Avoid the pipes and score points</p> | |
| <p>🏆 Try to beat your high score!</p> | |
| </div> | |
| </div> | |
| <div class="controls"> | |
| <button class="control-btn" id="pauseBtn">Pause</button> | |
| <button class="control-btn" id="soundBtn">🔊 Sound</button> | |
| </div> | |
| </div> | |
| <script> | |
| class FlappyBird { | |
| constructor() { | |
| this.canvas = document.getElementById('gameCanvas'); | |
| this.bird = document.getElementById('bird'); | |
| this.scoreDisplay = document.getElementById('scoreDisplay'); | |
| this.gameOverScreen = document.getElementById('gameOver'); | |
| this.finalScore = document.getElementById('finalScore'); | |
| this.startScreen = document.getElementById('startScreen'); | |
| this.instructions = document.getElementById('instructions'); | |
| this.birdY = 50; | |
| this.birdVelocity = 0; | |
| this.gravity = 0.5; | |
| this.jumpStrength = -8; | |
| this.pipes = []; | |
| this.score = 0; | |
| this.gameRunning = false; | |
| this.gamePaused = false; | |
| this.soundEnabled = true; | |
| this.highScore = localStorage.getItem('flappyHighScore') || 0; | |
| this.pipeGap = 150; | |
| this.pipeWidth = 60; | |
| this.pipeSpeed = 3; | |
| this.pipeInterval = 2000; | |
| this.lastPipeTime = 0; | |
| this.init(); | |
| } | |
| init() { | |
| document.getElementById('startBtn').addEventListener('click', () => this.startGame()); | |
| document.getElementById('restartBtn').addEventListener('click', () => this.restartGame()); | |
| document.getElementById('pauseBtn').addEventListener('click', () => this.togglePause()); | |
| document.getElementById('soundBtn').addEventListener('click', () => this.toggleSound()); | |
| document.addEventListener('keydown', (e) => { | |
| if (e.code === 'Space') { | |
| e.preventDefault(); | |
| if (this.gameRunning && !this.gamePaused) { | |
| this.jump(); | |
| } | |
| } | |
| }); | |
| this.canvas.addEventListener('click', () => { | |
| if (this.gameRunning && !this.gamePaused) { | |
| this.jump(); | |
| } | |
| }); | |
| // Create initial clouds | |
| this.createClouds(); | |
| } | |
| startGame() { | |
| this.startScreen.style.display = 'none'; | |
| this.instructions.style.display = 'block'; | |
| setTimeout(() => { | |
| this.instructions.style.display = 'none'; | |
| this.gameRunning = true; | |
| this.gameLoop(); | |
| }, 3000); | |
| } | |
| restartGame() { | |
| this.gameOverScreen.style.display = 'none'; | |
| this.pipes = []; | |
| this.score = 0; | |
| this.scoreDisplay.textContent = '0'; | |
| this.birdY = 50; | |
| this.birdVelocity = 0; | |
| this.updateBirdPosition(); | |
| this.gameRunning = true; | |
| this.gamePaused = false; | |
| this.gameLoop(); | |
| } | |
| togglePause() { | |
| if (this.gameRunning) { | |
| this.gamePaused = !this.gamePaused; | |
| document.getElementById('pauseBtn').textContent = this.gamePaused ? 'Resume' : 'Pause'; | |
| if (!this.gamePaused) { | |
| this.gameLoop(); | |
| } | |
| } | |
| } | |
| toggleSound() { | |
| this.soundEnabled = !this.soundEnabled; | |
| document.getElementById('soundBtn').textContent = this.soundEnabled ? '🔊 Sound' : '🔇 Sound'; | |
| } | |
| jump() { | |
| this.birdVelocity = this.jumpStrength; | |
| this.bird.style.transform = 'translateY(-50%) rotate(-20deg)'; | |
| setTimeout(() => { | |
| this.bird.style.transform = 'translateY(-50%) rotate(0deg)'; | |
| }, 100); | |
| } | |
| createPipes() { | |
| const pipeHeight = Math.random() * 200 + 100; | |
| const pipeTop = document.createElement('div'); | |
| const pipeBottom = document.createElement('div'); | |
| pipeTop.className = 'pipe pipe-top'; | |
| pipeBottom.className = 'pipe pipe-bottom'; | |
| pipeTop.style.height = `${pipeHeight}px`; | |
| pipeBottom.style.height = `${this.canvas.offsetHeight - pipeHeight - this.pipeGap}px`; | |
| pipeTop.style.left = `${this.canvas.offsetWidth}px`; | |
| pipeBottom.style.left = `${this.canvas.offsetWidth}px`; | |
| this.canvas.appendChild(pipeTop); | |
| this.canvas.appendChild(pipeBottom); | |
| this.pipes.push({ | |
| top: pipeTop, | |
| bottom: pipeBottom, | |
| passed: false, | |
| x: this.canvas.offsetWidth | |
| }); | |
| } | |
| createClouds() { | |
| for (let i = 0; i < 5; i++) { | |
| const cloud = document.createElement('div'); | |
| cloud.className = 'cloud'; | |
| cloud.style.width = `${Math.random() * 60 + 40}px`; | |
| cloud.style.height = `${Math.random() * 30 + 20}px`; | |
| cloud.style.top = `${Math.random() * 50}%`; | |
| cloud.style.animationDuration = `${Math.random() * 20 + 15}s`; | |
| cloud.style.animationDelay = `${Math.random() * 10}s`; | |
| this.canvas.appendChild(cloud); | |
| } | |
| } | |
| updateBirdPosition() { | |
| this.bird.style.top = `${this.birdY}%`; | |
| } | |
| checkCollision(pipe) { | |
| const birdRect = this.bird.getBoundingClientRect(); | |
| const topPipeRect = pipe.top.getBoundingClientRect(); | |
| const bottomPipeRect = pipe.bottom.getBoundingClientRect(); | |
| if (birdRect.right > topPipeRect.left && | |
| birdRect.left < topPipeRect.right && | |
| birdRect.top < topPipeRect.bottom) { | |
| return true; | |
| } | |
| if (birdRect.right > bottomPipeRect.left && | |
| birdRect.left < bottomPipeRect.right && | |
| birdRect.bottom > bottomPipeRect.top) { | |
| return true; | |
| } | |
| return false; | |
| } | |
| checkBoundaries() { | |
| const birdRect = this.bird.getBoundingClientRect(); | |
| const canvasRect = this.canvas.getBoundingClientRect(); | |
| if (birdRect.top < canvasRect.top || birdRect.bottom > canvasRect.bottom) { | |
| return true; | |
| } | |
| return false; | |
| } | |
| updateScore(pipe) { | |
| if (!pipe.passed && pipe.x + this.pipeWidth < this.bird.getBoundingClientRect().left) { | |
| pipe.passed = true; | |
| this.score++; | |
| this.scoreDisplay.textContent = this.score; | |
| if (this.score > this.highScore) { | |
| this.highScore = this.score; | |
| localStorage.setItem('flappyHighScore', this.highScore); | |
| } | |
| } | |
| } | |
| gameLoop() { | |
| if (!this.gameRunning || this.gamePaused) return; | |
| // Update bird position | |
| this.birdVelocity += this.gravity; | |
| this.birdY += this.birdVelocity * 0.5; | |
| this.updateBirdPosition(); | |
| // Create new pipes | |
| const currentTime = Date.now(); | |
| if (currentTime - this.lastPipeTime > this.pipeInterval) { | |
| this.createPipes(); | |
| this.lastPipeTime = currentTime; | |
| } | |
| // Update pipes | |
| this.pipes = this.pipes.filter(pipe => { | |
| pipe.x -= this.pipeSpeed; | |
| pipe.top.style.left = `${pipe.x}px`; | |
| pipe.bottom.style.left = `${pipe.x}px`; | |
| // Check collision | |
| if (this.checkCollision(pipe)) { | |
| this.endGame(); | |
| return false; | |
| } | |
| // Check boundaries | |
| if (this.checkBoundaries()) { | |
| this.endGame(); | |
| return false; | |
| } | |
| // Update score | |
| this.updateScore(pipe); | |
| // Remove pipes that are off screen | |
| if (pipe.x + this.pipeWidth < 0) { | |
| pipe.top.remove(); | |
| pipe.bottom.remove(); | |
| return false; | |
| } | |
| return true; | |
| }); | |
| requestAnimationFrame(() => this.gameLoop()); | |
| } | |
| endGame() { | |
| this.gameRunning = false; | |
| this.finalScore.textContent = this.score; | |
| this.gameOverScreen.style.display = 'block'; | |
| // Add celebration effect | |
| this.bird.style.transform = 'translateY(-50%) rotate(90deg)'; | |
| } | |
| } | |
| // Initialize the game when the page loads | |
| window.addEventListener('load', () => { | |
| new FlappyBird(); | |
| }); | |
| </script> | |
| </body> | |
| </html> |