Spaces:
Running
Running
File size: 13,987 Bytes
ad1b4a1 e26fbc6 ad1b4a1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flappy Bird</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
@keyframes flap {
0%, 100% { transform: rotate(-20deg); }
50% { transform: rotate(20deg); }
}
@keyframes scrollBackground {
0% { background-position: 0 0; }
100% { background-position: -100% 0; }
}
.flap-animation {
animation: flap 0.3s ease-in-out;
}
.scrolling-bg {
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><rect width="50" height="50" x="0" y="0" fill="%234fd1c5"/><rect width="50" height="50" x="50" y="50" fill="%234fd1c5"/></svg>');
background-size: 100px 100px;
animation: scrollBackground 10s linear infinite;
}
.pipe {
position: absolute;
width: 60px;
background-color: #38a169;
border-left: 4px solid #2f855a;
border-right: 4px solid #2f855a;
}
.pipe-top {
top: 0;
border-top: 4px solid #2f855a;
border-radius: 0 0 8px 8px;
}
.pipe-bottom {
bottom: 0;
border-bottom: 4px solid #2f855a;
border-radius: 8px 8px 0 0;
}
.bird {
position: absolute;
width: 40px;
height: 30px;
background-color: #f6e05e;
border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
z-index: 10;
}
.bird:before {
content: '';
position: absolute;
width: 10px;
height: 10px;
background-color: #000;
border-radius: 50%;
top: 10px;
right: 5px;
}
.bird:after {
content: '';
position: absolute;
width: 15px;
height: 8px;
background-color: #dd6b20;
border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
top: 15px;
right: -5px;
}
.wing {
position: absolute;
width: 20px;
height: 15px;
background-color: #ecc94b;
border-radius: 50%;
top: 5px;
left: -10px;
transform-origin: right center;
}
.game-container {
position: relative;
width: 100%;
max-width: 400px;
height: 600px;
margin: 0 auto;
overflow: hidden;
background-color: #4fd1c5;
}
.ground {
position: absolute;
bottom: 0;
width: 100%;
height: 30px;
background-color: #dd6b20;
border-top: 4px solid #c05621;
}
.score-display {
position: absolute;
top: 20px;
width: 100%;
text-align: center;
font-size: 24px;
font-weight: bold;
color: white;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
z-index: 20;
}
.game-screen {
position: absolute;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: rgba(0, 0, 0, 0.5);
z-index: 30;
}
.game-title {
font-size: 48px;
font-weight: bold;
color: white;
margin-bottom: 20px;
text-shadow: 4px 4px 8px rgba(0, 0, 0, 0.8);
}
.game-button {
padding: 12px 24px;
font-size: 20px;
font-weight: bold;
background-color: #f6e05e;
color: #2d3748;
border: none;
border-radius: 8px;
cursor: pointer;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
transition: all 0.2s;
}
.game-button:hover {
transform: translateY(-2px);
box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
}
.game-button:active {
transform: translateY(0);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body class="bg-gray-100 flex items-center justify-center min-h-screen">
<div class="game-container scrolling-bg">
<div id="score" class="score-display">0</div>
<div id="bird" class="bird">
<div class="wing"></div>
</div>
<div class="ground"></div>
<div id="start-screen" class="game-screen">
<h1 class="game-title">Flappy Bird</h1>
<button id="start-button" class="game-button">Play</button>
</div>
<div id="game-over-screen" class="game-screen hidden">
<h1 class="game-title">Game Over</h1>
<div id="final-score" class="text-white text-2xl mb-6">Score: 0</div>
<button id="restart-button" class="game-button">Play Again</button>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
// Game elements
const gameContainer = document.querySelector('.game-container');
const bird = document.getElementById('bird');
const scoreDisplay = document.getElementById('score');
const startScreen = document.getElementById('start-screen');
const gameOverScreen = document.getElementById('game-over-screen');
const finalScoreDisplay = document.getElementById('final-score');
const startButton = document.getElementById('start-button');
const restartButton = document.getElementById('restart-button');
const wing = document.querySelector('.wing');
// Game variables
let gameRunning = false;
let score = 0;
let birdY = 300;
let birdVelocity = 0;
let gravity = 0.5;
let jumpForce = -10;
let pipes = [];
let pipeGap = 150;
let pipeFrequency = 1500; // ms
let lastPipeTime = 0;
let gameSpeed = 2;
let animationId;
// Game dimensions
const gameWidth = gameContainer.offsetWidth;
const gameHeight = gameContainer.offsetHeight;
const birdWidth = 40;
const birdHeight = 30;
const groundHeight = 30;
// Initialize bird position
bird.style.left = '100px';
bird.style.top = birdY + 'px';
// Event listeners
startButton.addEventListener('click', startGame);
restartButton.addEventListener('click', startGame);
gameContainer.addEventListener('click', () => {
if (gameRunning) {
jump();
}
});
// Keyboard controls
document.addEventListener('keydown', (e) => {
if ((e.code === 'Space' || e.key === 'ArrowUp') && gameRunning) {
jump();
}
});
// Jump function
function jump() {
birdVelocity = jumpForce;
bird.classList.add('flap-animation');
wing.style.transform = 'rotate(-60deg)';
setTimeout(() => {
bird.classList.remove('flap-animation');
wing.style.transform = 'rotate(0deg)';
}, 300);
}
// Start game
function startGame() {
// Reset game state
gameRunning = true;
score = 0;
birdY = 300;
birdVelocity = 0;
pipes = [];
lastPipeTime = 0;
// Update UI
scoreDisplay.textContent = score;
startScreen.classList.add('hidden');
gameOverScreen.classList.add('hidden');
// Clear existing pipes
document.querySelectorAll('.pipe').forEach(pipe => pipe.remove());
// Start game loop
gameLoop();
}
// Game over
function gameOver() {
gameRunning = false;
finalScoreDisplay.textContent = `Score: ${score}`;
gameOverScreen.classList.remove('hidden');
cancelAnimationFrame(animationId);
}
// Create new pipe
function createPipe() {
const pipeHeight = Math.floor(Math.random() * (gameHeight - pipeGap - groundHeight - 100)) + 50;
const topPipe = document.createElement('div');
topPipe.className = 'pipe pipe-top';
topPipe.style.height = pipeHeight + 'px';
topPipe.style.left = gameWidth + 'px';
gameContainer.appendChild(topPipe);
const bottomPipe = document.createElement('div');
bottomPipe.className = 'pipe pipe-bottom';
bottomPipe.style.height = (gameHeight - pipeHeight - pipeGap - groundHeight) + 'px';
bottomPipe.style.left = gameWidth + 'px';
gameContainer.appendChild(bottomPipe);
pipes.push({
top: topPipe,
bottom: bottomPipe,
x: gameWidth,
passed: false
});
}
// Update pipes
function updatePipes() {
const currentTime = Date.now();
if (currentTime - lastPipeTime > pipeFrequency) {
createPipe();
lastPipeTime = currentTime;
}
for (let i = pipes.length - 1; i >= 0; i--) {
const pipe = pipes[i];
pipe.x -= gameSpeed;
pipe.top.style.left = pipe.x + 'px';
pipe.bottom.style.left = pipe.x + 'px';
// Check if pipe is passed
if (!pipe.passed && pipe.x < 100 - birdWidth) {
pipe.passed = true;
score++;
scoreDisplay.textContent = score;
// Increase difficulty
if (score % 5 === 0) {
gameSpeed += 0.3;
pipeFrequency = Math.max(1200, pipeFrequency - 50);
}
}
// Remove pipes that are off screen
if (pipe.x < -60) {
pipe.top.remove();
pipe.bottom.remove();
pipes.splice(i, 1);
}
}
}
// Check collisions
function checkCollisions() {
// Ground collision
if (birdY + birdHeight > gameHeight - groundHeight) {
return true;
}
// Ceiling collision
if (birdY < 0) {
return true;
}
// Pipe collisions
for (const pipe of pipes) {
if (
100 + birdWidth > pipe.x &&
100 < pipe.x + 60 &&
(birdY < pipe.top.offsetHeight ||
birdY + birdHeight > gameHeight - pipe.bottom.offsetHeight - groundHeight)
) {
return true;
}
}
return false;
}
// Game loop
function gameLoop() {
if (!gameRunning) return;
// Update bird position
birdVelocity += gravity;
birdY += birdVelocity;
bird.style.top = birdY + 'px';
// Update pipes
updatePipes();
// Check collisions
if (checkCollisions()) {
gameOver();
return;
}
animationId = requestAnimationFrame(gameLoop);
}
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=MarkBrianAdam/something-flappy" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |