Spaces:
Running
Running
Download index.html from AILOS/dome-blaster: direct link, hf CLI and curl.
- Browser
- Download file 22.3 kB
-
https://huggingface.co/spaces/AILOS/dome-blaster/resolve/main/index.html
- Command line
-
hf download hf://spaces/AILOS/dome-blaster/index.html
-
curl -L -o index.html https://huggingface.co/spaces/AILOS/dome-blaster/resolve/main/index.html
22.3 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Space Cylinder Defender</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <style> | |
| @keyframes bombExplosion { | |
| 0% { transform: scale(0); opacity: 1; } | |
| 100% { transform: scale(20); opacity: 0; } | |
| } | |
| .bomb-effect { | |
| animation: bombExplosion 2s forwards; | |
| background-color: #f5f5f5; | |
| border-radius: 50%; | |
| position: absolute; | |
| mix-blend-mode: screen; | |
| pointer-events: none; | |
| } | |
| body { | |
| overflow: hidden; | |
| touch-action: none; | |
| background-color: #000; | |
| } | |
| #gameCanvas { | |
| display: block; | |
| background-color: #111; | |
| } | |
| #gameContainer { | |
| position: relative; | |
| width: 100vw; | |
| height: 100vh; | |
| overflow: hidden; | |
| } | |
| #scoreDisplay { | |
| position: absolute; | |
| top: 20px; | |
| left: 20px; | |
| color: white; | |
| font-family: 'Arial', sans-serif; | |
| font-size: 24px; | |
| z-index: 10; | |
| } | |
| #startScreen, #gameOverScreen { | |
| position: absolute; | |
| top: 0; | |
| left: 0; | |
| width: 100%; | |
| height: 100%; | |
| display: flex; | |
| flex-direction: column; | |
| justify-content: center; | |
| align-items: center; | |
| background-color: rgba(0, 0, 0, 0.7); | |
| color: white; | |
| z-index: 20; | |
| } | |
| .hidden { | |
| display: none ; | |
| } | |
| .btn { | |
| background-color: #4f46e5; | |
| color: white; | |
| padding: 12px 24px; | |
| border-radius: 8px; | |
| font-size: 18px; | |
| margin-top: 20px; | |
| cursor: pointer; | |
| transition: all 0.3s; | |
| } | |
| .btn:hover { | |
| background-color: #6366f1; | |
| transform: scale(1.05); | |
| } | |
| .title { | |
| font-size: 48px; | |
| margin-bottom: 20px; | |
| text-shadow: 0 0 10px #6366f1; | |
| } | |
| .instructions { | |
| max-width: 500px; | |
| text-align: center; | |
| margin-bottom: 30px; | |
| line-height: 1.6; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="gameContainer"> | |
| <canvas id="gameCanvas"></canvas> | |
| <div id="scoreDisplay">Score: 0</div> | |
| <div id="startScreen"> | |
| <h1 class="title">Space Cylinder Defender</h1> | |
| <p class="instructions"> | |
| Defend against the egg invasion! Your cylinder body can shoot white blasters from its dome-shaped front. | |
| Reach 100 points to unleash a devastating bomb that will wipe out all eggs! | |
| </p> | |
| <button id="startBtn" class="btn">Start Game</button> | |
| </div> | |
| <div id="gameOverScreen" class="hidden"> | |
| <h1 class="title">Game Over</h1> | |
| <p id="finalScore" class="instructions">Your score: 0</p> | |
| <button id="restartBtn" class="btn">Play Again</button> | |
| </div> | |
| </div> | |
| <script> | |
| document.addEventListener('DOMContentLoaded', () => { | |
| const canvas = document.getElementById('gameCanvas'); | |
| const ctx = canvas.getContext('2d'); | |
| const scoreDisplay = document.getElementById('scoreDisplay'); | |
| const startScreen = document.getElementById('startScreen'); | |
| const gameOverScreen = document.getElementById('gameOverScreen'); | |
| const finalScore = document.getElementById('finalScore'); | |
| const startBtn = document.getElementById('startBtn'); | |
| const restartBtn = document.getElementById('restartBtn'); | |
| // Set canvas size | |
| function resizeCanvas() { | |
| canvas.width = window.innerWidth; | |
| canvas.height = window.innerHeight; | |
| } | |
| resizeCanvas(); | |
| window.addEventListener('resize', resizeCanvas); | |
| // Game variables | |
| let score = 0; | |
| let gameRunning = false; | |
| let animationId; | |
| let lastTime = 0; | |
| // Player | |
| const player = { | |
| x: 100, | |
| y: canvas.height / 2, | |
| width: 40, | |
| height: 30, | |
| speed: 5, | |
| blasters: [], | |
| lastShot: 0, | |
| shootDelay: 300, | |
| color: '#e2c8a8', | |
| hit: false | |
| }; | |
| // Enemies | |
| const enemies = []; | |
| const enemyColors = ['#ffb6c1', '#ffc0cb', '#ff69b4', '#db7093', '#ff1493']; // Pink colors for eggs | |
| let enemySpawnTimer = 0; | |
| const enemySpawnDelay = 1000; | |
| // Game state | |
| let keys = { | |
| ArrowUp: false, | |
| ArrowDown: false, | |
| ArrowLeft: false, | |
| ArrowRight: false, | |
| Space: false | |
| }; | |
| // Event listeners | |
| document.addEventListener('keydown', (e) => { | |
| if (keys.hasOwnProperty(e.code)) { | |
| keys[e.code] = true; | |
| } | |
| }); | |
| document.addEventListener('keyup', (e) => { | |
| if (keys.hasOwnProperty(e.code)) { | |
| keys[e.code] = false; | |
| } | |
| }); | |
| // Touch controls for mobile | |
| canvas.addEventListener('touchstart', handleTouch); | |
| canvas.addEventListener('touchmove', handleTouch); | |
| function handleTouch(e) { | |
| e.preventDefault(); | |
| if (!gameRunning) return; | |
| const touch = e.touches[0]; | |
| const touchY = touch.clientY; | |
| // Move player to touch position | |
| player.y = touchY; | |
| // Shoot if not recently shot | |
| const now = Date.now(); | |
| if (now - player.lastShot > player.shootDelay) { | |
| shootBlaster(); | |
| player.lastShot = now; | |
| } | |
| } | |
| startBtn.addEventListener('click', startGame); | |
| restartBtn.addEventListener('click', startGame); | |
| function startGame() { | |
| score = 0; | |
| scoreDisplay.textContent = `Score: ${score}`; | |
| player.x = 100; | |
| player.y = canvas.height / 2; | |
| player.blasters = []; | |
| enemies.length = 0; | |
| player.hit = false; | |
| startScreen.classList.add('hidden'); | |
| gameOverScreen.classList.add('hidden'); | |
| gameRunning = true; | |
| lastTime = performance.now(); | |
| gameLoop(lastTime); | |
| } | |
| function gameLoop(timestamp) { | |
| if (!gameRunning) return; | |
| const deltaTime = timestamp - lastTime; | |
| lastTime = timestamp; | |
| update(deltaTime); | |
| render(); | |
| animationId = requestAnimationFrame(gameLoop); | |
| } | |
| function update(deltaTime) { | |
| // Player movement | |
| if (keys.ArrowUp) player.y -= player.speed; | |
| if (keys.ArrowDown) player.y += player.speed; | |
| if (keys.ArrowLeft) player.x -= player.speed; | |
| if (keys.ArrowRight) player.x += player.speed; | |
| // Keep player in bounds | |
| player.x = Math.max(0, Math.min(canvas.width - player.width, player.x)); | |
| player.y = Math.max(0, Math.min(canvas.height - player.height, player.y)); | |
| // Shooting | |
| if (keys.Space && Date.now() - player.lastShot > player.shootDelay) { | |
| shootBlaster(); | |
| player.lastShot = Date.now(); | |
| } | |
| // Update blasters | |
| for (let i = player.blasters.length - 1; i >= 0; i--) { | |
| player.blasters[i].x += player.blasters[i].speed; | |
| // Remove blasters that go off screen | |
| if (player.blasters[i].x > canvas.width) { | |
| player.blasters.splice(i, 1); | |
| continue; | |
| } | |
| // Check for collisions with enemies (ignore babies) | |
| for (let j = enemies.length - 1; j >= 0; j--) { | |
| if (!enemies[j].isBaby && checkCollision(player.blasters[i], enemies[j])) { | |
| // Create baby from destroyed egg | |
| const baby = { | |
| x: enemies[j].x, | |
| y: enemies[j].y, | |
| width: enemies[j].width / 2, | |
| height: enemies[j].height / 2, | |
| speed: 1, | |
| color: '#ffcccb', | |
| isBaby: true, | |
| phrase: '', | |
| showPhrase: false | |
| }; | |
| // Set random phrase after 1 seconds | |
| setTimeout(() => { | |
| const phrases = ['daddy', 'dad', 'duhduh', 'child support', 'milky']; | |
| baby.phrase = phrases[Math.floor(Math.random() * phrases.length)]; | |
| baby.showPhrase = true; | |
| // Hide phrase after 2 seconds | |
| setTimeout(() => { | |
| baby.showPhrase = false; | |
| }, 3000); | |
| }, 2000); | |
| player.blasters.splice(i, 1); | |
| enemies.splice(j, 1); | |
| enemies.push(baby); | |
| score++; | |
| scoreDisplay.textContent = `Score: ${score}`; | |
| // Check for bomb condition | |
| if (score >= 100) { | |
| triggerBomb(); | |
| score = 100; // Cap at 100 | |
| scoreDisplay.textContent = `Score: ${score}`; | |
| } | |
| break; | |
| } | |
| } | |
| } | |
| // Spawn enemies | |
| enemySpawnTimer += deltaTime; | |
| if (enemySpawnTimer > enemySpawnDelay) { | |
| spawnEnemy(); | |
| enemySpawnTimer = 0; | |
| } | |
| // Update enemies | |
| for (let i = enemies.length - 1; i >= 0; i--) { | |
| enemies[i].x -= enemies[i].speed; | |
| // Remove enemies that go off screen | |
| if (enemies[i].x + enemies[i].width < 0) { | |
| enemies.splice(i, 1); | |
| continue; | |
| } | |
| // Check for collision with player (only non-baby enemies) | |
| if (!enemies[i].isBaby && checkCollision(player, enemies[i])) { | |
| gameOver(); | |
| break; | |
| } | |
| } | |
| } | |
| function render() { | |
| // Clear canvas | |
| ctx.clearRect(0, 0, canvas.width, canvas.height); | |
| // Draw stars (background) | |
| drawStars(); | |
| // Draw player | |
| drawPlayer(); | |
| // Draw blasters | |
| player.blasters.forEach(blaster => { | |
| ctx.fillStyle = blaster.color; | |
| ctx.beginPath(); | |
| ctx.arc(blaster.x, blaster.y, blaster.radius, 0, Math.PI * 2); | |
| ctx.fill(); | |
| }); | |
| // Draw enemies | |
| enemies.forEach(enemy => { | |
| drawEnemy(enemy); | |
| }); | |
| } | |
| function drawStars() { | |
| ctx.fillStyle = 'white'; | |
| for (let i = 0; i < 100; i++) { | |
| const x = Math.random() * canvas.width; | |
| const y = Math.random() * canvas.height; | |
| const size = Math.random() * 2; | |
| ctx.fillRect(x, y, size, size); | |
| } | |
| } | |
| function drawPlayer() { | |
| // Main cylinder body (longer section) | |
| ctx.fillStyle = player.color; | |
| const cylinderLength = player.width * 1.2; // Make cylinder slightly longer but proportional | |
| ctx.fillRect(player.x, player.y, cylinderLength, player.height); | |
| // Smaller dome-shaped front | |
| ctx.beginPath(); | |
| ctx.ellipse( | |
| player.x + cylinderLength, | |
| player.y + player.height / 2, | |
| player.width / 2, // Smaller width | |
| player.height / 2, // Smaller height | |
| 0, | |
| -Math.PI / 2, | |
| Math.PI / 2 | |
| ); | |
| ctx.fill(); | |
| // Two bigger circles on the back with single connecting cylinder | |
| const backX = player.x - 10; // Position circles closer due to smaller cylinder | |
| ctx.fillStyle = player.color; | |
| // Single connecting cylinder from main body to both balls | |
| ctx.fillRect(backX + 10, player.y + player.height / 4, 10, player.height / 2); | |
| // Draw the two bigger balls | |
| ctx.beginPath(); | |
| ctx.arc(backX, player.y + player.height / 8, 18, 0, Math.PI * 2); // Bigger radius | |
| ctx.fill(); | |
| ctx.beginPath(); | |
| ctx.arc(backX, player.y + (player.height / 3) * 3, 18, 0, Math.PI * 2); // Bigger radius | |
| ctx.fill(); | |
| // If hit, flash red | |
| if (player.hit) { | |
| ctx.fillStyle = 'rgba(255, 0, 0, 0.5)'; | |
| ctx.fillRect(player.x, player.y, player.width, player.height); | |
| player.hit = false; | |
| } | |
| } | |
| function drawEnemy(enemy) { | |
| if (enemy.isBaby) { | |
| // Draw baby only | |
| ctx.fillStyle = enemy.color; | |
| ctx.beginPath(); | |
| ctx.ellipse( | |
| enemy.x + enemy.width / 2, | |
| enemy.y + enemy.height / 2, | |
| enemy.width / 2, | |
| enemy.height / 2, | |
| 0, | |
| 0, | |
| Math.PI * 2 | |
| ); | |
| ctx.fill(); | |
| // Baby eyes | |
| ctx.fillStyle = 'black'; | |
| ctx.beginPath(); | |
| ctx.arc(enemy.x + enemy.width / 3, enemy.y + enemy.height / 3, 2, 0, Math.PI * 2); | |
| ctx.fill(); | |
| ctx.beginPath(); | |
| ctx.arc(enemy.x + (enemy.width / 3) * 2, enemy.y + enemy.height / 3, 2, 0, Math.PI * 2); | |
| ctx.fill(); | |
| // Baby mouth (smile) | |
| ctx.strokeStyle = 'black'; | |
| ctx.lineWidth = 1; | |
| ctx.beginPath(); | |
| ctx.arc(enemy.x + enemy.width / 2, enemy.y + enemy.height / 2, enemy.width / 4, 0, Math.PI); | |
| ctx.stroke(); | |
| // Show phrase if active | |
| if (enemy.showPhrase) { | |
| ctx.font = '12px Arial'; | |
| ctx.fillStyle = 'white'; | |
| ctx.textAlign = 'center'; | |
| ctx.fillText(enemy.phrase, enemy.x + enemy.width / 2, enemy.y - 10); | |
| } | |
| } else { | |
| // Draw egg with baby inside | |
| ctx.fillStyle = enemy.color; | |
| ctx.beginPath(); | |
| ctx.ellipse( | |
| enemy.x + enemy.width / 2, | |
| enemy.y + enemy.height / 2, | |
| enemy.width / 2, | |
| enemy.height / 2, | |
| 0, | |
| 0, | |
| Math.PI * 2 | |
| ); | |
| ctx.fill(); | |
| // Egg shell pattern | |
| ctx.strokeStyle = 'rgba(255, 255, 255, 0.3)'; | |
| ctx.lineWidth = 2; | |
| ctx.beginPath(); | |
| ctx.ellipse( | |
| enemy.x + enemy.width / 2, | |
| enemy.y + enemy.height / 2, | |
| enemy.width / 3, | |
| enemy.height / 3, | |
| 0, | |
| 0, | |
| Math.PI * 2 | |
| ); | |
| ctx.stroke(); | |
| // Baby inside | |
| ctx.fillStyle = '#ffcccb'; | |
| ctx.beginPath(); | |
| ctx.ellipse( | |
| enemy.x + enemy.width / 2, | |
| enemy.y + enemy.height / 2, | |
| enemy.width / 4, | |
| enemy.height / 4, | |
| 0, | |
| 0, | |
| Math.PI * 2 | |
| ); | |
| ctx.fill(); | |
| // Baby eyes | |
| ctx.fillStyle = 'black'; | |
| ctx.beginPath(); | |
| ctx.arc(enemy.x + enemy.width / 2.5, enemy.y + enemy.height / 2.5, 2, 0, Math.PI * 2); | |
| ctx.fill(); | |
| ctx.beginPath(); | |
| ctx.arc(enemy.x + (enemy.width / 2.5) * 1.5, enemy.y + enemy.height / 2.5, 2, 0, Math.PI * 2); | |
| ctx.fill(); | |
| } | |
| } | |
| function shootBlaster() { | |
| player.blasters.push({ | |
| x: player.x + player.width, | |
| y: player.y + player.height / 2, | |
| radius: 5, | |
| speed: 10, | |
| color: 'white' | |
| }); | |
| } | |
| function spawnEnemy() { | |
| const size = 30 + Math.random() * 30; | |
| enemies.push({ | |
| x: canvas.width, | |
| y: Math.random() * (canvas.height - size), | |
| width: size, | |
| height: size, | |
| speed: 2 + Math.random() * 3, | |
| color: enemyColors[Math.floor(Math.random() * enemyColors.length)] | |
| }); | |
| } | |
| function checkCollision(obj1, obj2) { | |
| return obj1.x < obj2.x + obj2.width && | |
| obj1.x + (obj1.width || obj1.radius * 2) > obj2.x && | |
| obj1.y < obj2.y + obj2.height && | |
| obj1.y + (obj1.height || obj1.radius * 2) > obj2.y; | |
| } | |
| function triggerBomb() { | |
| // Create bomb effect | |
| const bomb = document.createElement('div'); | |
| bomb.className = 'bomb-effect'; | |
| bomb.style.width = '20px'; | |
| bomb.style.height = '20px'; | |
| bomb.style.left = `${player.x + player.width / 2 - 10}px`; | |
| bomb.style.top = `${player.y + player.height / 2 - 10}px`; | |
| document.getElementById('gameContainer').appendChild(bomb); | |
| // Remove all enemies | |
| enemies.length = 0; | |
| // Remove bomb element after animation | |
| setTimeout(() => { | |
| bomb.remove(); | |
| }, 2000); | |
| } | |
| function gameOver() { | |
| gameRunning = false; | |
| cancelAnimationFrame(animationId); | |
| player.hit = true; | |
| render(); // Show final frame with hit effect | |
| setTimeout(() => { | |
| finalScore.textContent = `Your score: ${score}`; | |
| gameOverScreen.classList.remove('hidden'); | |
| }, 500); | |
| } | |
| }); | |
| </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=AILOS/dome-blaster" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
| </html> |