Add 2 files
Browse filesFiles changed (2)
- README.md+7-5
- index.html+642-19
12345678910---title: Pacmanemoji: 🌖colorFrom: greencolorTo: indigosdk: staticpinned: false---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference123456789101112---title: pacmanemoji: 🐳colorFrom: bluecolorTo: graysdk: staticpinned: falsetags:- deepsite---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
12345678910111213141516171819<!doctype html><html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width" /><title>My static Space</title><link rel="stylesheet" href="style.css" /></head><body><div class="card"><h1>Welcome to your static Space!</h1><p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p><p>Also don't forget to check the<a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.</p></div></body></html>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Tailwind Pacman</title><script src="https://cdn.tailwindcss.com"></script><style>@keyframes pacman-mouth {0% { clip-path: polygon(50% 50%, 100% 0%, 100% 100%); }50% { clip-path: polygon(50% 50%, 100% 25%, 100% 75%); }100% { clip-path: polygon(50% 50%, 100% 0%, 100% 100%); }}@keyframes ghost-float {0%, 100% { transform: translateY(0); }50% { transform: translateY(-5px); }}@keyframes scared-ghost {0%, 100% { background-color: #2563eb; }50% { background-color: #93c5fd; }}.pacman {animation: pacman-mouth 0.5s infinite;clip-path: polygon(50% 50%, 100% 0%, 100% 100%);}.ghost {animation: ghost-float 2s infinite;}.scared {animation: scared-ghost 0.5s infinite;}#game-board {position: relative;background-color: #111827;border: 4px solid #f59e0b;}.wall {background-color: #1e40af;}.pellet {width: 8px;height: 8px;background-color: #fef3c7;border-radius: 50%;}.power-pellet {width: 16px;height: 16px;background-color: #fef3c7;border-radius: 50%;animation: pulse 1s infinite;}@keyframes pulse {0%, 100% { transform: scale(1); opacity: 1; }50% { transform: scale(1.3); opacity: 0.8; }}</style></head><body class="bg-gray-900 text-white min-h-screen flex flex-col items-center justify-center p-4"><div class="text-center mb-6"><h1 class="text-4xl font-bold text-yellow-300 mb-2">Tailwind Pacman</h1><div class="flex justify-center items-center gap-8 mb-4"><div class="flex items-center"><div class="w-6 h-6 bg-yellow-300 rounded-full mr-2"></div><span>Score: <span id="score">0</span></span></div><div class="flex items-center"><div class="w-6 h-6 bg-red-500 rounded-full mr-2"></div><span>Lives: <span id="lives">3</span></span></div></div><button id="start-btn" class="bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-6 rounded-full transition">Start Game</button></div><div id="game-board" class="grid grid-cols-28 grid-rows-31 gap-0 w-[560px] h-[620px] relative overflow-hidden"><!-- Game elements will be generated by JavaScript --></div><div class="mt-6 text-center"><p class="text-gray-400">Use arrow keys to move. Eat all pellets to win!</p><p class="text-gray-400 mt-2">Eat power pellets to scare ghosts!</p></div><script>document.addEventListener('DOMContentLoaded', () => {// Game constantsconst GRID_SIZE = 28;const CELL_SIZE = 20;const PACMAN_SPEED = 2;const GHOST_SPEED = 1.5;const SCARED_DURATION = 10000; // 10 seconds// Game statelet score = 0;let lives = 3;let gameRunning = false;let scaredTimer = null;let ghostsScared = false;let pelletsRemaining = 0;// DOM elementsconst gameBoard = document.getElementById('game-board');const scoreDisplay = document.getElementById('score');const livesDisplay = document.getElementById('lives');const startBtn = document.getElementById('start-btn');// Game elementslet pacman = null;let ghosts = [];let pellets = [];let powerPellets = [];let walls = [];// Movementlet direction = 'right';let nextDirection = 'right';let moving = false;// Maze layout (1 = wall, 0 = path, p = pellet, P = power pellet)const mazeLayout = ['1111111111111111111111111111','1pppppppppppp1pppppppppppp1','1p1111p11111p1p11111p1111p1','1P1111p11111p1p11111p1111P1','1p1111p11111p1p11111p1111p1','1pppppppppppppppppppppppp1','1p1111p1p111111111p1p1111p1','1p1111p1p111111111p1p1111p1','1ppppppp1pppp1pppp1ppppppp1','1111111p1110p1p0111p1111111','0000011p1110p1p0111p1100000','0000011p100000000011p1100000','0000011p100111111011p1100000','1111111p100100001011p1111111','0000000ppp00p00000ppp0000000','1111111p100111111011p1111111','0000011p100000000011p1100000','0000011p100111111011p1100000','1111111p100p11111011p1111111','1ppppppppppp1ppppppppppppp1','1p1111p11111p1p11111p1111p1','1p1111p11111p1p11111p1111p1','1Ppppp1pppppp0pppppp1ppppP1','111p1p1p1p1111111p1p1p1p1111','111p1p1p1p1111111p1p1p1p1111','1ppppp1pppppp1pppppp1pppppp1','1p1111111111p1p11111111111p1','1p1111111111p1p11111111111p1','1ppppppppppppppppppppppppp1','1111111111111111111111111111'];// Initialize gamefunction initGame() {clearGame();createMaze();createPacman();createGhosts();updateDisplay();}// Clear game elementsfunction clearGame() {gameBoard.innerHTML = '';ghosts = [];pellets = [];powerPellets = [];walls = [];pelletsRemaining = 0;direction = 'right';nextDirection = 'right';moving = false;clearTimeout(scaredTimer);ghostsScared = false;}// Create maze from layoutfunction createMaze() {for (let y = 0; y < mazeLayout.length; y++) {for (let x = 0; x < mazeLayout[y].length; x++) {const cell = document.createElement('div');cell.className = 'absolute';cell.style.width = `${CELL_SIZE}px`;cell.style.height = `${CELL_SIZE}px`;cell.style.left = `${x * CELL_SIZE}px`;cell.style.top = `${y * CELL_SIZE}px`;switch (mazeLayout[y][x]) {case '1':cell.classList.add('wall');walls.push({ x, y });break;case 'p':createPellet(x, y);pelletsRemaining++;break;case 'P':createPowerPellet(x, y);pelletsRemaining++;break;}gameBoard.appendChild(cell);}}}// Create a pelletfunction createPellet(x, y) {const pellet = document.createElement('div');pellet.className = 'pellet absolute';pellet.style.left = `${x * CELL_SIZE + CELL_SIZE / 2 - 4}px`;pellet.style.top = `${y * CELL_SIZE + CELL_SIZE / 2 - 4}px`;gameBoard.appendChild(pellet);pellets.push({ element: pellet, x, y });}// Create a power pelletfunction createPowerPellet(x, y) {const powerPellet = document.createElement('div');powerPellet.className = 'power-pellet absolute';powerPellet.style.left = `${x * CELL_SIZE + CELL_SIZE / 2 - 8}px`;powerPellet.style.top = `${y * CELL_SIZE + CELL_SIZE / 2 - 8}px`;gameBoard.appendChild(powerPellet);powerPellets.push({ element: powerPellet, x, y });}// Create Pacmanfunction createPacman() {pacman = document.createElement('div');pacman.className = 'pacman bg-yellow-300 absolute rounded-full';pacman.style.width = `${CELL_SIZE}px`;pacman.style.height = `${CELL_SIZE}px`;pacman.style.left = `${14 * CELL_SIZE}px`;pacman.style.top = `${23 * CELL_SIZE}px`;pacman.style.transform = 'rotate(0deg)';gameBoard.appendChild(pacman);}// Create ghostsfunction createGhosts() {const ghostColors = ['bg-red-500', 'bg-pink-500', 'bg-cyan-400', 'bg-orange-400'];const ghostPositions = [{ x: 13, y: 11 },{ x: 14, y: 11 },{ x: 13, y: 14 },{ x: 14, y: 14 }];ghostPositions.forEach((pos, index) => {const ghost = document.createElement('div');ghost.className = `ghost ${ghostColors[index]} absolute rounded-t-full`;ghost.style.width = `${CELL_SIZE}px`;ghost.style.height = `${CELL_SIZE}px`;ghost.style.left = `${pos.x * CELL_SIZE}px`;ghost.style.top = `${pos.y * CELL_SIZE}px`;// Add ghost eyesconst eyes = document.createElement('div');eyes.className = 'flex justify-between absolute w-full px-1 top-1';eyes.innerHTML = `<div class="w-2 h-2 bg-white rounded-full flex items-center justify-center"><div class="w-1 h-1 bg-black rounded-full"></div></div><div class="w-2 h-2 bg-white rounded-full flex items-center justify-center"><div class="w-1 h-1 bg-black rounded-full"></div></div>`;ghost.appendChild(eyes);gameBoard.appendChild(ghost);ghosts.push({element: ghost,x: pos.x,y: pos.y,direction: ['up', 'down', 'left', 'right'][Math.floor(Math.random() * 4)],speed: GHOST_SPEED,isScared: false});});}// Update score and lives displayfunction updateDisplay() {scoreDisplay.textContent = score;livesDisplay.textContent = lives;}// Start the gamefunction startGame() {if (gameRunning) return;initGame();gameRunning = true;startBtn.textContent = 'Restart Game';moving = true;// Game loopconst gameLoop = setInterval(() => {if (!gameRunning) {clearInterval(gameLoop);return;}movePacman();moveGhosts();checkCollisions();// Win conditionif (pelletsRemaining === 0) {gameOver(true);}}, 16); // ~60fps}// Move Pacmanfunction movePacman() {if (!moving) return;let newX = Math.floor(parseInt(pacman.style.left) / CELL_SIZE);let newY = Math.floor(parseInt(pacman.style.top) / CELL_SIZE);// Check if Pacman is centered in a cell to change directionconst pacmanLeft = parseInt(pacman.style.left);const pacmanTop = parseInt(pacman.style.top);const centeredX = pacmanLeft % CELL_SIZE === 0;const centeredY = pacmanTop % CELL_SIZE === 0;if (centeredX && centeredY) {// Try to change direction if possibleconst tempDirection = direction;direction = nextDirection;if (canMove(newX, newY, direction)) {// Direction changed successfully} else if (canMove(newX, newY, tempDirection)) {direction = tempDirection;} else {direction = tempDirection;moving = false;return;}// Update Pacman's rotationswitch (direction) {case 'up': pacman.style.transform = 'rotate(-90deg)'; break;case 'down': pacman.style.transform = 'rotate(90deg)'; break;case 'left': pacman.style.transform = 'rotate(180deg)'; break;case 'right': pacman.style.transform = 'rotate(0deg)'; break;}}// Move Pacmanswitch (direction) {case 'up':pacman.style.top = `${parseInt(pacman.style.top) - PACMAN_SPEED}px`;break;case 'down':pacman.style.top = `${parseInt(pacman.style.top) + PACMAN_SPEED}px`;break;case 'left':pacman.style.left = `${parseInt(pacman.style.left) - PACMAN_SPEED}px`;break;case 'right':pacman.style.left = `${parseInt(pacman.style.left) + PACMAN_SPEED}px`;break;}// Handle tunnel/wrap-aroundif (parseInt(pacman.style.left) < -CELL_SIZE) {pacman.style.left = `${GRID_SIZE * CELL_SIZE}px`;} else if (parseInt(pacman.style.left) > GRID_SIZE * CELL_SIZE) {pacman.style.left = `${-CELL_SIZE}px`;}// Check for pellet collisioncheckPelletCollision();}// Move ghostsfunction moveGhosts() {ghosts.forEach(ghost => {let ghostX = Math.floor(parseInt(ghost.element.style.left) / CELL_SIZE);let ghostY = Math.floor(parseInt(ghost.element.style.top) / CELL_SIZE);// Check if ghost is centered in a cell to change directionconst ghostLeft = parseInt(ghost.element.style.left);const ghostTop = parseInt(ghost.element.style.top);const centeredX = ghostLeft % CELL_SIZE === 0;const centeredY = ghostTop % CELL_SIZE === 0;if (centeredX && centeredY) {// Get possible directions (not opposite current direction)const possibleDirections = ['up', 'down', 'left', 'right'].filter(dir => {if (dir === 'up' && ghost.direction === 'down') return false;if (dir === 'down' && ghost.direction === 'up') return false;if (dir === 'left' && ghost.direction === 'right') return false;if (dir === 'right' && ghost.direction === 'left') return false;return canMove(ghostX, ghostY, dir);});// Choose random directionif (possibleDirections.length > 0) {ghost.direction = possibleDirections[Math.floor(Math.random() * possibleDirections.length)];}}// Move ghostswitch (ghost.direction) {case 'up':ghost.element.style.top = `${parseInt(ghost.element.style.top) - ghost.speed}px`;break;case 'down':ghost.element.style.top = `${parseInt(ghost.element.style.top) + ghost.speed}px`;break;case 'left':ghost.element.style.left = `${parseInt(ghost.element.style.left) - ghost.speed}px`;break;case 'right':ghost.element.style.left = `${parseInt(ghost.element.style.left) + ghost.speed}px`;break;}// Handle tunnel/wrap-aroundif (parseInt(ghost.element.style.left) < -CELL_SIZE) {ghost.element.style.left = `${GRID_SIZE * CELL_SIZE}px`;} else if (parseInt(ghost.element.style.left) > GRID_SIZE * CELL_SIZE) {ghost.element.style.left = `${-CELL_SIZE}px`;}});}// Check if movement is possiblefunction canMove(x, y, dir) {let newX = x;let newY = y;switch (dir) {case 'up': newY--; break;case 'down': newY++; break;case 'left': newX--; break;case 'right': newX++; break;}// Check boundariesif (newX < 0 || newX >= GRID_SIZE || newY < 0 || newY >= mazeLayout.length) {return false;}// Check wallsreturn mazeLayout[newY][newX] !== '1';}// Check pellet collisionsfunction checkPelletCollision() {const pacmanX = Math.round(parseInt(pacman.style.left) / CELL_SIZE);const pacmanY = Math.round(parseInt(pacman.style.top) / CELL_SIZE);// Check regular pelletspellets.forEach((pellet, index) => {if (pellet.x === pacmanX && pellet.y === pacmanY) {pellet.element.remove();pellets.splice(index, 1);score += 10;pelletsRemaining--;updateDisplay();}});// Check power pelletspowerPellets.forEach((pellet, index) => {if (pellet.x === pacmanX && pellet.y === pacmanY) {pellet.element.remove();powerPellets.splice(index, 1);score += 50;pelletsRemaining--;scareGhosts();updateDisplay();}});}// Scare ghosts (make them vulnerable)function scareGhosts() {ghostsScared = true;ghosts.forEach(ghost => {ghost.isScared = true;ghost.element.classList.remove('bg-red-500', 'bg-pink-500', 'bg-cyan-400', 'bg-orange-400');ghost.element.classList.add('scared');ghost.speed = GHOST_SPEED * 0.7; // Slow down when scared});// Reset scared state after durationclearTimeout(scaredTimer);scaredTimer = setTimeout(() => {ghostsScared = false;ghosts.forEach(ghost => {ghost.isScared = false;ghost.element.classList.remove('scared');ghost.element.classList.add('bg-red-500', 'bg-pink-500', 'bg-cyan-400', 'bg-orange-400');ghost.speed = GHOST_SPEED;});}, SCARED_DURATION);}// Check collisions with ghostsfunction checkCollisions() {const pacmanX = Math.round(parseInt(pacman.style.left) / CELL_SIZE);const pacmanY = Math.round(parseInt(pacman.style.top) / CELL_SIZE);ghosts.forEach((ghost, index) => {const ghostX = Math.round(parseInt(ghost.element.style.left) / CELL_SIZE);const ghostY = Math.round(parseInt(ghost.element.style.top) / CELL_SIZE);if (pacmanX === ghostX && pacmanY === ghostY) {if (ghost.isScared) {// Eat ghostghost.element.remove();ghosts.splice(index, 1);score += 200;updateDisplay();// Respawn ghost after delaysetTimeout(() => {const ghost = document.createElement('div');ghost.className = `ghost bg-red-500 absolute rounded-t-full`;ghost.style.width = `${CELL_SIZE}px`;ghost.style.height = `${CELL_SIZE}px`;ghost.style.left = `${14 * CELL_SIZE}px`;ghost.style.top = `${11 * CELL_SIZE}px`;const eyes = document.createElement('div');eyes.className = 'flex justify-between absolute w-full px-1 top-1';eyes.innerHTML = `<div class="w-2 h-2 bg-white rounded-full flex items-center justify-center"><div class="w-1 h-1 bg-black rounded-full"></div></div><div class="w-2 h-2 bg-white rounded-full flex items-center justify-center"><div class="w-1 h-1 bg-black rounded-full"></div></div>`;ghost.appendChild(eyes);gameBoard.appendChild(ghost);ghosts.push({element: ghost,x: 14,y: 11,direction: ['up', 'down', 'left', 'right'][Math.floor(Math.random() * 4)],speed: GHOST_SPEED,isScared: false});}, 3000);} else {// Lose lifelives--;updateDisplay();if (lives <= 0) {gameOver(false);} else {// Reset positionspacman.style.left = `${14 * CELL_SIZE}px`;pacman.style.top = `${23 * CELL_SIZE}px`;direction = 'right';nextDirection = 'right';pacman.style.transform = 'rotate(0deg)';ghosts.forEach(g => {g.element.style.left = `${14 * CELL_SIZE}px`;g.element.style.top = `${11 * CELL_SIZE}px`;});// Pause brieflymoving = false;setTimeout(() => {moving = true;}, 1000);}}}});}// Game overfunction gameOver(won) {gameRunning = false;moving = false;if (won) {alert(`Congratulations! You won with a score of ${score}!`);} else {alert(`Game Over! Your score was ${score}.`);}}// Event listenersstartBtn.addEventListener('click', startGame);document.addEventListener('keydown', (e) => {if (!gameRunning) return;switch (e.key) {case 'ArrowUp':nextDirection = 'up';break;case 'ArrowDown':nextDirection = 'down';break;case 'ArrowLeft':nextDirection = 'left';break;case 'ArrowRight':nextDirection = 'right';break;}// Start moving if not alreadyif (!moving) {direction = nextDirection;moving = true;}});});</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=Engelko/pacman" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body></html>
README.md+7-5
index.html+642-19