Spaces:
Running
Running
Add 2 files
Browse files- README.md +7 -5
- index.html +493 -19
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: flappybirdgame
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: pink
|
| 5 |
+
colorTo: gray
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,493 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Flappy Bird</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<style>
|
| 9 |
+
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');
|
| 10 |
+
|
| 11 |
+
body {
|
| 12 |
+
font-family: 'Press Start 2P', cursive;
|
| 13 |
+
overflow: hidden;
|
| 14 |
+
background-color: #70c5ce;
|
| 15 |
+
touch-action: manipulation;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
#game-container {
|
| 19 |
+
position: relative;
|
| 20 |
+
width: 100vw;
|
| 21 |
+
height: 100vh;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
#game-canvas {
|
| 25 |
+
position: absolute;
|
| 26 |
+
top: 0;
|
| 27 |
+
left: 0;
|
| 28 |
+
width: 100%;
|
| 29 |
+
height: 100%;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
.pipe {
|
| 33 |
+
position: absolute;
|
| 34 |
+
width: 80px;
|
| 35 |
+
background-color: #5f9e5f;
|
| 36 |
+
border: 5px solid #3a6b3a;
|
| 37 |
+
box-sizing: border-box;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
.bird {
|
| 41 |
+
position: absolute;
|
| 42 |
+
width: 40px;
|
| 43 |
+
height: 30px;
|
| 44 |
+
background-color: #ffcc00;
|
| 45 |
+
border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
|
| 46 |
+
z-index: 10;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
.bird:before {
|
| 50 |
+
content: '';
|
| 51 |
+
position: absolute;
|
| 52 |
+
width: 12px;
|
| 53 |
+
height: 12px;
|
| 54 |
+
background-color: #ff6600;
|
| 55 |
+
border-radius: 50%;
|
| 56 |
+
top: 5px;
|
| 57 |
+
right: 5px;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
.bird:after {
|
| 61 |
+
content: '';
|
| 62 |
+
position: absolute;
|
| 63 |
+
width: 8px;
|
| 64 |
+
height: 3px;
|
| 65 |
+
background-color: #000;
|
| 66 |
+
border-radius: 50%;
|
| 67 |
+
top: 12px;
|
| 68 |
+
right: 10px;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
.wing {
|
| 72 |
+
position: absolute;
|
| 73 |
+
width: 30px;
|
| 74 |
+
height: 15px;
|
| 75 |
+
background-color: #ffcc00;
|
| 76 |
+
border-radius: 50% 50% 0 0;
|
| 77 |
+
top: 15px;
|
| 78 |
+
left: -15px;
|
| 79 |
+
transform-origin: right center;
|
| 80 |
+
animation: flap 0.3s infinite alternate;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
@keyframes flap {
|
| 84 |
+
0% { transform: rotateY(0deg) rotateZ(0deg); }
|
| 85 |
+
100% { transform: rotateY(60deg) rotateZ(20deg); }
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.ground {
|
| 89 |
+
position: absolute;
|
| 90 |
+
bottom: 0;
|
| 91 |
+
width: 100%;
|
| 92 |
+
height: 100px;
|
| 93 |
+
background-color: #deb887;
|
| 94 |
+
border-top: 5px solid #8b4513;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
.cloud {
|
| 98 |
+
position: absolute;
|
| 99 |
+
background-color: white;
|
| 100 |
+
border-radius: 50%;
|
| 101 |
+
opacity: 0.8;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
#score-display {
|
| 105 |
+
position: absolute;
|
| 106 |
+
top: 20px;
|
| 107 |
+
left: 0;
|
| 108 |
+
right: 0;
|
| 109 |
+
text-align: center;
|
| 110 |
+
color: white;
|
| 111 |
+
font-size: 24px;
|
| 112 |
+
text-shadow: 2px 2px 0 #000;
|
| 113 |
+
z-index: 100;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
#game-over {
|
| 117 |
+
position: absolute;
|
| 118 |
+
top: 0;
|
| 119 |
+
left: 0;
|
| 120 |
+
width: 100%;
|
| 121 |
+
height: 100%;
|
| 122 |
+
background-color: rgba(0, 0, 0, 0.7);
|
| 123 |
+
display: flex;
|
| 124 |
+
flex-direction: column;
|
| 125 |
+
justify-content: center;
|
| 126 |
+
align-items: center;
|
| 127 |
+
color: white;
|
| 128 |
+
z-index: 200;
|
| 129 |
+
display: none;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
#start-screen {
|
| 133 |
+
position: absolute;
|
| 134 |
+
top: 0;
|
| 135 |
+
left: 0;
|
| 136 |
+
width: 100%;
|
| 137 |
+
height: 100%;
|
| 138 |
+
background-color: rgba(0, 0, 0, 0.5);
|
| 139 |
+
display: flex;
|
| 140 |
+
flex-direction: column;
|
| 141 |
+
justify-content: center;
|
| 142 |
+
align-items: center;
|
| 143 |
+
color: white;
|
| 144 |
+
z-index: 200;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
.btn {
|
| 148 |
+
background-color: #ffcc00;
|
| 149 |
+
color: #333;
|
| 150 |
+
border: none;
|
| 151 |
+
padding: 15px 30px;
|
| 152 |
+
font-size: 16px;
|
| 153 |
+
margin-top: 20px;
|
| 154 |
+
cursor: pointer;
|
| 155 |
+
border-radius: 5px;
|
| 156 |
+
font-family: 'Press Start 2P', cursive;
|
| 157 |
+
box-shadow: 0 4px 0 #cc9900;
|
| 158 |
+
transition: all 0.1s;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
.btn:active {
|
| 162 |
+
transform: translateY(4px);
|
| 163 |
+
box-shadow: 0 0 0 #cc9900;
|
| 164 |
+
}
|
| 165 |
+
</style>
|
| 166 |
+
</head>
|
| 167 |
+
<body class="flex items-center justify-center min-h-screen">
|
| 168 |
+
<div id="game-container" class="relative overflow-hidden">
|
| 169 |
+
<div id="score-display">0</div>
|
| 170 |
+
|
| 171 |
+
<div id="start-screen">
|
| 172 |
+
<h1 class="text-4xl mb-8 text-center">FLAPPY BIRD</h1>
|
| 173 |
+
<p class="mb-4 text-center">Press SPACE or tap screen to jump</p>
|
| 174 |
+
<button id="start-btn" class="btn">START GAME</button>
|
| 175 |
+
</div>
|
| 176 |
+
|
| 177 |
+
<div id="game-over">
|
| 178 |
+
<h1 class="text-4xl mb-8">GAME OVER</h1>
|
| 179 |
+
<p id="final-score" class="text-2xl mb-4">Score: 0</p>
|
| 180 |
+
<p id="high-score" class="text-xl mb-8">High Score: 0</p>
|
| 181 |
+
<button id="restart-btn" class="btn">PLAY AGAIN</button>
|
| 182 |
+
</div>
|
| 183 |
+
|
| 184 |
+
<div id="bird" class="bird">
|
| 185 |
+
<div class="wing"></div>
|
| 186 |
+
</div>
|
| 187 |
+
|
| 188 |
+
<div id="ground" class="ground"></div>
|
| 189 |
+
</div>
|
| 190 |
+
|
| 191 |
+
<script>
|
| 192 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 193 |
+
// Game elements
|
| 194 |
+
const gameContainer = document.getElementById('game-container');
|
| 195 |
+
const bird = document.getElementById('bird');
|
| 196 |
+
const ground = document.getElementById('ground');
|
| 197 |
+
const scoreDisplay = document.getElementById('score-display');
|
| 198 |
+
const gameOverScreen = document.getElementById('game-over');
|
| 199 |
+
const finalScoreDisplay = document.getElementById('final-score');
|
| 200 |
+
const highScoreDisplay = document.getElementById('high-score');
|
| 201 |
+
const startScreen = document.getElementById('start-screen');
|
| 202 |
+
const startBtn = document.getElementById('start-btn');
|
| 203 |
+
const restartBtn = document.getElementById('restart-btn');
|
| 204 |
+
|
| 205 |
+
// Game variables
|
| 206 |
+
let gameRunning = false;
|
| 207 |
+
let score = 0;
|
| 208 |
+
let highScore = localStorage.getItem('flappyHighScore') || 0;
|
| 209 |
+
let gravity = 0.5;
|
| 210 |
+
let velocity = 0;
|
| 211 |
+
let birdPosition = 250;
|
| 212 |
+
let pipes = [];
|
| 213 |
+
let pipeGap = 150;
|
| 214 |
+
let pipeWidth = 80;
|
| 215 |
+
let pipeFrequency = 1500; // ms
|
| 216 |
+
let lastPipeTime = 0;
|
| 217 |
+
let gameSpeed = 2;
|
| 218 |
+
let clouds = [];
|
| 219 |
+
let lastCloudTime = 0;
|
| 220 |
+
let cloudFrequency = 3000;
|
| 221 |
+
|
| 222 |
+
// Initialize game
|
| 223 |
+
function initGame() {
|
| 224 |
+
// Set initial positions
|
| 225 |
+
birdPosition = gameContainer.clientHeight / 2 - 50;
|
| 226 |
+
bird.style.top = `${birdPosition}px`;
|
| 227 |
+
bird.style.left = '100px';
|
| 228 |
+
|
| 229 |
+
// Clear existing pipes
|
| 230 |
+
pipes.forEach(pipe => {
|
| 231 |
+
if (pipe.element && pipe.element.parentNode) {
|
| 232 |
+
pipe.element.parentNode.removeChild(pipe.element);
|
| 233 |
+
}
|
| 234 |
+
});
|
| 235 |
+
pipes = [];
|
| 236 |
+
|
| 237 |
+
// Clear clouds
|
| 238 |
+
clouds.forEach(cloud => {
|
| 239 |
+
if (cloud.element && cloud.element.parentNode) {
|
| 240 |
+
cloud.element.parentNode.removeChild(cloud.element);
|
| 241 |
+
}
|
| 242 |
+
});
|
| 243 |
+
clouds = [];
|
| 244 |
+
|
| 245 |
+
// Reset game variables
|
| 246 |
+
score = 0;
|
| 247 |
+
velocity = 0;
|
| 248 |
+
scoreDisplay.textContent = '0';
|
| 249 |
+
gameOverScreen.style.display = 'none';
|
| 250 |
+
highScoreDisplay.textContent = `High Score: ${highScore}`;
|
| 251 |
+
|
| 252 |
+
// Start game loop
|
| 253 |
+
gameRunning = true;
|
| 254 |
+
lastPipeTime = Date.now();
|
| 255 |
+
lastCloudTime = Date.now();
|
| 256 |
+
requestAnimationFrame(gameLoop);
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
// Game loop
|
| 260 |
+
function gameLoop() {
|
| 261 |
+
if (!gameRunning) return;
|
| 262 |
+
|
| 263 |
+
const now = Date.now();
|
| 264 |
+
const deltaTime = 16; // Approximate for 60fps
|
| 265 |
+
|
| 266 |
+
// Apply gravity
|
| 267 |
+
velocity += gravity;
|
| 268 |
+
birdPosition += velocity;
|
| 269 |
+
bird.style.top = `${birdPosition}px`;
|
| 270 |
+
|
| 271 |
+
// Rotate bird based on velocity
|
| 272 |
+
const rotation = Math.min(Math.max(velocity * 3, -30), 90);
|
| 273 |
+
bird.style.transform = `rotate(${rotation}deg)`;
|
| 274 |
+
|
| 275 |
+
// Generate pipes
|
| 276 |
+
if (now - lastPipeTime > pipeFrequency) {
|
| 277 |
+
createPipe();
|
| 278 |
+
lastPipeTime = now;
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
// Generate clouds
|
| 282 |
+
if (now - lastCloudTime > cloudFrequency) {
|
| 283 |
+
createCloud();
|
| 284 |
+
lastCloudTime = now;
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
// Move pipes
|
| 288 |
+
movePipes(deltaTime);
|
| 289 |
+
|
| 290 |
+
// Move clouds
|
| 291 |
+
moveClouds(deltaTime);
|
| 292 |
+
|
| 293 |
+
// Check collisions
|
| 294 |
+
if (checkCollisions()) {
|
| 295 |
+
gameOver();
|
| 296 |
+
return;
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
// Continue game loop
|
| 300 |
+
requestAnimationFrame(gameLoop);
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
// Create a new pipe
|
| 304 |
+
function createPipe() {
|
| 305 |
+
const containerHeight = gameContainer.clientHeight;
|
| 306 |
+
const minHeight = 50;
|
| 307 |
+
const maxHeight = containerHeight - ground.clientHeight - pipeGap - minHeight;
|
| 308 |
+
const topHeight = Math.floor(Math.random() * (maxHeight - minHeight + 1)) + minHeight;
|
| 309 |
+
|
| 310 |
+
// Create top pipe
|
| 311 |
+
const topPipe = document.createElement('div');
|
| 312 |
+
topPipe.className = 'pipe';
|
| 313 |
+
topPipe.style.height = `${topHeight}px`;
|
| 314 |
+
topPipe.style.top = '0';
|
| 315 |
+
topPipe.style.left = `${gameContainer.clientWidth}px`;
|
| 316 |
+
gameContainer.appendChild(topPipe);
|
| 317 |
+
|
| 318 |
+
// Create bottom pipe
|
| 319 |
+
const bottomPipe = document.createElement('div');
|
| 320 |
+
bottomPipe.className = 'pipe';
|
| 321 |
+
bottomPipe.style.height = `${containerHeight - ground.clientHeight - topHeight - pipeGap}px`;
|
| 322 |
+
bottomPipe.style.bottom = `${ground.clientHeight}px`;
|
| 323 |
+
bottomPipe.style.left = `${gameContainer.clientWidth}px`;
|
| 324 |
+
gameContainer.appendChild(bottomPipe);
|
| 325 |
+
|
| 326 |
+
pipes.push({
|
| 327 |
+
element: topPipe,
|
| 328 |
+
x: gameContainer.clientWidth,
|
| 329 |
+
height: topHeight,
|
| 330 |
+
passed: false
|
| 331 |
+
});
|
| 332 |
+
|
| 333 |
+
pipes.push({
|
| 334 |
+
element: bottomPipe,
|
| 335 |
+
x: gameContainer.clientWidth,
|
| 336 |
+
height: containerHeight - ground.clientHeight - topHeight - pipeGap,
|
| 337 |
+
passed: false
|
| 338 |
+
});
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
// Create a cloud
|
| 342 |
+
function createCloud() {
|
| 343 |
+
const size = Math.floor(Math.random() * 50) + 30;
|
| 344 |
+
const cloud = document.createElement('div');
|
| 345 |
+
cloud.className = 'cloud';
|
| 346 |
+
cloud.style.width = `${size}px`;
|
| 347 |
+
cloud.style.height = `${size}px`;
|
| 348 |
+
cloud.style.top = `${Math.floor(Math.random() * (gameContainer.clientHeight / 2))}px`;
|
| 349 |
+
cloud.style.left = `${gameContainer.clientWidth}px`;
|
| 350 |
+
gameContainer.appendChild(cloud);
|
| 351 |
+
|
| 352 |
+
clouds.push({
|
| 353 |
+
element: cloud,
|
| 354 |
+
x: gameContainer.clientWidth,
|
| 355 |
+
y: parseInt(cloud.style.top),
|
| 356 |
+
speed: Math.random() * 0.5 + 0.5
|
| 357 |
+
});
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
// Move all pipes
|
| 361 |
+
function movePipes(deltaTime) {
|
| 362 |
+
for (let i = 0; i < pipes.length; i++) {
|
| 363 |
+
const pipe = pipes[i];
|
| 364 |
+
pipe.x -= gameSpeed;
|
| 365 |
+
pipe.element.style.left = `${pipe.x}px`;
|
| 366 |
+
|
| 367 |
+
// Check if pipe is passed by bird
|
| 368 |
+
if (!pipe.passed && pipe.x + pipeWidth < 100) {
|
| 369 |
+
pipe.passed = true;
|
| 370 |
+
if (i % 2 === 0) { // Only count for top pipe to avoid double counting
|
| 371 |
+
score++;
|
| 372 |
+
scoreDisplay.textContent = score;
|
| 373 |
+
|
| 374 |
+
// Increase difficulty
|
| 375 |
+
if (score % 5 === 0) {
|
| 376 |
+
gameSpeed += 0.2;
|
| 377 |
+
pipeFrequency = Math.max(1000, pipeFrequency - 100);
|
| 378 |
+
}
|
| 379 |
+
}
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
// Remove pipe if off screen
|
| 383 |
+
if (pipe.x + pipeWidth < 0) {
|
| 384 |
+
pipe.element.parentNode.removeChild(pipe.element);
|
| 385 |
+
pipes.splice(i, 1);
|
| 386 |
+
i--;
|
| 387 |
+
}
|
| 388 |
+
}
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
// Move all clouds
|
| 392 |
+
function moveClouds(deltaTime) {
|
| 393 |
+
for (let i = 0; i < clouds.length; i++) {
|
| 394 |
+
const cloud = clouds[i];
|
| 395 |
+
cloud.x -= cloud.speed;
|
| 396 |
+
cloud.element.style.left = `${cloud.x}px`;
|
| 397 |
+
|
| 398 |
+
// Remove cloud if off screen
|
| 399 |
+
if (cloud.x + parseInt(cloud.element.style.width) < 0) {
|
| 400 |
+
cloud.element.parentNode.removeChild(cloud.element);
|
| 401 |
+
clouds.splice(i, 1);
|
| 402 |
+
i--;
|
| 403 |
+
}
|
| 404 |
+
}
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
// Check for collisions
|
| 408 |
+
function checkCollisions() {
|
| 409 |
+
const birdRect = bird.getBoundingClientRect();
|
| 410 |
+
const containerRect = gameContainer.getBoundingClientRect();
|
| 411 |
+
|
| 412 |
+
// Check ground collision
|
| 413 |
+
if (birdRect.bottom >= containerRect.bottom - ground.clientHeight) {
|
| 414 |
+
return true;
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
// Check ceiling collision
|
| 418 |
+
if (birdRect.top <= containerRect.top) {
|
| 419 |
+
return true;
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
// Check pipe collisions
|
| 423 |
+
for (const pipe of pipes) {
|
| 424 |
+
const pipeRect = pipe.element.getBoundingClientRect();
|
| 425 |
+
|
| 426 |
+
if (
|
| 427 |
+
birdRect.right > pipeRect.left &&
|
| 428 |
+
birdRect.left < pipeRect.right &&
|
| 429 |
+
birdRect.bottom > pipeRect.top &&
|
| 430 |
+
birdRect.top < pipeRect.bottom
|
| 431 |
+
) {
|
| 432 |
+
return true;
|
| 433 |
+
}
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
return false;
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
// Game over
|
| 440 |
+
function gameOver() {
|
| 441 |
+
gameRunning = false;
|
| 442 |
+
|
| 443 |
+
// Update high score
|
| 444 |
+
if (score > highScore) {
|
| 445 |
+
highScore = score;
|
| 446 |
+
localStorage.setItem('flappyHighScore', highScore);
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
// Show game over screen
|
| 450 |
+
finalScoreDisplay.textContent = `Score: ${score}`;
|
| 451 |
+
highScoreDisplay.textContent = `High Score: ${highScore}`;
|
| 452 |
+
gameOverScreen.style.display = 'flex';
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
// Jump function
|
| 456 |
+
function jump() {
|
| 457 |
+
if (!gameRunning) return;
|
| 458 |
+
velocity = -10;
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
// Event listeners
|
| 462 |
+
document.addEventListener('keydown', (e) => {
|
| 463 |
+
if (e.code === 'Space') {
|
| 464 |
+
e.preventDefault();
|
| 465 |
+
jump();
|
| 466 |
+
}
|
| 467 |
+
});
|
| 468 |
+
|
| 469 |
+
gameContainer.addEventListener('click', () => {
|
| 470 |
+
jump();
|
| 471 |
+
});
|
| 472 |
+
|
| 473 |
+
gameContainer.addEventListener('touchstart', (e) => {
|
| 474 |
+
e.preventDefault();
|
| 475 |
+
jump();
|
| 476 |
+
});
|
| 477 |
+
|
| 478 |
+
startBtn.addEventListener('click', () => {
|
| 479 |
+
startScreen.style.display = 'none';
|
| 480 |
+
initGame();
|
| 481 |
+
});
|
| 482 |
+
|
| 483 |
+
restartBtn.addEventListener('click', () => {
|
| 484 |
+
gameOverScreen.style.display = 'none';
|
| 485 |
+
initGame();
|
| 486 |
+
});
|
| 487 |
+
|
| 488 |
+
// Initial setup
|
| 489 |
+
highScoreDisplay.textContent = `High Score: ${highScore}`;
|
| 490 |
+
});
|
| 491 |
+
</script>
|
| 492 |
+
<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=vatsal-p-wa/flappybirdgame" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 493 |
+
</html>
|