Add 2 files
Browse files- README.md +6 -4
- index.html +437 -19
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: pink
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: gg
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: pink
|
| 5 |
colorTo: pink
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,437 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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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>Neon Snake Game</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 9 |
+
<style>
|
| 10 |
+
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');
|
| 11 |
+
|
| 12 |
+
body {
|
| 13 |
+
font-family: 'Press Start 2P', cursive;
|
| 14 |
+
background-color: #0f172a;
|
| 15 |
+
overflow: hidden;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
#game-board {
|
| 19 |
+
border: 4px solid #4f46e5;
|
| 20 |
+
box-shadow: 0 0 20px #4f46e5, inset 0 0 20px #4f46e5;
|
| 21 |
+
position: relative;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
.snake-segment {
|
| 25 |
+
background-color: #10b981;
|
| 26 |
+
border: 1px solid #a7f3d0;
|
| 27 |
+
box-shadow: 0 0 10px #10b981;
|
| 28 |
+
border-radius: 3px;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
.food {
|
| 32 |
+
background-color: #ef4444;
|
| 33 |
+
border-radius: 50%;
|
| 34 |
+
box-shadow: 0 0 15px #ef4444;
|
| 35 |
+
animation: pulse 0.8s infinite alternate;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
@keyframes pulse {
|
| 39 |
+
from { transform: scale(0.9); }
|
| 40 |
+
to { transform: scale(1.1); }
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.glow-text {
|
| 44 |
+
text-shadow: 0 0 10px currentColor;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
.modal-overlay {
|
| 48 |
+
background-color: rgba(15, 23, 42, 0.9);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.modal-content {
|
| 52 |
+
border: 3px solid #4f46e5;
|
| 53 |
+
box-shadow: 0 0 30px #4f46e5;
|
| 54 |
+
}
|
| 55 |
+
</style>
|
| 56 |
+
</head>
|
| 57 |
+
<body class="min-h-screen flex flex-col items-center justify-center p-4">
|
| 58 |
+
<div class="text-center mb-6">
|
| 59 |
+
<h1 class="text-4xl md:text-5xl font-bold text-indigo-400 glow-text mb-2">NEON SNAKE</h1>
|
| 60 |
+
<div class="flex justify-center items-center gap-6 text-emerald-400">
|
| 61 |
+
<div class="flex items-center gap-2">
|
| 62 |
+
<i class="fas fa-star"></i>
|
| 63 |
+
<span id="score" class="text-xl">0</span>
|
| 64 |
+
</div>
|
| 65 |
+
<div class="flex items-center gap-2">
|
| 66 |
+
<i class="fas fa-tachometer-alt"></i>
|
| 67 |
+
<span id="speed" class="text-xl">1</span>
|
| 68 |
+
</div>
|
| 69 |
+
</div>
|
| 70 |
+
</div>
|
| 71 |
+
|
| 72 |
+
<div class="relative">
|
| 73 |
+
<canvas id="game-board" width="400" height="400" class="bg-gray-900"></canvas>
|
| 74 |
+
|
| 75 |
+
<div id="game-over-modal" class="fixed inset-0 flex items-center justify-center modal-overlay hidden">
|
| 76 |
+
<div class="bg-gray-800 p-8 rounded-lg modal-content text-center max-w-md w-full">
|
| 77 |
+
<h2 class="text-3xl text-red-500 glow-text mb-4">GAME OVER!</h2>
|
| 78 |
+
<p class="text-indigo-300 mb-6">Your score: <span id="final-score" class="text-emerald-400">0</span></p>
|
| 79 |
+
<div class="flex flex-col space-y-3">
|
| 80 |
+
<button id="restart-btn" class="bg-emerald-600 hover:bg-emerald-500 text-white py-3 px-6 rounded transition">
|
| 81 |
+
<i class="fas fa-redo mr-2"></i> Play Again
|
| 82 |
+
</button>
|
| 83 |
+
<button id="quit-btn" class="bg-indigo-600 hover:bg-indigo-500 text-white py-3 px-6 rounded transition">
|
| 84 |
+
<i class="fas fa-times mr-2"></i> Quit
|
| 85 |
+
</button>
|
| 86 |
+
</div>
|
| 87 |
+
</div>
|
| 88 |
+
</div>
|
| 89 |
+
|
| 90 |
+
<div id="start-modal" class="fixed inset-0 flex items-center justify-center modal-overlay">
|
| 91 |
+
<div class="bg-gray-800 p-8 rounded-lg modal-content text-center max-w-md w-full">
|
| 92 |
+
<h2 class="text-3xl text-indigo-400 glow-text mb-6">NEON SNAKE</h2>
|
| 93 |
+
<div class="mb-8 text-left text-indigo-200">
|
| 94 |
+
<div class="flex items-center mb-3">
|
| 95 |
+
<i class="fas fa-arrow-up text-xl w-8"></i>
|
| 96 |
+
<span>Move Up</span>
|
| 97 |
+
</div>
|
| 98 |
+
<div class="flex items-center mb-3">
|
| 99 |
+
<i class="fas fa-arrow-down text-xl w-8"></i>
|
| 100 |
+
<span>Move Down</span>
|
| 101 |
+
</div>
|
| 102 |
+
<div class="flex items-center mb-3">
|
| 103 |
+
<i class="fas fa-arrow-left text-xl w-8"></i>
|
| 104 |
+
<span>Move Left</span>
|
| 105 |
+
</div>
|
| 106 |
+
<div class="flex items-center mb-3">
|
| 107 |
+
<i class="fas fa-arrow-right text-xl w-8"></i>
|
| 108 |
+
<span>Move Right</span>
|
| 109 |
+
</div>
|
| 110 |
+
<div class="flex items-center">
|
| 111 |
+
<i class="fas fa-space-shuttle text-xl w-8"></i>
|
| 112 |
+
<span>Pause Game</span>
|
| 113 |
+
</div>
|
| 114 |
+
</div>
|
| 115 |
+
<button id="start-btn" class="bg-emerald-600 hover:bg-emerald-500 text-white py-3 px-8 rounded-lg text-lg transition">
|
| 116 |
+
<i class="fas fa-play mr-2"></i> Start Game
|
| 117 |
+
</button>
|
| 118 |
+
</div>
|
| 119 |
+
</div>
|
| 120 |
+
</div>
|
| 121 |
+
|
| 122 |
+
<div class="mt-6 text-center text-indigo-300 text-sm">
|
| 123 |
+
<p>Use arrow keys to control the snake. Collect food to grow!</p>
|
| 124 |
+
</div>
|
| 125 |
+
|
| 126 |
+
<script>
|
| 127 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 128 |
+
const canvas = document.getElementById('game-board');
|
| 129 |
+
const ctx = canvas.getContext('2d');
|
| 130 |
+
const scoreElement = document.getElementById('score');
|
| 131 |
+
const speedElement = document.getElementById('speed');
|
| 132 |
+
const finalScoreElement = document.getElementById('final-score');
|
| 133 |
+
const gameOverModal = document.getElementById('game-over-modal');
|
| 134 |
+
const startModal = document.getElementById('start-modal');
|
| 135 |
+
const startBtn = document.getElementById('start-btn');
|
| 136 |
+
const restartBtn = document.getElementById('restart-btn');
|
| 137 |
+
const quitBtn = document.getElementById('quit-btn');
|
| 138 |
+
|
| 139 |
+
const gridSize = 20;
|
| 140 |
+
const tileCount = canvas.width / gridSize;
|
| 141 |
+
let speed = 1;
|
| 142 |
+
let score = 0;
|
| 143 |
+
let gameRunning = false;
|
| 144 |
+
let gamePaused = false;
|
| 145 |
+
|
| 146 |
+
// Snake variables
|
| 147 |
+
let snake = [
|
| 148 |
+
{x: 10, y: 10}
|
| 149 |
+
];
|
| 150 |
+
let velocityX = 0;
|
| 151 |
+
let velocityY = 0;
|
| 152 |
+
let nextVelocityX = 0;
|
| 153 |
+
let nextVelocityY = 0;
|
| 154 |
+
|
| 155 |
+
// Food variables
|
| 156 |
+
let foodX = 5;
|
| 157 |
+
let foodY = 5;
|
| 158 |
+
|
| 159 |
+
// Game loop variables
|
| 160 |
+
let lastRenderTime = 0;
|
| 161 |
+
let gameOver = false;
|
| 162 |
+
|
| 163 |
+
// Initialize game
|
| 164 |
+
function initGame() {
|
| 165 |
+
snake = [{x: 10, y: 10}];
|
| 166 |
+
velocityX = 0;
|
| 167 |
+
velocityY = 0;
|
| 168 |
+
nextVelocityX = 0;
|
| 169 |
+
nextVelocityY = 0;
|
| 170 |
+
score = 0;
|
| 171 |
+
speed = 1;
|
| 172 |
+
gameOver = false;
|
| 173 |
+
gameRunning = true;
|
| 174 |
+
gamePaused = false;
|
| 175 |
+
scoreElement.textContent = score;
|
| 176 |
+
speedElement.textContent = speed;
|
| 177 |
+
placeFood();
|
| 178 |
+
window.requestAnimationFrame(gameLoop);
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
// Main game loop
|
| 182 |
+
function gameLoop(currentTime) {
|
| 183 |
+
if (gameOver || !gameRunning) return;
|
| 184 |
+
|
| 185 |
+
window.requestAnimationFrame(gameLoop);
|
| 186 |
+
|
| 187 |
+
const secondsSinceLastRender = (currentTime - lastRenderTime) / (1000 / (7 + speed));
|
| 188 |
+
if (secondsSinceLastRender < 1) return;
|
| 189 |
+
lastRenderTime = currentTime;
|
| 190 |
+
|
| 191 |
+
if (!gamePaused) {
|
| 192 |
+
update();
|
| 193 |
+
}
|
| 194 |
+
draw();
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
// Update game state
|
| 198 |
+
function update() {
|
| 199 |
+
// Apply the next velocity (this prevents direction changes that would cause instant game over)
|
| 200 |
+
velocityX = nextVelocityX;
|
| 201 |
+
velocityY = nextVelocityY;
|
| 202 |
+
|
| 203 |
+
// Move snake
|
| 204 |
+
const head = {x: snake[0].x + velocityX, y: snake[0].y + velocityY};
|
| 205 |
+
|
| 206 |
+
// Check wall collision
|
| 207 |
+
if (head.x < 0 || head.x >= tileCount || head.y < 0 || head.y >= tileCount) {
|
| 208 |
+
gameOver = true;
|
| 209 |
+
endGame();
|
| 210 |
+
return;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
// Check self collision
|
| 214 |
+
for (let i = 0; i < snake.length; i++) {
|
| 215 |
+
if (head.x === snake[i].x && head.y === snake[i].y) {
|
| 216 |
+
gameOver = true;
|
| 217 |
+
endGame();
|
| 218 |
+
return;
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
// Add new head
|
| 223 |
+
snake.unshift(head);
|
| 224 |
+
|
| 225 |
+
// Check food collision
|
| 226 |
+
if (head.x === foodX && head.y === foodY) {
|
| 227 |
+
// Increase score
|
| 228 |
+
score += speed * 10;
|
| 229 |
+
scoreElement.textContent = score;
|
| 230 |
+
|
| 231 |
+
// Increase speed every 50 points
|
| 232 |
+
if (score > 0 && score % 50 === 0) {
|
| 233 |
+
speed++;
|
| 234 |
+
speedElement.textContent = speed;
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
placeFood();
|
| 238 |
+
} else {
|
| 239 |
+
// Remove tail if no food eaten
|
| 240 |
+
snake.pop();
|
| 241 |
+
}
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
// Draw game
|
| 245 |
+
function draw() {
|
| 246 |
+
// Clear canvas
|
| 247 |
+
ctx.fillStyle = '#1e293b';
|
| 248 |
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
| 249 |
+
|
| 250 |
+
// Draw grid lines
|
| 251 |
+
ctx.strokeStyle = '#334155';
|
| 252 |
+
ctx.lineWidth = 0.5;
|
| 253 |
+
for (let i = 0; i < tileCount; i++) {
|
| 254 |
+
ctx.beginPath();
|
| 255 |
+
ctx.moveTo(i * gridSize, 0);
|
| 256 |
+
ctx.lineTo(i * gridSize, canvas.height);
|
| 257 |
+
ctx.stroke();
|
| 258 |
+
|
| 259 |
+
ctx.beginPath();
|
| 260 |
+
ctx.moveTo(0, i * gridSize);
|
| 261 |
+
ctx.lineTo(canvas.width, i * gridSize);
|
| 262 |
+
ctx.stroke();
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
// Draw snake
|
| 266 |
+
snake.forEach((segment, index) => {
|
| 267 |
+
// Head is brighter than body
|
| 268 |
+
const intensity = index === 0 ? 1 : 0.6 - (index * 0.01);
|
| 269 |
+
ctx.fillStyle = `rgba(16, 185, 129, ${intensity})`;
|
| 270 |
+
ctx.strokeStyle = `rgba(167, 243, 208, ${intensity})`;
|
| 271 |
+
|
| 272 |
+
ctx.fillRect(segment.x * gridSize, segment.y * gridSize, gridSize, gridSize);
|
| 273 |
+
ctx.strokeRect(segment.x * gridSize, segment.y * gridSize, gridSize, gridSize);
|
| 274 |
+
});
|
| 275 |
+
|
| 276 |
+
// Draw food
|
| 277 |
+
ctx.fillStyle = '#ef4444';
|
| 278 |
+
ctx.beginPath();
|
| 279 |
+
ctx.arc(
|
| 280 |
+
foodX * gridSize + gridSize / 2,
|
| 281 |
+
foodY * gridSize + gridSize / 2,
|
| 282 |
+
gridSize / 2 - 2,
|
| 283 |
+
0,
|
| 284 |
+
Math.PI * 2
|
| 285 |
+
);
|
| 286 |
+
ctx.fill();
|
| 287 |
+
|
| 288 |
+
// Draw pause message if paused
|
| 289 |
+
if (gamePaused) {
|
| 290 |
+
ctx.fillStyle = 'rgba(255, 255, 255, 0.7)';
|
| 291 |
+
ctx.font = '20px "Press Start 2P"';
|
| 292 |
+
ctx.textAlign = 'center';
|
| 293 |
+
ctx.fillText('PAUSED', canvas.width / 2, canvas.height / 2);
|
| 294 |
+
}
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
// Place food at random position
|
| 298 |
+
function placeFood() {
|
| 299 |
+
let validPosition = false;
|
| 300 |
+
|
| 301 |
+
while (!validPosition) {
|
| 302 |
+
foodX = Math.floor(Math.random() * tileCount);
|
| 303 |
+
foodY = Math.floor(Math.random() * tileCount);
|
| 304 |
+
|
| 305 |
+
validPosition = true;
|
| 306 |
+
|
| 307 |
+
// Make sure food doesn't spawn on snake
|
| 308 |
+
for (let i = 0; i < snake.length; i++) {
|
| 309 |
+
if (snake[i].x === foodX && snake[i].y === foodY) {
|
| 310 |
+
validPosition = false;
|
| 311 |
+
break;
|
| 312 |
+
}
|
| 313 |
+
}
|
| 314 |
+
}
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
// End game
|
| 318 |
+
function endGame() {
|
| 319 |
+
gameRunning = false;
|
| 320 |
+
finalScoreElement.textContent = score;
|
| 321 |
+
gameOverModal.classList.remove('hidden');
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
// Event listeners
|
| 325 |
+
document.addEventListener('keydown', (e) => {
|
| 326 |
+
if (!gameRunning && e.key === ' ') {
|
| 327 |
+
startBtn.click();
|
| 328 |
+
return;
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
switch (e.key) {
|
| 332 |
+
case 'ArrowUp':
|
| 333 |
+
if (velocityY === 0 && !gamePaused) {
|
| 334 |
+
nextVelocityX = 0;
|
| 335 |
+
nextVelocityY = -1;
|
| 336 |
+
}
|
| 337 |
+
break;
|
| 338 |
+
case 'ArrowDown':
|
| 339 |
+
if (velocityY === 0 && !gamePaused) {
|
| 340 |
+
nextVelocityX = 0;
|
| 341 |
+
nextVelocityY = 1;
|
| 342 |
+
}
|
| 343 |
+
break;
|
| 344 |
+
case 'ArrowLeft':
|
| 345 |
+
if (velocityX === 0 && !gamePaused) {
|
| 346 |
+
nextVelocityX = -1;
|
| 347 |
+
nextVelocityY = 0;
|
| 348 |
+
}
|
| 349 |
+
break;
|
| 350 |
+
case 'ArrowRight':
|
| 351 |
+
if (velocityX === 0 && !gamePaused) {
|
| 352 |
+
nextVelocityX = 1;
|
| 353 |
+
nextVelocityY = 0;
|
| 354 |
+
}
|
| 355 |
+
break;
|
| 356 |
+
case ' ':
|
| 357 |
+
if (gameRunning) {
|
| 358 |
+
gamePaused = !gamePaused;
|
| 359 |
+
}
|
| 360 |
+
break;
|
| 361 |
+
}
|
| 362 |
+
});
|
| 363 |
+
|
| 364 |
+
startBtn.addEventListener('click', () => {
|
| 365 |
+
startModal.classList.add('hidden');
|
| 366 |
+
initGame();
|
| 367 |
+
});
|
| 368 |
+
|
| 369 |
+
restartBtn.addEventListener('click', () => {
|
| 370 |
+
gameOverModal.classList.add('hidden');
|
| 371 |
+
initGame();
|
| 372 |
+
});
|
| 373 |
+
|
| 374 |
+
quitBtn.addEventListener('click', () => {
|
| 375 |
+
gameOverModal.classList.add('hidden');
|
| 376 |
+
startModal.classList.remove('hidden');
|
| 377 |
+
});
|
| 378 |
+
|
| 379 |
+
// Touch controls for mobile
|
| 380 |
+
let touchStartX = 0;
|
| 381 |
+
let touchStartY = 0;
|
| 382 |
+
|
| 383 |
+
canvas.addEventListener('touchstart', (e) => {
|
| 384 |
+
touchStartX = e.touches[0].clientX;
|
| 385 |
+
touchStartY = e.touches[0].clientY;
|
| 386 |
+
e.preventDefault();
|
| 387 |
+
}, false);
|
| 388 |
+
|
| 389 |
+
canvas.addEventListener('touchmove', (e) => {
|
| 390 |
+
if (!touchStartX || !touchStartY || gamePaused) return;
|
| 391 |
+
|
| 392 |
+
const touchEndX = e.touches[0].clientX;
|
| 393 |
+
const touchEndY = e.touches[0].clientY;
|
| 394 |
+
|
| 395 |
+
const diffX = touchStartX - touchEndX;
|
| 396 |
+
const diffY = touchStartY - touchEndY;
|
| 397 |
+
|
| 398 |
+
// Horizontal swipe
|
| 399 |
+
if (Math.abs(diffX) > Math.abs(diffY)) {
|
| 400 |
+
if (diffX > 0 && velocityX === 0) {
|
| 401 |
+
// Swipe left
|
| 402 |
+
nextVelocityX = -1;
|
| 403 |
+
nextVelocityY = 0;
|
| 404 |
+
} else if (diffX < 0 && velocityX === 0) {
|
| 405 |
+
// Swipe right
|
| 406 |
+
nextVelocityX = 1;
|
| 407 |
+
nextVelocityY = 0;
|
| 408 |
+
}
|
| 409 |
+
}
|
| 410 |
+
// Vertical swipe
|
| 411 |
+
else {
|
| 412 |
+
if (diffY > 0 && velocityY === 0) {
|
| 413 |
+
// Swipe up
|
| 414 |
+
nextVelocityX = 0;
|
| 415 |
+
nextVelocityY = -1;
|
| 416 |
+
} else if (diffY < 0 && velocityY === 0) {
|
| 417 |
+
// Swipe down
|
| 418 |
+
nextVelocityX = 0;
|
| 419 |
+
nextVelocityY = 1;
|
| 420 |
+
}
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
touchStartX = 0;
|
| 424 |
+
touchStartY = 0;
|
| 425 |
+
e.preventDefault();
|
| 426 |
+
}, false);
|
| 427 |
+
|
| 428 |
+
// Tap to pause
|
| 429 |
+
canvas.addEventListener('click', () => {
|
| 430 |
+
if (gameRunning) {
|
| 431 |
+
gamePaused = !gamePaused;
|
| 432 |
+
}
|
| 433 |
+
});
|
| 434 |
+
});
|
| 435 |
+
</script>
|
| 436 |
+
<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=Atum09/gg" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 437 |
+
</html>
|