Spaces:
Running
Running
Download index.html from rocketglobal/anycoder-1be2f206: direct link, hf CLI and curl.
- Browser
- Download file 36.8 kB
-
https://huggingface.co/spaces/rocketglobal/anycoder-1be2f206/resolve/main/index.html
- Command line
-
hf download hf://spaces/rocketglobal/anycoder-1be2f206/index.html
-
curl -L -o index.html https://huggingface.co/spaces/rocketglobal/anycoder-1be2f206/resolve/main/index.html
36.8 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D Flappy Bird</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
overflow: hidden;
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
min-height: 100vh;
}
#game-container {
position: relative;
width: 100vw;
height: 100vh;
overflow: hidden;
}
#canvas-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
/* Header */
.header {
position: absolute;
top: 0;
left: 0;
right: 0;
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px 30px;
z-index: 100;
background: linear-gradient(180deg, rgba(0,0,0,0.4) 0%, transparent 100%);
}
.logo {
display: flex;
align-items: center;
gap: 12px;
}
.logo-icon {
width: 45px;
height: 45px;
background: linear-gradient(135deg, #ffd700, #ffaa00);
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 4px 15px rgba(255, 215, 0, 0.4);
animation: pulse 2s infinite;
}
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.05); }
}
.logo-text {
color: #fff;
font-size: 24px;
font-weight: 700;
text-shadow: 0 2px 10px rgba(0,0,0,0.3);
}
.anycoder-link {
color: rgba(255,255,255,0.7);
text-decoration: none;
font-size: 14px;
padding: 8px 16px;
border: 1px solid rgba(255,255,255,0.2);
border-radius: 20px;
transition: all 0.3s ease;
backdrop-filter: blur(10px);
}
.anycoder-link:hover {
background: rgba(255,255,255,0.1);
color: #fff;
border-color: rgba(255,255,255,0.4);
}
/* Score Display */
.score-container {
position: absolute;
top: 100px;
left: 50%;
transform: translateX(-50%);
z-index: 100;
text-align: center;
}
.current-score {
font-size: 72px;
font-weight: 800;
color: #fff;
text-shadow: 0 4px 20px rgba(0,0,0,0.3), 0 0 40px rgba(255,215,0,0.2);
line-height: 1;
opacity: 0;
transition: opacity 0.3s ease;
}
.current-score.visible {
opacity: 1;
}
.best-score {
font-size: 16px;
color: rgba(255,255,255,0.6);
margin-top: 8px;
opacity: 0;
transition: opacity 0.3s ease;
}
.best-score.visible {
opacity: 1;
}
/* Start Screen */
.start-screen {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
z-index: 200;
background: rgba(0,0,0,0.6);
backdrop-filter: blur(10px);
transition: opacity 0.5s ease, visibility 0.5s ease;
}
.start-screen.hidden {
opacity: 0;
visibility: hidden;
}
.game-title {
font-size: 64px;
font-weight: 800;
color: #fff;
text-shadow: 0 4px 30px rgba(255,215,0,0.5);
margin-bottom: 10px;
animation: float 3s ease-in-out infinite;
}
.game-subtitle {
font-size: 18px;
color: rgba(255,255,255,0.6);
margin-bottom: 50px;
}
@keyframes float {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-10px); }
}
.start-btn {
padding: 18px 60px;
font-size: 22px;
font-weight: 700;
color: #1a1a2e;
background: linear-gradient(135deg, #ffd700 0%, #ffaa00 100%);
border: none;
border-radius: 50px;
cursor: pointer;
box-shadow: 0 8px 30px rgba(255,215,0,0.4);
transition: all 0.3s ease;
position: relative;
overflow: hidden;
}
.start-btn::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
transition: left 0.5s ease;
}
.start-btn:hover::before {
left: 100%;
}
.start-btn:hover {
transform: translateY(-3px);
box-shadow: 0 12px 40px rgba(255,215,0,0.5);
}
.start-btn:active {
transform: translateY(0);
}
.instructions {
margin-top: 40px;
display: flex;
gap: 30px;
color: rgba(255,255,255,0.5);
font-size: 14px;
}
.instruction-item {
display: flex;
align-items: center;
gap: 8px;
}
.key {
padding: 6px 12px;
background: rgba(255,255,255,0.1);
border-radius: 6px;
font-weight: 600;
}
/* Game Over Screen */
.game-over-screen {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
z-index: 200;
background: rgba(0,0,0,0.7);
backdrop-filter: blur(10px);
opacity: 0;
visibility: hidden;
transition: opacity 0.5s ease, visibility 0.5s ease;
}
.game-over-screen.visible {
opacity: 1;
visibility: visible;
}
.game-over-title {
font-size: 56px;
font-weight: 800;
color: #ff6b6b;
text-shadow: 0 4px 30px rgba(255,107,107,0.5);
margin-bottom: 30px;
animation: shake 0.5s ease;
}
@keyframes shake {
0%, 100% { transform: translateX(0); }
25% { transform: translateX(-10px); }
75% { transform: translateX(10px); }
}
.final-score-container {
background: rgba(255,255,255,0.1);
padding: 30px 50px;
border-radius: 20px;
margin-bottom: 30px;
text-align: center;
}
.final-score-label {
font-size: 16px;
color: rgba(255,255,255,0.6);
margin-bottom: 8px;
}
.final-score {
font-size: 72px;
font-weight: 800;
color: #ffd700;
text-shadow: 0 4px 20px rgba(255,215,0,0.5);
line-height: 1;
}
.new-record {
color: #4ecdc4;
font-size: 18px;
margin-top: 10px;
opacity: 0;
transform: scale(0.5);
transition: all 0.3s ease;
}
.new-record.visible {
opacity: 1;
transform: scale(1);
}
.restart-btn {
padding: 16px 50px;
font-size: 20px;
font-weight: 700;
color: #1a1a2e;
background: linear-gradient(135deg, #4ecdc4 0%, #44a08d 100%);
border: none;
border-radius: 50px;
cursor: pointer;
box-shadow: 0 8px 30px rgba(78,205,196,0.4);
transition: all 0.3s ease;
}
.restart-btn:hover {
transform: translateY(-3px);
box-shadow: 0 12px 40px rgba(78,205,196,0.5);
}
/* Mobile Controls */
.mobile-controls {
position: absolute;
bottom: 30px;
left: 50%;
transform: translateX(-50%);
z-index: 100;
display: none;
}
.tap-area {
width: 120px;
height: 120px;
background: rgba(255,255,255,0.1);
border: 2px solid rgba(255,255,255,0.2);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: all 0.3s ease;
backdrop-filter: blur(10px);
}
.tap-area:hover, .tap-area:active {
background: rgba(255,255,255,0.2);
transform: scale(0.95);
}
.tap-icon {
font-size: 40px;
}
/* Responsive Design */
@media (max-width: 768px) {
.header {
padding: 15px 20px;
}
.logo-text {
font-size: 18px;
}
.logo-icon {
width: 35px;
height: 35px;
}
.anycoder-link {
font-size: 12px;
padding: 6px 12px;
}
.game-title {
font-size: 42px;
}
.game-subtitle {
font-size: 14px;
}
.start-btn {
padding: 14px 40px;
font-size: 18px;
}
.current-score {
font-size: 56px;
}
.instructions {
flex-direction: column;
gap: 15px;
}
.mobile-controls {
display: block;
}
.game-over-title {
font-size: 42px;
}
.final-score {
font-size: 56px;
}
}
@media (max-width: 480px) {
.game-title {
font-size: 36px;
}
.current-score {
font-size: 48px;
}
.tap-area {
width: 100px;
height: 100px;
}
}
/* Loading Animation */
.loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 300;
}
.loading-spinner {
width: 50px;
height: 50px;
border: 4px solid rgba(255,255,255,0.1);
border-top-color: #ffd700;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
/* Particle effects container */
#particles {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 50;
}
</style>
</head>
<body>
<div id="game-container">
<div id="canvas-container"></div>
<!-- Header -->
<header class="header">
<div class="logo">
<div class="logo-icon">🐦</div>
<span class="logo-text">Flappy 3D</span>
</div>
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="anycoder-link">Built with anycoder</a>
</header>
<!-- Score -->
<div class="score-container">
<div class="current-score" id="current-score">0</div>
<div class="best-score" id="best-score">Best: 0</div>
</div>
<!-- Start Screen -->
<div class="start-screen" id="start-screen">
<h1 class="game-title">Flappy 3D</h1>
<p class="game-subtitle">Experience the classic in stunning 3D</p>
<button class="start-btn" id="start-btn">Start Game</button>
<div class="instructions">
<div class="instruction-item">
<span class="key">SPACE</span>
<span>or</span>
</div>
<div class="instruction-item">
<span class="key">↑</span>
<span>to jump</span>
</div>
</div>
</div>
<!-- Game Over Screen -->
<div class="game-over-screen" id="game-over-screen">
<h1 class="game-over-title">Game Over</h1>
<div class="final-score-container">
<div class="final-score-label">Score</div>
<div class="final-score" id="final-score">0</div>
<div class="new-record" id="new-record">🏆 New Record!</div>
</div>
<button class="restart-btn" id="restart-btn">Play Again</button>
</div>
<!-- Mobile Controls -->
<div class="mobile-controls">
<div class="tap-area" id="tap-area">
<span class="tap-icon">👆</span>
</div>
</div>
<!-- Loading -->
<div class="loading" id="loading">
<div class="loading-spinner"></div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
// Game State
const GameState = {
MENU: 'menu',
PLAYING: 'playing',
GAMEOVER: 'gameover'
};
// Game Configuration
const CONFIG = {
gravity: 0.015,
jumpStrength: 0.35,
pipeSpeed: 0.12,
pipeSpawnDistance: 15,
pipeGap: 4,
pipeMinHeight: 2,
pipeMaxHeight: 6,
birdSize: 0.8,
rotationSpeed: 0.1
};
// Game Variables
let scene, camera, renderer;
let bird, birdGroup;
let pipes = [];
let particles = [];
let gameState = GameState.MENU;
let score = 0;
let bestScore = localStorage.getItem('flappy3d_best') || 0;
let birdVelocity = 0;
let distance = 0;
let lastPipeX = 0;
let animationId;
// DOM Elements
const canvasContainer = document.getElementById('canvas-container');
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 currentScoreEl = document.getElementById('current-score');
const bestScoreEl = document.getElementById('best-score');
const finalScoreEl = document.getElementById('final-score');
const newRecordEl = document.getElementById('new-record');
const tapArea = document.getElementById('tap-area');
const loadingEl = document.getElementById('loading');
// Initialize Three.js
function init() {
// Scene
scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x1a1a2e, 20, 60);
// Camera
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 100);
camera.position.set(0, 2, 10);
camera.lookAt(0, 2, 0);
// Renderer
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
canvasContainer.appendChild(renderer.domElement);
// Lighting
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
directionalLight.position.set(10, 20, 10);
directionalLight.castShadow = true;
directionalLight.shadow.mapSize.width = 2048;
directionalLight.shadow.mapSize.height = 2048;
directionalLight.shadow.camera.near = 0.5;
directionalLight.shadow.camera.far = 50;
directionalLight.shadow.camera.left = -20;
directionalLight.shadow.camera.right = 20;
directionalLight.shadow.camera.top = 20;
directionalLight.shadow.camera.bottom = -20;
scene.add(directionalLight);
// Add point light for bird glow
const pointLight = new THREE.PointLight(0xffd700, 0.5, 10);
pointLight.position.set(0, 2, 5);
scene.add(pointLight);
// Create scene elements
createBackground();
createGround();
createBird();
createClouds();
// Event listeners
window.addEventListener('resize', onWindowResize);
document.addEventListener('keydown', onKeyDown);
tapArea.addEventListener('touchstart', (e) => {
e.preventDefault();
jump();
});
tapArea.addEventListener('click', jump);
// Update best score display
bestScoreEl.textContent = `Best: ${bestScore}`;
bestScoreEl.classList.add('visible');
// Hide loading
setTimeout(() => {
loadingEl.style.display = 'none';
}, 500);
// Start render loop
animate();
}
function createBackground() {
// Create gradient background with particles
const particleCount = 500;
const geometry = new THREE.BufferGeometry();
const positions = new Float32Array(particleCount * 3);
const colors = new Float32Array(particleCount * 3);
for (let i = 0; i < particleCount; i++) {
positions[i * 3] = (Math.random() - 0.5) * 100;
positions[i * 3 + 1] = Math.random() * 50;
positions[i * 3 + 2] = (Math.random() - 0.5) * 50 - 10;
colors[i * 3] = 1;
colors[i * 3 + 1] = 0.84;
colors[i * 3 + 2] = 0;
}
geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
geometry.setAttribute('color', new THREE.BufferAttribute(colors, 3));
const material = new THREE.PointsMaterial({
size: 0.1,
vertexColors: true,
transparent: true,
opacity: 0.6,
blending: THREE.AdditiveBlending
});
const stars = new THREE.Points(geometry, material);
scene.add(stars);
}
function createGround() {
// Main ground
const groundGeometry = new THREE.PlaneGeometry(200, 30, 100, 15);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x2d5a27,
roughness: 0.8,
metalness: 0.1
});
// Add some height variation
const vertices = groundGeometry.attributes.position.array;
for (let i = 0; i < vertices.length; i += 3) {
vertices[i + 2] = Math.random() * 0.3;
}
groundGeometry.computeVertexNormals();
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -5;
ground.receiveShadow = true;
scene.add(ground);
// Add grass blades
const grassGeometry = new THREE.ConeGeometry(0.1, 0.5, 4);
const grassMaterial = new THREE.MeshStandardMaterial({
color: 0x3d7a37,
roughness: 0.9
});
for (let i = 0; i < 200; i++) {
const grass = new THREE.Mesh(grassGeometry, grassMaterial);
grass.position.set(
(Math.random() - 0.5) * 100,
-4.75,
(Math.random() - 0.5) * 15
);
grass.scale.setScalar(0.5 + Math.random() * 0.5);
grass.rotation.z = (Math.random() - 0.5) * 0.3;
scene.add(grass);
}
}
function createBird() {
birdGroup = new THREE.Group();
// Body
const bodyGeometry = new THREE.SphereGeometry(CONFIG.birdSize / 2, 32, 32);
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0xffd700,
roughness: 0.3,
metalness: 0.5,
emissive: 0xffd700,
emissiveIntensity: 0.1
});
const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
body.castShadow = true;
birdGroup.add(body);
// Wings
const wingGeometry = new THREE.BoxGeometry(0.8, 0.1, 0.4);
const wingMaterial = new THREE.MeshStandardMaterial({
color: 0xffa500,
roughness: 0.4
});
const leftWing = new THREE.Mesh(wingGeometry, wingMaterial);
leftWing.position.set(-0.3, 0, 0);
leftWing.castShadow = true;
birdGroup.add(leftWing);
const rightWing = new THREE.Mesh(wingGeometry, wingMaterial);
rightWing.position.set(0.3, 0, 0);
rightWing.castShadow = true;
birdGroup.add(rightWing);
// Eyes
const eyeGeometry = new THREE.SphereGeometry(0.1, 16, 16);
const eyeWhiteMaterial = new THREE.MeshStandardMaterial({ color: 0xffffff });
const eyePupilMaterial = new THREE.MeshStandardMaterial({ color: 0x000000 });
const leftEyeWhite = new THREE.Mesh(eyeGeometry, eyeWhiteMaterial);
leftEyeWhite.position.set(0.15, 0.15, 0.25);
birdGroup.add(leftEyeWhite);
const leftEyePupil = new THREE.Mesh(
new THREE.SphereGeometry(0.05, 8, 8),
eyePupilMaterial
);
leftEyePupil.position.set(0.18, 0.15, 0.3);
birdGroup.add(leftEyePupil);
const rightEyeWhite = new THREE.Mesh(eyeGeometry, eyeWhiteMaterial);
rightEyeWhite.position.set(0.15, 0.15, -0.25);
birdGroup.add(rightEyeWhite);
const rightEyePupil = new THREE.Mesh(
new THREE.SphereGeometry(0.05, 8, 8),
eyePupilMaterial
);
rightEyePupil.position.set(0.18, 0.15, -0.3);
birdGroup.add(rightEyePupil);
// Beak
const beakGeometry = new THREE.ConeGeometry(0.15, 0.4, 4);
const beakMaterial = new THREE.MeshStandardMaterial({ color: 0xff6600 });
const beak = new THREE.Mesh(beakGeometry, beakMaterial);
beak.rotation.z = -Math.PI / 2;
beak.position.set(0.4, 0, 0);
birdGroup.add(beak);
// Crest
const crestGeometry = new THREE.BoxGeometry(0.1, 0.3, 0.3);
const crestMaterial = new THREE.MeshStandardMaterial({ color: 0xff0000 });
const crest = new THREE.Mesh(crestGeometry, crestMaterial);
crest.position.set(-0.2, 0.3, 0);
crest.rotation.z = 0.3;
birdGroup.add(crest);
birdGroup.position.set(0, 2, 0);
scene.add(birdGroup);
bird = birdGroup;
}
function createClouds() {
const cloudGeometry = new THREE.SphereGeometry(1, 16, 16);
const cloudMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.8
});
for (let i = 0; i < 20; i++) {
const cloud = new THREE.Group();
const numSpheres = 3 + Math.floor(Math.random() * 3);
for (let j = 0; j < numSpheres; j++) {
const sphere = new THREE.Mesh(cloudGeometry, cloudMaterial);
sphere.position.set(
j * 1.2 - numSpheres * 0.6,
Math.random() * 0.5,
(Math.random() - 0.5) * 0.5
);
sphere.scale.setScalar(0.8 + Math.random() * 0.5);
cloud.add(sphere);
}
cloud.position.set(
(Math.random() - 0.5) * 150,
10 + Math.random() * 15,
-20 - Math.random() * 20
);
cloud.scale.setScalar(1 + Math.random() * 2);
scene.add(cloud);
}
}
function createPipe(x) {
const pipeGroup = new THREE.Group();
// Pipe material with gradient-like appearance
const pipeMaterial = new THREE.MeshStandardMaterial({
color: 0x2ecc71,
roughness: 0.4,
metalness: 0.2
});
const pipeTopMaterial = new THREE.MeshStandardMaterial({
color: 0x27ae60,
roughness: 0.3,
metalness: 0.3
});
// Pipe dimensions
const pipeRadius = 0.8;
const pipeLength = 2;
// Top pipe
const topHeight = CONFIG.pipeMinHeight + Math.random() * (CONFIG.pipeMaxHeight - CONFIG.pipeMinHeight);
const topPipeGeometry = new THREE.CylinderGeometry(pipeRadius, pipeRadius, topHeight, 16);
const topPipe = new THREE.Mesh(topPipeGeometry, pipeMaterial);
topPipe.position.y = 5 + topHeight / 2;
topPipe.castShadow = true;
topPipe.receiveShadow = true;
pipeGroup.add(topPipe);
// Top cap
const capGeometry = new THREE.CylinderGeometry(pipeRadius * 1.2, pipeRadius * 1.2, 0.4, 16);
const topCap = new THREE.Mesh(capGeometry, pipeTopMaterial);
topCap.position.y = 5 + topHeight;
topCap.castShadow = true;
pipeGroup.add(topCap);
// Bottom pipe
const bottomHeight = 12 - topHeight - CONFIG.pipeGap;
const bottomPipeGeometry = new THREE.CylinderGeometry(pipeRadius, pipeRadius, bottomHeight, 16);
const bottomPipe = new THREE.Mesh(bottomPipeGeometry, pipeMaterial);
bottomPipe.position.y = -5 - bottomHeight / 2;
bottomPipe.castShadow = true;
bottomPipe.receiveShadow = true;
pipeGroup.add(bottomPipe);
// Bottom cap
const bottomCap = new THREE.Mesh(capGeometry, pipeTopMaterial);
bottomCap.position.y = -5 - bottomHeight;
bottomCap.castShadow = true;
pipeGroup.add(bottomCap);
// Add stripes to pipe
const stripeGeometry = new THREE.RingGeometry(pipeRadius * 0.9, pipeRadius * 1.1, 16);
const stripeMaterial = new THREE.MeshStandardMaterial({
color: 0x1a8c4a,
side: THREE.DoubleSide
});
for (let i = 0; i < 3; i++) {
const stripe = new THREE.Mesh(stripeGeometry, stripeMaterial);
stripe.rotation.x = Math.PI / 2;
stripe.position.y = 5 + topHeight * (0.2 + i * 0.3);
pipeGroup.add(stripe);
const stripe2 = new THREE.Mesh(stripeGeometry, stripeMaterial);
stripe2.rotation.x = Math.PI / 2;
stripe2.position.y = -5 - bottomHeight * (0.2 + i * 0.3);
pipeGroup.add(stripe2);
}
pipeGroup.position.x = x;
pipeGroup.userData = {
passed: false,
topHeight: topHeight,
bottomHeight: bottomHeight
};
scene.add(pipeGroup);
pipes.push(pipeGroup);
return pipeGroup;
}
function jump() {
if (gameState === GameState.PLAYING) {
birdVelocity = CONFIG.jumpStrength;
// Create jump particles
createJumpParticles();
}
}
function createJumpParticles() {
const particleCount = 10;
const geometry = new THREE.SphereGeometry(0.05, 8, 8);
const material = new THREE.MeshBasicMaterial({
color: 0xffd700,
transparent: true,
opacity: 1
});
for (let i = 0; i < particleCount; i++) {
const particle = new THREE.Mesh(geometry, material.clone());
particle.position.copy(bird.position);
particle.position.x -= 0.3;
particle.userData = {
velocity: new THREE.Vector3(
-0.1 - Math.random() * 0.1,
-0.1 + Math.random() * 0.2,
(Math.random() - 0.5) * 0.1
),
life: 1
};
scene.add(particle);
particles.push(particle);
}
}
function createScoreParticles() {
const particleCount = 20;
const geometry = new THREE.SphereGeometry(0.08, 8, 8);
const material = new THREE.MeshBasicMaterial({
color: 0x4ecdc4,
transparent: true,
opacity: 1
});
for (let i = 0; i < particleCount; i++) {
const particle = new THREE.Mesh(geometry, material.clone());
particle.position.set(lastPipeX, 0, 0);
particle.userData = {
velocity: new THREE.Vector3(
(Math.random() - 0.5) * 0.2,
Math.random() * 0.3,
(Math.random() - 0.5) * 0.2
),
life: 1
};
scene.add(particle);
particles.push(particle);
}
}
function updateParticles() {
for (let i = particles.length - 1; i >= 0; i--) {
const particle = particles[i];
particle.position.add(particle.userData.velocity);
particle.userData.life -= 0.02;
particle.material.opacity = particle.userData.life;
particle.scale.setScalar(particle.userData.life);
if (particle.userData.life <= 0) {
scene.remove(particle);
particles.splice(i, 1);
}
}
}
function checkCollision() {
const birdBox = new THREE.Box3().setFromObject(bird);
// Shrink hitbox slightly for better gameplay
birdBox.min.addScalar(0.2);
birdBox.max.subScalar(0.2);
// Check ground collision
if (bird.position.y < -4) {
return true;
}
// Check pipe collision
for (const pipe of pipes) {
const pipeBox = new THREE.Box3().setFromObject(pipe);
if (birdBox.intersectsBox(pipeBox)) {
return true;
}
}
return false;
}
function startGame() {
gameState = GameState.PLAYING;
score = 0;
distance = 0;
birdVelocity = 0;
lastPipeX = 8;
// Reset bird position
bird.position.set(0, 2, 0);
bird.rotation.set(0, 0, 0);
// Clear existing pipes
for (const pipe of pipes) {
scene.remove(pipe);
}
pipes = [];
// Clear particles
for (const particle of particles) {
scene.remove(particle);
}
particles = [];
// Create initial pipes
for (let i = 0; i < 5; i++) {
lastPipeX += CONFIG.pipeSpawnDistance;
createPipe(lastPipeX);
}
// Update UI
currentScoreEl.textContent = score;
currentScoreEl.classList.add('visible');
bestScoreEl.classList.remove('visible');
startScreen.classList.add('hidden');
gameOverScreen.classList.remove('visible');
}
function gameOver() {
gameState = GameState.GAMEOVER;
// Check for new record
if (score > bestScore) {
bestScore = score;
localStorage.setItem('flappy3d_best', bestScore);
newRecordEl.classList.add('visible');
} else {
newRecordEl.classList.remove('visible');
}
// Update UI
finalScoreEl.textContent = score;
currentScoreEl.classList.remove('visible');
bestScoreEl.textContent = `Best: ${bestScore}`;
bestScoreEl.classList.add('visible');
gameOverScreen.classList.add('visible');
}
function update() {
if (gameState !== GameState.PLAYING) return;
// Apply gravity
birdVelocity -= CONFIG.gravity;
bird.position.y += birdVelocity;
// Rotate bird based on velocity
bird.rotation.z = Math.min(Math.max(birdVelocity * 3, -0.5), 0.8);
// Move pipes
for (let i = pipes.length - 1; i >= 0; i--) {
const pipe = pipes[i];
pipe.position.x -= CONFIG.pipeSpeed;
// Check if bird passed pipe
if (!pipe.userData.passed && pipe.position.x < bird.position.x) {
pipe.userData.passed = true;
score++;
currentScoreEl.textContent = score;
createScoreParticles();
}
// Remove off-screen pipes
if (pipe.position.x < -15) {
scene.remove(pipe);
pipes.splice(i, 1);
}
}
// Spawn new pipes
const lastPipe = pipes[pipes.length - 1];
if (lastPipe && lastPipe.position.x < 30) {
lastPipeX = lastPipe.position.x + CONFIG.pipeSpawnDistance;
createPipe(lastPipeX);
}
// Update particles
updateParticles();
// Check collision
if (checkCollision()) {
gameOver();
}
}
function animate() {
animationId = requestAnimationFrame(animate);
// Idle animation when in menu
if (gameState === GameState.MENU && bird) {
bird.position.y = 2 + Math.sin(Date.now() * 0.003) * 0.3;
bird.rotation.z = Math.sin(Date.now() * 0.002) * 0.1;
}
update();
renderer.render(scene, camera);
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function onKeyDown(event) {
if (event.code === 'Space' || event.code === 'ArrowUp') {
event.preventDefault();
if (gameState === GameState.MENU) {
startGame();
} else if (gameState === GameState.PLAYING) {
jump();
} else if (gameState === GameState.GAMEOVER) {
startGame();
}
}
}
// Event Listeners
startBtn.addEventListener('click', startGame);
restartBtn.addEventListener('click', startGame);
// Initialize game
init();
</script>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D Flappy Bird</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
overflow: hidden;
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
min-height: 100vh;
}
#game-container {
position: relative;
width: 100vw;
height: 100vh;
overflow: hidden;
}
#canvas-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
/* Header */
.header {
position: absolute;
top: 0;
left: 0;
right: 0;
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px 30px;
z-index: 100;
background: linear-gradient(180deg, rgba(0,0,0,0.4) 0%, transparent 100%);
}
.logo {
display: flex;
align-items: center;
gap: 12px;
}
.logo-icon {
width: 45px;
height: 45px;
background: linear-gradient(135deg, #ffd700, #ffaa00);
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 4px 15px rgba(255, 215, 0, 0.4);
animation: pulse 2s infinite;
}
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.05); }
}
.logo-text {
color: #fff;
font-size: 24px;
font-weight: 700;
text-shadow: 0 2px 10px rgba(0,0,0,0.3);
}
.anycoder-link {
color: rgba(255,255,255,0.7);
text-decoration: none;
font-size: 14px;
padding: 8px 16px;
border: 1px solid rgba(255,255,255,0.2);
border-radius: 20px;
transition: all 0.3s ease;
backdrop-filter: blur(10px);
}
.anycoder-link:hover {
background: rgba(255,255,255,0.1);
color: #fff;
border-color: rgba(255,255,255,0.4);
}
/* Score Display */
.score-container {
position: absolute;
top: 100px;