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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>Minimal Flappy Bird</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
margin: 0;
|
| 10 |
+
padding: 0;
|
| 11 |
+
box-sizing: border-box;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
body {
|
| 15 |
+
display: flex;
|
| 16 |
+
justify-content: center;
|
| 17 |
+
align-items: center;
|
| 18 |
+
min-height: 100vh;
|
| 19 |
+
background: linear-gradient(to bottom, #64b3f4, #c2e59c);
|
| 20 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 21 |
+
overflow: hidden;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
.game-container {
|
| 25 |
+
position: relative;
|
| 26 |
+
width: 360px;
|
| 27 |
+
text-align: center;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
canvas {
|
| 31 |
+
background: #70c5ce;
|
| 32 |
+
border-radius: 10px;
|
| 33 |
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
|
| 34 |
+
display: block;
|
| 35 |
+
margin: 0 auto;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
h1 {
|
| 39 |
+
color: #fff;
|
| 40 |
+
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
|
| 41 |
+
margin-bottom: 15px;
|
| 42 |
+
font-size: 2.5rem;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
.score-display {
|
| 46 |
+
position: absolute;
|
| 47 |
+
top: 20px;
|
| 48 |
+
left: 0;
|
| 49 |
+
right: 0;
|
| 50 |
+
text-align: center;
|
| 51 |
+
font-size: 50px;
|
| 52 |
+
font-weight: bold;
|
| 53 |
+
color: white;
|
| 54 |
+
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
|
| 55 |
+
z-index: 10;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
.instructions {
|
| 59 |
+
background: rgba(0, 0, 0, 0.7);
|
| 60 |
+
color: white;
|
| 61 |
+
padding: 15px;
|
| 62 |
+
border-radius: 10px;
|
| 63 |
+
margin-top: 20px;
|
| 64 |
+
font-size: 16px;
|
| 65 |
+
line-height: 1.5;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
.game-over {
|
| 69 |
+
position: absolute;
|
| 70 |
+
top: 50%;
|
| 71 |
+
left: 50%;
|
| 72 |
+
transform: translate(-50%, -50%);
|
| 73 |
+
background: rgba(0, 0, 0, 0.85);
|
| 74 |
+
color: white;
|
| 75 |
+
padding: 30px;
|
| 76 |
+
border-radius: 15px;
|
| 77 |
+
text-align: center;
|
| 78 |
+
display: none;
|
| 79 |
+
z-index: 20;
|
| 80 |
+
width: 80%;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
.game-over h2 {
|
| 84 |
+
font-size: 36px;
|
| 85 |
+
margin-bottom: 15px;
|
| 86 |
+
color: #ffcc00;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
.final-score {
|
| 90 |
+
font-size: 28px;
|
| 91 |
+
margin: 15px 0;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
button {
|
| 95 |
+
background: #ffcc00;
|
| 96 |
+
border: none;
|
| 97 |
+
padding: 12px 30px;
|
| 98 |
+
font-size: 18px;
|
| 99 |
+
border-radius: 50px;
|
| 100 |
+
cursor: pointer;
|
| 101 |
+
font-weight: bold;
|
| 102 |
+
margin-top: 15px;
|
| 103 |
+
transition: all 0.2s;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
button:hover {
|
| 107 |
+
background: #ffd84d;
|
| 108 |
+
transform: scale(1.05);
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
.pipe-counter {
|
| 112 |
+
position: absolute;
|
| 113 |
+
bottom: 20px;
|
| 114 |
+
left: 0;
|
| 115 |
+
right: 0;
|
| 116 |
+
text-align: center;
|
| 117 |
+
color: white;
|
| 118 |
+
font-size: 18px;
|
| 119 |
+
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
|
| 120 |
+
}
|
| 121 |
+
</style>
|
| 122 |
+
</head>
|
| 123 |
+
<body>
|
| 124 |
+
<div class="game-container">
|
| 125 |
+
<h1>Flappy Bird</h1>
|
| 126 |
+
<div class="score-display">0</div>
|
| 127 |
+
<canvas id="gameCanvas" width="360" height="640"></canvas>
|
| 128 |
+
<div class="pipe-counter">Pipes Passed: <span id="pipesPassed">0</span></div>
|
| 129 |
+
<div class="instructions">
|
| 130 |
+
<p>Press SPACE, CLICK, or TOUCH to flap your wings!</p>
|
| 131 |
+
<p>Avoid the pipes and don't hit the ground!</p>
|
| 132 |
+
</div>
|
| 133 |
+
<div class="game-over" id="gameOverScreen">
|
| 134 |
+
<h2>Game Over!</h2>
|
| 135 |
+
<div class="final-score">Score: <span id="finalScore">0</span></div>
|
| 136 |
+
<div>Pipes Passed: <span id="finalPipes">0</span></div>
|
| 137 |
+
<button id="restartButton">Play Again</button>
|
| 138 |
+
</div>
|
| 139 |
+
</div>
|
| 140 |
+
|
| 141 |
+
<script>
|
| 142 |
+
// Game variables
|
| 143 |
+
const canvas = document.getElementById('gameCanvas');
|
| 144 |
+
const ctx = canvas.getContext('2d');
|
| 145 |
+
const scoreDisplay = document.querySelector('.score-display');
|
| 146 |
+
const gameOverScreen = document.getElementById('gameOverScreen');
|
| 147 |
+
const finalScore = document.getElementById('finalScore');
|
| 148 |
+
const finalPipes = document.getElementById('finalPipes');
|
| 149 |
+
const restartButton = document.getElementById('restartButton');
|
| 150 |
+
const pipesPassedDisplay = document.getElementById('pipesPassed');
|
| 151 |
+
|
| 152 |
+
// Game state
|
| 153 |
+
let gameState = "start"; // start, playing, gameover
|
| 154 |
+
let score = 0;
|
| 155 |
+
let pipesPassed = 0;
|
| 156 |
+
let frames = 0;
|
| 157 |
+
|
| 158 |
+
// Bird properties
|
| 159 |
+
const bird = {
|
| 160 |
+
x: 50,
|
| 161 |
+
y: canvas.height / 2 - 10,
|
| 162 |
+
width: 34,
|
| 163 |
+
height: 24,
|
| 164 |
+
gravity: 0.5,
|
| 165 |
+
velocity: 0,
|
| 166 |
+
jump: -10,
|
| 167 |
+
|
| 168 |
+
draw: function() {
|
| 169 |
+
ctx.fillStyle = '#FFD700'; // Yellow body
|
| 170 |
+
ctx.beginPath();
|
| 171 |
+
ctx.arc(this.x, this.y, 15, 0, Math.PI * 2);
|
| 172 |
+
ctx.fill();
|
| 173 |
+
|
| 174 |
+
// Draw eye
|
| 175 |
+
ctx.fillStyle = 'black';
|
| 176 |
+
ctx.beginPath();
|
| 177 |
+
ctx.arc(this.x + 8, this.y - 3, 4, 0, Math.PI * 2);
|
| 178 |
+
ctx.fill();
|
| 179 |
+
|
| 180 |
+
// Draw beak
|
| 181 |
+
ctx.fillStyle = '#FF8C00';
|
| 182 |
+
ctx.beginPath();
|
| 183 |
+
ctx.moveTo(this.x + 15, this.y);
|
| 184 |
+
ctx.lineTo(this.x + 30, this.y);
|
| 185 |
+
ctx.lineTo(this.x + 15, this.y + 8);
|
| 186 |
+
ctx.fill();
|
| 187 |
+
|
| 188 |
+
// Draw wing
|
| 189 |
+
ctx.fillStyle = '#FFA500';
|
| 190 |
+
ctx.beginPath();
|
| 191 |
+
ctx.ellipse(this.x - 5, this.y + 5, 10, 7, 0, 0, Math.PI * 2);
|
| 192 |
+
ctx.fill();
|
| 193 |
+
},
|
| 194 |
+
|
| 195 |
+
update: function() {
|
| 196 |
+
if (gameState === "playing") {
|
| 197 |
+
this.velocity += this.gravity;
|
| 198 |
+
this.y += this.velocity;
|
| 199 |
+
|
| 200 |
+
// Floor collision
|
| 201 |
+
if (this.y + this.height/2 >= canvas.height - groundHeight) {
|
| 202 |
+
this.y = canvas.height - groundHeight - this.height/2;
|
| 203 |
+
if (gameState === "playing") {
|
| 204 |
+
gameOver();
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
// Ceiling collision
|
| 209 |
+
if (this.y - this.height/2 <= 0) {
|
| 210 |
+
this.y = this.height/2;
|
| 211 |
+
this.velocity = 0;
|
| 212 |
+
}
|
| 213 |
+
}
|
| 214 |
+
},
|
| 215 |
+
|
| 216 |
+
flap: function() {
|
| 217 |
+
this.velocity = this.jump;
|
| 218 |
+
},
|
| 219 |
+
|
| 220 |
+
reset: function() {
|
| 221 |
+
this.y = canvas.height / 2 - 10;
|
| 222 |
+
this.velocity = 0;
|
| 223 |
+
}
|
| 224 |
+
};
|
| 225 |
+
|
| 226 |
+
// Ground properties
|
| 227 |
+
const groundHeight = 80;
|
| 228 |
+
|
| 229 |
+
function drawGround() {
|
| 230 |
+
ctx.fillStyle = '#DEB887'; // Brown ground
|
| 231 |
+
ctx.fillRect(0, canvas.height - groundHeight, canvas.width, groundHeight);
|
| 232 |
+
|
| 233 |
+
// Draw grass
|
| 234 |
+
ctx.fillStyle = '#7CFC00'; // Green grass
|
| 235 |
+
ctx.fillRect(0, canvas.height - groundHeight, canvas.width, 15);
|
| 236 |
+
|
| 237 |
+
// Draw ground pattern
|
| 238 |
+
ctx.fillStyle = '#8B4513';
|
| 239 |
+
for (let i = 0; i < canvas.width; i += 30) {
|
| 240 |
+
ctx.fillRect(i, canvas.height - 20, 15, 5);
|
| 241 |
+
}
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
// Pipes
|
| 245 |
+
const pipes = {
|
| 246 |
+
position: [],
|
| 247 |
+
gap: 180,
|
| 248 |
+
maxYPos: -150,
|
| 249 |
+
dx: 2,
|
| 250 |
+
|
| 251 |
+
draw: function() {
|
| 252 |
+
for (let i = 0; i < this.position.length; i++) {
|
| 253 |
+
let p = this.position[i];
|
| 254 |
+
|
| 255 |
+
// Top pipe
|
| 256 |
+
ctx.fillStyle = '#228B22'; // Green pipe
|
| 257 |
+
ctx.fillRect(p.x, p.y, p.width, p.height);
|
| 258 |
+
|
| 259 |
+
// Pipe cap
|
| 260 |
+
ctx.fillStyle = '#006400';
|
| 261 |
+
ctx.fillRect(p.x - 5, p.y + p.height - 20, p.width + 10, 20);
|
| 262 |
+
|
| 263 |
+
// Bottom pipe
|
| 264 |
+
ctx.fillStyle = '#228B22';
|
| 265 |
+
ctx.fillRect(p.x, p.y + p.height + this.gap, p.width, canvas.height);
|
| 266 |
+
|
| 267 |
+
// Pipe cap
|
| 268 |
+
ctx.fillStyle = '#006400';
|
| 269 |
+
ctx.fillRect(p.x - 5, p.y + p.height + this.gap, p.width + 10, 20);
|
| 270 |
+
}
|
| 271 |
+
},
|
| 272 |
+
|
| 273 |
+
update: function() {
|
| 274 |
+
if (gameState !== "playing") return;
|
| 275 |
+
|
| 276 |
+
if (frames % 100 === 0) {
|
| 277 |
+
this.position.push({
|
| 278 |
+
x: canvas.width,
|
| 279 |
+
y: this.maxYPos * (Math.random() + 1),
|
| 280 |
+
width: 60,
|
| 281 |
+
height: 300
|
| 282 |
+
});
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
for (let i = 0; i < this.position.length; i++) {
|
| 286 |
+
let p = this.position[i];
|
| 287 |
+
|
| 288 |
+
// Move pipe to the left
|
| 289 |
+
p.x -= this.dx;
|
| 290 |
+
|
| 291 |
+
// If pipe moves off screen, remove it
|
| 292 |
+
if (p.x + p.width <= 0) {
|
| 293 |
+
this.position.shift();
|
| 294 |
+
pipesPassed++;
|
| 295 |
+
pipesPassedDisplay.textContent = pipesPassed;
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
// Collision detection
|
| 299 |
+
// Top pipe
|
| 300 |
+
if (
|
| 301 |
+
bird.x + bird.width/2 > p.x &&
|
| 302 |
+
bird.x - bird.width/2 < p.x + p.width &&
|
| 303 |
+
bird.y - bird.height/2 < p.y + p.height
|
| 304 |
+
) {
|
| 305 |
+
gameOver();
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
// Bottom pipe
|
| 309 |
+
if (
|
| 310 |
+
bird.x + bird.width/2 > p.x &&
|
| 311 |
+
bird.x - bird.width/2 < p.x + p.width &&
|
| 312 |
+
bird.y + bird.height/2 > p.y + p.height + this.gap
|
| 313 |
+
) {
|
| 314 |
+
gameOver();
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
// Score when passing a pipe
|
| 318 |
+
if (p.x + p.width < bird.x && !p.passed) {
|
| 319 |
+
score++;
|
| 320 |
+
scoreDisplay.textContent = score;
|
| 321 |
+
p.passed = true;
|
| 322 |
+
}
|
| 323 |
+
}
|
| 324 |
+
},
|
| 325 |
+
|
| 326 |
+
reset: function() {
|
| 327 |
+
this.position = [];
|
| 328 |
+
}
|
| 329 |
+
};
|
| 330 |
+
|
| 331 |
+
// Background elements
|
| 332 |
+
const background = {
|
| 333 |
+
draw: function() {
|
| 334 |
+
// Sky
|
| 335 |
+
ctx.fillStyle = '#70c5ce';
|
| 336 |
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
| 337 |
+
|
| 338 |
+
// Clouds
|
| 339 |
+
ctx.fillStyle = 'rgba(255, 255, 255, 0.8)';
|
| 340 |
+
ctx.beginPath();
|
| 341 |
+
ctx.arc(100, 80, 30, 0, Math.PI * 2);
|
| 342 |
+
ctx.arc(130, 70, 35, 0, Math.PI * 2);
|
| 343 |
+
ctx.arc(160, 80, 25, 0, Math.PI * 2);
|
| 344 |
+
ctx.fill();
|
| 345 |
+
|
| 346 |
+
ctx.beginPath();
|
| 347 |
+
ctx.arc(300, 120, 30, 0, Math.PI * 2);
|
| 348 |
+
ctx.arc(330, 110, 35, 0, Math.PI * 2);
|
| 349 |
+
ctx.arc(360, 120, 25, 0, Math.PI * 2);
|
| 350 |
+
ctx.fill();
|
| 351 |
+
}
|
| 352 |
+
};
|
| 353 |
+
|
| 354 |
+
// Game functions
|
| 355 |
+
function gameOver() {
|
| 356 |
+
gameState = "gameover";
|
| 357 |
+
finalScore.textContent = score;
|
| 358 |
+
finalPipes.textContent = pipesPassed;
|
| 359 |
+
gameOverScreen.style.display = "block";
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
function resetGame() {
|
| 363 |
+
score = 0;
|
| 364 |
+
pipesPassed = 0;
|
| 365 |
+
frames = 0;
|
| 366 |
+
scoreDisplay.textContent = score;
|
| 367 |
+
pipesPassedDisplay.textContent = pipesPassed;
|
| 368 |
+
bird.reset();
|
| 369 |
+
pipes.reset();
|
| 370 |
+
gameOverScreen.style.display = "none";
|
| 371 |
+
gameState = "playing";
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
// Draw everything
|
| 375 |
+
function draw() {
|
| 376 |
+
background.draw();
|
| 377 |
+
pipes.draw();
|
| 378 |
+
drawGround();
|
| 379 |
+
bird.draw();
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
// Update game state
|
| 383 |
+
function update() {
|
| 384 |
+
bird.update();
|
| 385 |
+
pipes.update();
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
// Game loop
|
| 389 |
+
function loop() {
|
| 390 |
+
update();
|
| 391 |
+
draw();
|
| 392 |
+
frames++;
|
| 393 |
+
|
| 394 |
+
requestAnimationFrame(loop);
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
// Event listeners
|
| 398 |
+
function flap() {
|
| 399 |
+
if (gameState === "start") {
|
| 400 |
+
gameState = "playing";
|
| 401 |
+
}
|
| 402 |
+
if (gameState === "playing") {
|
| 403 |
+
bird.flap();
|
| 404 |
+
}
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
canvas.addEventListener("click", flap);
|
| 408 |
+
document.addEventListener("keydown", function(e) {
|
| 409 |
+
if (e.code === "Space") {
|
| 410 |
+
flap();
|
| 411 |
+
}
|
| 412 |
+
});
|
| 413 |
+
|
| 414 |
+
restartButton.addEventListener("click", resetGame);
|
| 415 |
+
|
| 416 |
+
// Touch support for mobile devices
|
| 417 |
+
canvas.addEventListener("touchstart", function(e) {
|
| 418 |
+
e.preventDefault();
|
| 419 |
+
flap();
|
| 420 |
+
});
|
| 421 |
+
|
| 422 |
+
// Start the game
|
| 423 |
+
loop();
|
| 424 |
+
</script>
|
| 425 |
+
</body>
|
| 426 |
+
</html>
|