File size: 18,482 Bytes
d621833 | 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 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fruit Catcher Game</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
@keyframes float {
0% { transform: translateY(0px); }
50% { transform: translateY(-10px); }
100% { transform: translateY(0px); }
}
.floating {
animation: float 3s ease-in-out infinite;
}
.game-object {
position: absolute;
transition: transform 0.1s;
user-select: none;
}
.explosion {
position: absolute;
background: radial-gradient(circle, rgba(255,200,0,0.8) 0%, rgba(255,100,0,0.6) 50%, rgba(255,0,0,0) 70%);
border-radius: 50%;
transform: scale(0);
opacity: 1;
animation: explode 0.5s forwards;
}
@keyframes explode {
to {
transform: scale(3);
opacity: 0;
}
}
.shake {
animation: shake 0.5s;
}
@keyframes shake {
0%, 100% { transform: translateX(0); }
10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
20%, 40%, 60%, 80% { transform: translateX(5px); }
}
</style>
</head>
<body class="bg-gradient-to-b from-blue-400 to-blue-600 min-h-screen overflow-hidden font-sans">
<div class="container mx-auto px-4 py-8">
<!-- Game Title -->
<h1 class="text-5xl font-bold text-center text-white mb-2 floating">π Fruit Catcher π</h1>
<p class="text-center text-white mb-8">Catch the fruits, avoid the bombs!</p>
<!-- Game Info -->
<div class="flex justify-between items-center mb-4 px-4">
<div class="bg-white bg-opacity-20 rounded-lg p-3">
<p class="text-white font-bold">Score: <span id="score" class="text-yellow-300">0</span></p>
</div>
<div class="bg-white bg-opacity-20 rounded-lg p-3">
<p class="text-white font-bold">Lives: <span id="lives" class="text-red-300">β€οΈβ€οΈβ€οΈ</span></p>
</div>
<div class="bg-white bg-opacity-20 rounded-lg p-3">
<p class="text-white font-bold">Level: <span id="level" class="text-green-300">1</span></p>
</div>
</div>
<!-- Game Area -->
<div id="game-area" class="relative bg-blue-300 bg-opacity-30 rounded-xl border-4 border-blue-400 h-96 w-full overflow-hidden">
<!-- Player Basket -->
<div id="basket" class="absolute bottom-4 left-1/2 transform -translate-x-1/2 w-24 h-16 bg-gradient-to-r from-amber-700 to-amber-900 rounded-lg flex justify-center items-center">
<div class="w-full h-4 bg-amber-800 rounded-b-lg absolute -bottom-4"></div>
<div class="w-4 h-8 bg-amber-900 rounded-full absolute -bottom-8 left-4"></div>
<div class="w-4 h-8 bg-amber-900 rounded-full absolute -bottom-8 right-4"></div>
</div>
<!-- Start Screen -->
<div id="start-screen" class="absolute inset-0 flex flex-col justify-center items-center bg-black bg-opacity-70 text-white">
<h2 class="text-4xl font-bold mb-6">Fruit Catcher</h2>
<p class="text-xl mb-8 text-center px-4">Use your mouse or arrow keys to move the basket.<br>Catch fruits for points, avoid bombs!</p>
<button id="start-btn" class="bg-green-500 hover:bg-green-600 text-white font-bold py-3 px-8 rounded-full text-xl transition-all transform hover:scale-105">
Start Game
</button>
<div class="mt-8 flex space-x-4">
<div class="text-center">
<div class="text-4xl">π</div>
<div class="text-sm">+10 pts</div>
</div>
<div class="text-center">
<div class="text-4xl">π</div>
<div class="text-sm">+15 pts</div>
</div>
<div class="text-center">
<div class="text-4xl">π</div>
<div class="text-sm">+20 pts</div>
</div>
<div class="text-center">
<div class="text-4xl">π£</div>
<div class="text-sm">-1 life</div>
</div>
</div>
</div>
<!-- Game Over Screen -->
<div id="game-over" class="absolute inset-0 flex flex-col justify-center items-center bg-black bg-opacity-70 text-white hidden">
<h2 class="text-4xl font-bold mb-4">Game Over!</h2>
<p class="text-2xl mb-2">Your score: <span id="final-score" class="text-yellow-300">0</span></p>
<p class="text-xl mb-6">Level reached: <span id="final-level" class="text-green-300">1</span></p>
<button id="restart-btn" class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-3 px-8 rounded-full text-xl transition-all transform hover:scale-105">
Play Again
</button>
</div>
</div>
<!-- Controls -->
<div class="mt-6 text-center text-white">
<p>Controls: Mouse or Arrow Keys (β β)</p>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
// Game elements
const gameArea = document.getElementById('game-area');
const basket = document.getElementById('basket');
const scoreDisplay = document.getElementById('score');
const livesDisplay = document.getElementById('lives');
const levelDisplay = document.getElementById('level');
const startScreen = document.getElementById('start-screen');
const gameOverScreen = document.getElementById('game-over');
const startBtn = document.getElementById('start-btn');
const restartBtn = document.getElementById('restart-btn');
const finalScoreDisplay = document.getElementById('final-score');
const finalLevelDisplay = document.getElementById('final-level');
// Game state
let score = 0;
let lives = 3;
let level = 1;
let gameRunning = false;
let basketPosition = gameArea.offsetWidth / 2 - basket.offsetWidth / 2;
let basketWidth = basket.offsetWidth;
let gameAreaWidth = gameArea.offsetWidth;
let gameAreaHeight = gameArea.offsetHeight;
let fallingObjects = [];
let objectInterval;
let speedInterval;
let objectSpeed = 3;
let spawnRate = 1500; // ms
// Fruits and their values
const fruits = [
{ emoji: 'π', value: 10, color: 'bg-red-500' },
{ emoji: 'π', value: 15, color: 'bg-yellow-400' },
{ emoji: 'π', value: 20, color: 'bg-red-600' },
{ emoji: 'π', value: 12, color: 'bg-orange-500' },
{ emoji: 'π', value: 18, color: 'bg-pink-500' }
];
// Bombs
const bombs = [
{ emoji: 'π£', penalty: 1, color: 'bg-gray-700' }
];
// Initialize game
function initGame() {
score = 0;
lives = 3;
level = 1;
objectSpeed = 3;
spawnRate = 1500;
scoreDisplay.textContent = score;
livesDisplay.textContent = 'β€οΈβ€οΈβ€οΈ';
levelDisplay.textContent = level;
basketPosition = gameAreaWidth / 2 - basketWidth / 2;
basket.style.left = `${basketPosition}px`;
// Clear any existing objects
fallingObjects.forEach(obj => {
if (obj.element && obj.element.parentNode) {
obj.element.remove();
}
});
fallingObjects = [];
// Clear intervals
clearInterval(objectInterval);
clearInterval(speedInterval);
}
// Start game
function startGame() {
initGame();
gameRunning = true;
startScreen.classList.add('hidden');
gameOverScreen.classList.add('hidden');
// Start spawning objects
objectInterval = setInterval(createFallingObject, spawnRate);
// Gradually increase difficulty
speedInterval = setInterval(() => {
level++;
levelDisplay.textContent = level;
objectSpeed += 0.5;
spawnRate = Math.max(500, spawnRate - 100);
// Clear and reset interval with new spawn rate
clearInterval(objectInterval);
objectInterval = setInterval(createFallingObject, spawnRate);
}, 15000); // Every 15 seconds
}
// Game over
function endGame() {
gameRunning = false;
clearInterval(objectInterval);
clearInterval(speedInterval);
finalScoreDisplay.textContent = score;
finalLevelDisplay.textContent = level;
gameOverScreen.classList.remove('hidden');
}
// Create falling objects (fruits or bombs)
function createFallingObject() {
if (!gameRunning) return;
// 20% chance of bomb, 80% chance of fruit
const isBomb = Math.random() < 0.2;
const objectType = isBomb
? bombs[Math.floor(Math.random() * bombs.length)]
: fruits[Math.floor(Math.random() * fruits.length)];
const object = document.createElement('div');
object.className = `game-object text-3xl flex items-center justify-center rounded-full w-12 h-12 ${objectType.color}`;
object.textContent = objectType.emoji;
// Random horizontal position
const xPos = Math.random() * (gameAreaWidth - 50);
object.style.left = `${xPos}px`;
object.style.top = '-50px';
gameArea.appendChild(object);
const newObject = {
element: object,
x: xPos,
y: -50,
width: 50,
height: 50,
value: objectType.value || 0,
penalty: objectType.penalty || 0,
speed: objectSpeed + (Math.random() * 2 - 1) // Slight speed variation
};
fallingObjects.push(newObject);
}
// Update game state
function updateGame() {
if (!gameRunning) return;
// Update falling objects
fallingObjects.forEach((obj, index) => {
obj.y += obj.speed;
obj.element.style.top = `${obj.y}px`;
// Check if object is caught by basket
if (
obj.y + obj.height >= gameAreaHeight - 80 &&
obj.y <= gameAreaHeight - 40 &&
obj.x + obj.width >= basketPosition &&
obj.x <= basketPosition + basketWidth
) {
// Object caught
if (obj.penalty) {
// It's a bomb!
lives -= obj.penalty;
livesDisplay.textContent = 'β€οΈ'.repeat(Math.max(0, lives)) + 'β‘'.repeat(Math.max(0, 3 - lives));
// Create explosion effect
const explosion = document.createElement('div');
explosion.className = 'explosion';
explosion.style.left = `${obj.x + obj.width/2 - 15}px`;
explosion.style.top = `${obj.y + obj.height/2 - 15}px`;
explosion.style.width = '30px';
explosion.style.height = '30px';
gameArea.appendChild(explosion);
// Remove explosion after animation
setTimeout(() => {
explosion.remove();
}, 500);
// Shake basket
basket.classList.add('shake');
setTimeout(() => {
basket.classList.remove('shake');
}, 500);
// Game over if no lives left
if (lives <= 0) {
endGame();
}
} else {
// It's a fruit - add to score
score += obj.value;
scoreDisplay.textContent = score;
// Create floating score effect
const scoreEffect = document.createElement('div');
scoreEffect.className = 'absolute text-yellow-300 font-bold text-xl';
scoreEffect.textContent = `+${obj.value}`;
scoreEffect.style.left = `${obj.x + obj.width/2 - 15}px`;
scoreEffect.style.top = `${obj.y - 20}px`;
gameArea.appendChild(scoreEffect);
// Animate and remove score effect
setTimeout(() => {
scoreEffect.style.transition = 'all 0.5s';
scoreEffect.style.opacity = '0';
scoreEffect.style.transform = 'translateY(-30px)';
setTimeout(() => {
scoreEffect.remove();
}, 500);
}, 0);
}
// Remove object
obj.element.remove();
fallingObjects.splice(index, 1);
}
// Remove object if it falls past the bottom
if (obj.y > gameAreaHeight) {
obj.element.remove();
fallingObjects.splice(index, 1);
}
});
// Request next animation frame
requestAnimationFrame(updateGame);
}
// Handle keyboard controls
function handleKeyDown(e) {
if (!gameRunning) return;
const moveAmount = 20;
if (e.key === 'ArrowLeft' || e.key === 'a') {
basketPosition = Math.max(0, basketPosition - moveAmount);
} else if (e.key === 'ArrowRight' || e.key === 'd') {
basketPosition = Math.min(gameAreaWidth - basketWidth, basketPosition + moveAmount);
}
basket.style.left = `${basketPosition}px`;
}
// Handle mouse/touch controls
function handleMouseMove(e) {
if (!gameRunning) return;
const rect = gameArea.getBoundingClientRect();
const mouseX = e.clientX - rect.left;
// Keep basket within game area
basketPosition = Math.max(
0,
Math.min(
mouseX - basketWidth / 2,
gameAreaWidth - basketWidth
)
);
basket.style.left = `${basketPosition}px`;
}
// Event listeners
startBtn.addEventListener('click', () => {
startGame();
updateGame();
});
restartBtn.addEventListener('click', () => {
startGame();
updateGame();
});
document.addEventListener('keydown', handleKeyDown);
gameArea.addEventListener('mousemove', handleMouseMove);
gameArea.addEventListener('touchmove', (e) => {
e.preventDefault();
handleMouseMove(e.touches[0]);
});
// Initial setup
basket.style.left = `${basketPosition}px`;
});
</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=Hossar/savior" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |