Spaces:
Running
Running
File size: 17,303 Bytes
574f64d | 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 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tech Flappy</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&family=Press+Start+2P&display=swap');
body {
font-family: 'Orbitron', sans-serif;
background-color: #0f0f1a;
overflow: hidden;
color: #00fffc;
}
#game-container {
position: relative;
width: 100vw;
height: 100vh;
overflow: hidden;
background: linear-gradient(135deg, #0f0f1a 0%, #1a1a2e 100%);
}
#game-canvas {
display: block;
margin: 0 auto;
background-color: #0a0a12;
border: 2px solid #00fffc;
box-shadow: 0 0 20px rgba(0, 255, 252, 0.3);
}
.neon-text {
text-shadow: 0 0 5px #00fffc, 0 0 10px #00fffc, 0 0 15px #00fffc;
}
.neon-border {
border: 2px solid #00fffc;
box-shadow: 0 0 10px rgba(0, 255, 252, 0.5);
}
.pixel-font {
font-family: 'Press Start 2P', cursive;
}
.glow {
animation: glow 2s infinite alternate;
}
@keyframes glow {
from {
box-shadow: 0 0 5px #00fffc, 0 0 10px rgba(0, 255, 252, 0.5);
}
to {
box-shadow: 0 0 15px #00fffc, 0 0 30px rgba(0, 255, 252, 0.8);
}
}
.pipe {
background: linear-gradient(90deg, #00fffc 0%, #008e8b 100%);
}
.bird {
background: linear-gradient(45deg, #ff00fc 0%, #00fffc 100%);
border-radius: 50%;
}
</style>
</head>
<body>
<div id="game-container" class="flex flex-col items-center justify-center">
<h1 class="text-4xl md:text-6xl font-bold mb-4 neon-text glow">TECH FLAPPY</h1>
<div class="relative">
<canvas id="game-canvas" width="320" height="480" class="neon-border"></canvas>
<!-- Start Screen -->
<div id="start-screen" class="absolute inset-0 flex flex-col items-center justify-center bg-black bg-opacity-70">
<div class="text-center p-8 neon-border rounded-lg bg-gray-900">
<h2 class="text-2xl md:text-3xl font-bold mb-6 neon-text">TECH FLAPPY</h2>
<p class="mb-6 text-sm md:text-base">Navigate through the binary pipes</p>
<button id="start-btn" class="px-6 py-3 bg-transparent neon-border rounded-lg text-lg font-bold hover:bg-blue-900 hover:text-white transition-all duration-300 glow">
<i class="fas fa-play mr-2"></i> START
</button>
<div class="mt-6 text-xs">
<p>Press SPACE or CLICK to flap</p>
<p class="mt-2">High Score: <span id="high-score-display">0</span></p>
</div>
</div>
</div>
<!-- Game Over Screen -->
<div id="game-over-screen" class="absolute inset-0 hidden flex-col items-center justify-center bg-black bg-opacity-70">
<div class="text-center p-8 neon-border rounded-lg bg-gray-900">
<h2 class="text-2xl md:text-3xl font-bold mb-2 neon-text">GAME OVER</h2>
<p class="mb-1">Your score: <span id="final-score" class="font-bold">0</span></p>
<p class="mb-6">High score: <span id="new-high-score" class="font-bold">0</span></p>
<button id="restart-btn" class="px-6 py-3 bg-transparent neon-border rounded-lg text-lg font-bold hover:bg-blue-900 hover:text-white transition-all duration-300 glow">
<i class="fas fa-redo mr-2"></i> PLAY AGAIN
</button>
</div>
</div>
</div>
<div class="mt-6 flex items-center space-x-8">
<div class="text-center">
<p class="text-sm">SCORE</p>
<p id="score-display" class="text-2xl font-bold neon-text">0</p>
</div>
<div class="text-center">
<p class="text-sm">BEST</p>
<p id="current-high-score" class="text-2xl font-bold neon-text">0</p>
</div>
</div>
<div class="mt-8 text-xs text-gray-500">
<p>© 2023 TECH FLAPPY | <i class="fas fa-code"></i> with <i class="fas fa-heart text-red-500"></i> by Dev</p>
</div>
</div>
<audio id="flap-sound" src="https://assets.mixkit.co/sfx/preview/mixkit-arcade-game-jump-coin-216.mp3"></audio>
<audio id="score-sound" src="https://assets.mixkit.co/sfx/preview/mixkit-unlock-game-notification-253.mp3"></audio>
<audio id="hit-sound" src="https://assets.mixkit.co/sfx/preview/mixkit-arcade-game-explosion-275.mp3"></audio>
<script>
// Game variables
const canvas = document.getElementById('game-canvas');
const ctx = canvas.getContext('2d');
const startScreen = document.getElementById('start-screen');
const gameOverScreen = document.getElementById('game-over-screen');
const startBtn = document.getElementById('start-btn');
const restartBtn = document.getElementById('restart-btn');
const scoreDisplay = document.getElementById('score-display');
const finalScoreDisplay = document.getElementById('final-score');
const highScoreDisplay = document.getElementById('high-score-display');
const currentHighScoreDisplay = document.getElementById('current-high-score');
const newHighScoreDisplay = document.getElementById('new-high-score');
// Sound effects
const flapSound = document.getElementById('flap-sound');
const scoreSound = document.getElementById('score-sound');
const hitSound = document.getElementById('hit-sound');
// Game state
let gameRunning = false;
let score = 0;
let highScore = localStorage.getItem('techFlappyHighScore') || 0;
highScoreDisplay.textContent = highScore;
currentHighScoreDisplay.textContent = highScore;
// Bird properties - MODIFIED FOR SMOOTHER PHYSICS
const bird = {
x: 50,
y: canvas.height / 2,
width: 30,
height: 30,
velocity: 0,
gravity: 0.3, // Reduced gravity for slower falling
jump: -6, // Reduced jump force for less dramatic jumps
draw() {
ctx.fillStyle = '#00fffc';
ctx.beginPath();
ctx.arc(this.x, this.y, this.width / 2, 0, Math.PI * 2);
ctx.fill();
// Add tech details to bird
ctx.fillStyle = '#ff00fc';
ctx.beginPath();
ctx.arc(this.x - 5, this.y - 5, 3, 0, Math.PI * 2);
ctx.fill();
ctx.beginPath();
ctx.arc(this.x + 5, this.y - 5, 3, 0, Math.PI * 2);
ctx.fill();
},
update() {
this.velocity += this.gravity;
this.y += this.velocity;
// Check if bird hits the ground or ceiling
if (this.y + this.height / 2 > canvas.height || this.y - this.height / 2 < 0) {
gameOver();
}
},
flap() {
this.velocity = this.jump;
flapSound.currentTime = 0;
flapSound.play();
}
};
// Pipes
const pipes = [];
const pipeWidth = 60;
const pipeGap = 120;
let pipeTimer = 0;
let pipeInterval = 1500; // milliseconds
function createPipe() {
const minHeight = 50;
const maxHeight = canvas.height - pipeGap - minHeight;
const height = Math.floor(Math.random() * (maxHeight - minHeight + 1) + minHeight);
pipes.push({
x: canvas.width,
height: height,
passed: false
});
}
function drawPipes() {
ctx.fillStyle = '#00fffc';
pipes.forEach(pipe => {
// Top pipe
ctx.fillRect(pipe.x, 0, pipeWidth, pipe.height);
// Bottom pipe
ctx.fillRect(pipe.x, pipe.height + pipeGap, pipeWidth, canvas.height - pipe.height - pipeGap);
// Add tech details to pipes
ctx.fillStyle = '#008e8b';
for (let i = 0; i < pipe.height; i += 15) {
ctx.fillRect(pipe.x + 10, i + 5, pipeWidth - 20, 5);
}
for (let i = pipe.height + pipeGap; i < canvas.height; i += 15) {
ctx.fillRect(pipe.x + 10, i + 5, pipeWidth - 20, 5);
}
ctx.fillStyle = '#00fffc';
});
}
function updatePipes() {
if (gameRunning) {
pipeTimer += 16; // assuming 60fps
if (pipeTimer > pipeInterval) {
createPipe();
pipeTimer = 0;
// Increase difficulty
if (score > 0 && score % 5 === 0) {
pipeInterval = Math.max(800, pipeInterval - 50);
pipeGap = Math.max(80, pipeGap - 5);
}
}
pipes.forEach((pipe, index) => {
pipe.x -= 2;
// Check if bird passed the pipe
if (!pipe.passed && pipe.x + pipeWidth < bird.x) {
pipe.passed = true;
score++;
scoreDisplay.textContent = score;
scoreSound.currentTime = 0;
scoreSound.play();
}
// Check collision
if (
bird.x + bird.width / 2 > pipe.x &&
bird.x - bird.width / 2 < pipe.x + pipeWidth &&
(bird.y - bird.height / 2 < pipe.height ||
bird.y + bird.height / 2 > pipe.height + pipeGap)
) {
gameOver();
}
// Remove pipes that are off screen
if (pipe.x + pipeWidth < 0) {
pipes.splice(index, 1);
}
});
}
}
// Background elements
const stars = [];
for (let i = 0; i < 100; i++) {
stars.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
size: Math.random() * 2 + 1,
speed: Math.random() * 0.5 + 0.5
});
}
function drawBackground() {
// Draw space background
ctx.fillStyle = '#0a0a12';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Draw stars
ctx.fillStyle = '#ffffff';
stars.forEach(star => {
ctx.beginPath();
ctx.arc(star.x, star.y, star.size, 0, Math.PI * 2);
ctx.fill();
});
// Draw grid lines
ctx.strokeStyle = 'rgba(0, 255, 252, 0.1)';
ctx.lineWidth = 1;
// Vertical lines
for (let x = 0; x < canvas.width; x += 40) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, canvas.height);
ctx.stroke();
}
// Horizontal lines
for (let y = 0; y < canvas.height; y += 40) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(canvas.width, y);
ctx.stroke();
}
}
// Game loop
function gameLoop() {
// Clear canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw background
drawBackground();
// Update and draw pipes
updatePipes();
drawPipes();
// Update and draw bird
bird.update();
bird.draw();
// Update stars
stars.forEach(star => {
star.x -= star.speed;
if (star.x < 0) {
star.x = canvas.width;
star.y = Math.random() * canvas.height;
}
});
// Continue game loop if running
if (gameRunning) {
requestAnimationFrame(gameLoop);
}
}
// Game controls
function startGame() {
// Reset game state
score = 0;
scoreDisplay.textContent = score;
pipes.length = 0;
pipeTimer = 0;
bird.y = canvas.height / 2;
bird.velocity = 0;
// Show game and hide start screen
startScreen.style.display = 'none';
gameOverScreen.style.display = 'none';
// Start game
gameRunning = true;
gameLoop();
}
function gameOver() {
gameRunning = false;
hitSound.currentTime = 0;
hitSound.play();
// Update high score if needed
if (score > highScore) {
highScore = score;
localStorage.setItem('techFlappyHighScore', highScore);
currentHighScoreDisplay.textContent = highScore;
}
// Show game over screen
finalScoreDisplay.textContent = score;
newHighScoreDisplay.textContent = highScore;
gameOverScreen.style.display = 'flex';
}
// Event listeners
startBtn.addEventListener('click', startGame);
restartBtn.addEventListener('click', startGame);
// Keyboard controls
document.addEventListener('keydown', (e) => {
if (e.code === 'Space') {
if (!gameRunning && startScreen.style.display !== 'none') {
startGame();
} else if (gameRunning) {
bird.flap();
} else if (!gameRunning && gameOverScreen.style.display === 'flex') {
startGame();
}
}
});
// Mouse/touch controls
canvas.addEventListener('click', () => {
if (gameRunning) {
bird.flap();
}
});
// Mobile touch support
canvas.addEventListener('touchstart', (e) => {
e.preventDefault();
if (gameRunning) {
bird.flap();
} else if (!gameRunning && startScreen.style.display !== 'none') {
startGame();
} else if (!gameRunning && gameOverScreen.style.display === 'flex') {
startGame();
}
});
// Responsive canvas sizing
function resizeCanvas() {
const container = document.getElementById('game-container');
const scale = Math.min(
container.clientWidth / 320,
container.clientHeight / 480
);
canvas.style.width = `${320 * scale}px`;
canvas.style.height = `${480 * scale}px`;
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
</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=BudBit3/techno-flappybird" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |