space-br / index.html
Vicky-07's picture
Add 3 files
7c9f446 verified
Raw History Blame Contribute Delete
75 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <title>Offline Battle Royale</title> <script src="https://cdn.tailwindcss.com"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> <style> /* Custom styles */ .game-container { touch-action: manipulation; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .joystick-area { position: absolute; bottom: 20px; left: 20px; width: 120px; height: 120px; background-color: rgba(255, 255, 255, 0.2); border-radius: 50%; } .joystick { position: absolute; width: 60px; height: 60px; background-color: rgba(255, 255, 255, 0.5); border-radius: 50%; top: 30px; left: 30px; } .action-button { position: absolute; bottom: 40px; right: 40px; width: 80px; height: 80px; background-color: rgba(255, 0, 0, 0.5); border-radius: 50%; display: flex; justify-content: center; align-items: center; color: white; font-size: 24px; } .map { position: relative; width: 1000px; height: 1000px; background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="1000" height="1000" viewBox="0 0 1000 1000"><rect width="100%" height="100%" fill="%234CAF50"/><rect x="100" y="100" width="300" height="300" fill="%238BC34A" stroke="%233E2723" stroke-width="5"/><rect x="600" y="100" width="300" height="300" fill="%238BC34A" stroke="%233E2723" stroke-width="5"/><rect x="100" y="600" width="300" height="300" fill="%238BC34A" stroke="%233E2723" stroke-width="5"/><rect x="600" y="600" width="300" height="300" fill="%238BC34A" stroke="%233E2723" stroke-width="5"/><circle cx="500" cy="500" r="150" fill="%23FFC107" stroke="%233E2723" stroke-width="5"/><path d="M500,100 L500,900 M100,500 L900,500" stroke="%233E2723" stroke-width="3" stroke-dasharray="10,5"/></svg>'); transform-origin: 0 0; } .player { position: absolute; width: 30px; height: 30px; border-radius: 50%; display: flex; justify-content: center; align-items: center; color: white; font-weight: bold; z-index: 10; } .enemy { position: absolute; width: 30px; height: 30px; border-radius: 50%; background-color: red; display: flex; justify-content: center; align-items: center; color: white; font-weight: bold; z-index: 5; } .loot { position: absolute; width: 20px; height: 20px; border-radius: 50%; background-color: gold; z-index: 2; } .safe-zone { position: absolute; border-radius: 50%; border: 3px dashed white; box-sizing: border-box; z-index: 1; } .health-bar { position: absolute; top: -10px; left: 0; width: 100%; height: 5px; background-color: #ddd; } .health-fill { height: 100%; background-color: #4CAF50; } .bullet { position: absolute; width: 6px; height: 6px; background-color: black; border-radius: 50%; z-index: 8; } .damage-indicator { position: absolute; color: red; font-weight: bold; font-size: 16px; animation: fadeUp 1s forwards; z-index: 20; } @keyframes fadeUp { 0% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-30px); } } .zoom-control { position: absolute; right: 20px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 10px; } .zoom-button { width: 40px; height: 40px; background-color: rgba(0, 0, 0, 0.5); border-radius: 50%; display: flex; justify-content: center; align-items: center; color: white; font-size: 20px; } .inventory-item { border: 1px solid #ddd; border-radius: 5px; padding: 5px; display: flex; flex-direction: column; align-items: center; background-color: rgba(255, 255, 255, 0.1); } .inventory-item.equipped { border-color: gold; background-color: rgba(255, 215, 0, 0.2); } .progress-bar { height: 5px; background-color: #e0e0e0; border-radius: 2px; overflow: hidden; } .progress-fill { height: 100%; background-color: #4CAF50; } /* Character selection */ .character-option { border: 3px solid transparent; border-radius: 10px; padding: 10px; transition: all 0.3s; cursor: pointer; } .character-option.selected { border-color: gold; background-color: rgba(255, 215, 0, 0.2); } /* Responsive adjustments */ @media (max-width: 640px) { .character-option { padding: 5px; } } </style> </head> <body class="bg-gray-900 text-white overflow-hidden game-container"> <!-- Main Menu --> <div id="main-menu" class="fixed inset-0 bg-gray-900 flex flex-col items-center justify-center z-50 p-4"> <h1 class="text-4xl md:text-6xl font-bold mb-8 text-yellow-400">OFFLINE BATTLE ROYALE</h1> <div class="flex flex-col gap-4 w-full max-w-md"> <button id="new-game-btn" class="bg-green-600 hover:bg-green-700 text-white font-bold py-3 px-6 rounded-lg text-xl transition"> <i class="fas fa-play mr-2"></i> New Game </button> <button id="continue-game-btn" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 px-6 rounded-lg text-xl transition"> <i class="fas fa-undo mr-2"></i> Continue Game </button> <button id="leaderboard-btn" class="bg-purple-600 hover:bg-purple-700 text-white font-bold py-3 px-6 rounded-lg text-xl transition"> <i class="fas fa-trophy mr-2"></i> Leaderboard </button> <button id="how-to-play-btn" class="bg-gray-600 hover:bg-gray-700 text-white font-bold py-3 px-6 rounded-lg text-xl transition"> <i class="fas fa-question-circle mr-2"></i> How to Play </button> </div> </div> <!-- Character Selection --> <div id="character-selection" class="fixed inset-0 bg-gray-900 flex flex-col items-center justify-center z-40 p-4 hidden"> <h2 class="text-3xl font-bold mb-8 text-yellow-400">SELECT YOUR CHARACTER</h2> <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8"> <div class="character-option" data-character="soldier"> <div class="bg-gray-800 rounded-lg p-4 flex flex-col items-center"> <div class="w-24 h-24 bg-blue-500 rounded-full mb-3 flex items-center justify-center text-4xl"> <i class="fas fa-user-shield"></i> </div> <h3 class="text-xl font-bold">Soldier</h3> <p class="text-sm text-gray-300">Balanced stats</p> <div class="mt-2 w-full"> <div class="flex justify-between text-xs mb-1"> <span>Health</span> <span>80%</span> </div> <div class="progress-bar"> <div class="progress-fill" style="width: 80%"></div> </div> </div> <div class="mt-1 w-full"> <div class="flex justify-between text-xs mb-1"> <span>Speed</span> <span>70%</span> </div> <div class="progress-bar"> <div class="progress-fill" style="width: 70%"></div> </div> </div> <div class="mt-1 w-full"> <div class="flex justify-between text-xs mb-1"> <span>Damage</span> <span>75%</span> </div> <div class="progress-bar"> <div class="progress-fill" style="width: 75%"></div> </div> </div> </div> </div> <div class="character-option" data-character="scout"> <div class="bg-gray-800 rounded-lg p-4 flex flex-col items-center"> <div class="w-24 h-24 bg-green-500 rounded-full mb-3 flex items-center justify-center text-4xl"> <i class="fas fa-running"></i> </div> <h3 class="text-xl font-bold">Scout</h3> <p class="text-sm text-gray-300">Fast and agile</p> <div class="mt-2 w-full"> <div class="flex justify-between text-xs mb-1"> <span>Health</span> <span>60%</span> </div> <div class="progress-bar"> <div class="progress-fill" style="width: 60%"></div> </div> </div> <div class="mt-1 w-full"> <div class="flex justify-between text-xs mb-1"> <span>Speed</span> <span>90%</span> </div> <div class="progress-bar"> <div class="progress-fill" style="width: 90%"></div> </div> </div> <div class="mt-1 w-full"> <div class="flex justify-between text-xs mb-1"> <span>Damage</span> <span>50%</span> </div> <div class="progress-bar"> <div class="progress-fill" style="width: 50%"></div> </div> </div> </div> </div> <div class="character-option" data-character="tank"> <div class="bg-gray-800 rounded-lg p-4 flex flex-col items-center"> <div class="w-24 h-24 bg-red-500 rounded-full mb-3 flex items-center justify-center text-4xl"> <i class="fas fa-shield-alt"></i> </div> <h3 class="text-xl font-bold">Tank</h3> <p class="text-sm text-gray-300">Strong and tough</p> <div class="mt-2 w-full"> <div class="flex justify-between text-xs mb-1"> <span>Health</span> <span>100%</span> </div> <div class="progress-bar"> <div class="progress-fill" style="width: 100%"></div> </div> </div> <div class="mt-1 w-full"> <div class="flex justify-between text-xs mb-1"> <span>Speed</span> <span>40%</span> </div> <div class="progress-bar"> <div class="progress-fill" style="width: 40%"></div> </div> </div> <div class="mt-1 w-full"> <div class="flex justify-between text-xs mb-1"> <span>Damage</span> <span>85%</span> </div> <div class="progress-bar"> <div class="progress-fill" style="width: 85%"></div> </div> </div> </div> </div> </div> <div class="flex gap-4"> <button id="back-to-menu-btn" class="bg-gray-600 hover:bg-gray-700 text-white font-bold py-2 px-6 rounded-lg transition"> <i class="fas fa-arrow-left mr-2"></i> Back </button> <button id="start-game-btn" class="bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-6 rounded-lg transition"> <i class="fas fa-play mr-2"></i> Start Game </button> </div> </div> <!-- How to Play --> <div id="how-to-play" class="fixed inset-0 bg-gray-900 flex flex-col items-center justify-center z-40 p-4 hidden overflow-y-auto"> <div class="max-w-2xl w-full bg-gray-800 rounded-lg p-6"> <h2 class="text-3xl font-bold mb-6 text-yellow-400">HOW TO PLAY</h2> <div class="space-y-4"> <div class="flex items-start gap-3"> <div class="bg-blue-600 rounded-full w-8 h-8 flex items-center justify-center flex-shrink-0"> <i class="fas fa-joystick text-white"></i> </div> <div> <h3 class="font-bold text-lg">Movement</h3> <p class="text-gray-300">Use the virtual joystick on the left side of the screen to move your character.</p> </div> </div> <div class="flex items-start gap-3"> <div class="bg-red-600 rounded-full w-8 h-8 flex items-center justify-center flex-shrink-0"> <i class="fas fa-fire text-white"></i> </div> <div> <h3 class="font-bold text-lg">Shooting</h3> <p class="text-gray-300">Tap the red action button on the right to shoot. Your character will fire in the direction they're facing.</p> </div> </div> <div class="flex items-start gap-3"> <div class="bg-purple-600 rounded-full w-8 h-8 flex items-center justify-center flex-shrink-0"> <i class="fas fa-search text-white"></i> </div> <div> <h3 class="font-bold text-lg">Looting</h3> <p class="text-gray-300">Walk over loot items to pick them up. Open your inventory to equip weapons and use healing items.</p> </div> </div> <div class="flex items-start gap-3"> <div class="bg-green-600 rounded-full w-8 h-8 flex items-center justify-center flex-shrink-0"> <i class="fas fa-map-marked-alt text-white"></i> </div> <div> <h3 class="font-bold text-lg">Safe Zone</h3> <p class="text-gray-300">The safe zone will shrink over time. Stay inside the white circle to avoid taking damage.</p> </div> </div> <div class="flex items-start gap-3"> <div class="bg-yellow-600 rounded-full w-8 h-8 flex items-center justify-center flex-shrink-0"> <i class="fas fa-trophy text-white"></i> </div> <div> <h3 class="font-bold text-lg">Victory</h3> <p class="text-gray-300">Be the last player standing to win the match and earn rewards.</p> </div> </div> </div> <div class="mt-8"> <button id="back-from-help-btn" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-6 rounded-lg transition"> <i class="fas fa-arrow-left mr-2"></i> Back to Menu </button> </div> </div> </div> <!-- Leaderboard --> <div id="leaderboard" class="fixed inset-0 bg-gray-900 flex flex-col items-center justify-center z-40 p-4 hidden overflow-y-auto"> <div class="max-w-2xl w-full bg-gray-800 rounded-lg p-6"> <h2 class="text-3xl font-bold mb-6 text-yellow-400">LEADERBOARD</h2> <div class="overflow-x-auto"> <table class="w-full"> <thead> <tr class="bg-gray-700"> <th class="py-2 px-4 text-left">Rank</th> <th class="py-2 px-4 text-left">Character</th> <th class="py-2 px-4 text-left">Kills</th> <th class="py-2 px-4 text-left">Survival Time</th> <th class="py-2 px-4 text-left">Date</th> </tr> </thead> <tbody id="leaderboard-entries"> <!-- Leaderboard entries will be added here --> </tbody> </table> </div> <div class="mt-8"> <button id="back-from-leaderboard-btn" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-6 rounded-lg transition"> <i class="fas fa-arrow-left mr-2"></i> Back to Menu </button> </div> </div> </div> <!-- Game UI --> <div id="game-ui" class="fixed inset-0 flex flex-col hidden"> <!-- Top Bar --> <div class="bg-black bg-opacity-50 p-3 flex justify-between items-center"> <div class="flex items-center gap-3"> <div class="relative w-24 h-6 bg-gray-700 rounded-full overflow-hidden"> <div id="health-bar" class="h-full bg-green-500" style="width: 100%"></div> <div class="absolute inset-0 flex items-center justify-center text-xs font-bold text-white"> <span id="health-text">100/100</span> </div> </div> <div class="flex items-center gap-1"> <i class="fas fa-bolt text-yellow-400"></i> <span id="ammo-count">30</span>/<span id="ammo-total">90</span> </div> <div class="flex items-center gap-1"> <i class="fas fa-user-friends text-red-400"></i> <span id="players-left">24</span> </div> </div> <div class="flex items-center gap-2"> <button id="inventory-btn" class="bg-gray-700 hover:bg-gray-600 text-white p-2 rounded-full transition"> <i class="fas fa-backpack"></i> </button> <button id="pause-btn" class="bg-gray-700 hover:bg-gray-600 text-white p-2 rounded-full transition"> <i class="fas fa-pause"></i> </button> </div> </div> <!-- Game View --> <div class="flex-1 relative overflow-hidden"> <div id="game-view" class="absolute inset-0 overflow-hidden"> <div id="map" class="map"> <!-- Safe zone will be added here --> <!-- Players and enemies will be added here --> <!-- Loot items will be added here --> </div> </div> <!-- Controls --> <div class="joystick-area" id="joystick-area"> <div class="joystick" id="joystick"></div> </div> <div class="action-button" id="shoot-btn"> <i class="fas fa-fire"></i> </div> <div class="zoom-control"> <button id="zoom-in-btn" class="zoom-button"> <i class="fas fa-search-plus"></i> </button> <button id="zoom-out-btn" class="zoom-button"> <i class="fas fa-search-minus"></i> </button> </div> </div> <!-- Mini Map --> <div class="bg-black bg-opacity-50 p-2 flex justify-center"> <div id="mini-map" class="w-32 h-32 relative overflow-hidden border border-gray-600"> <!-- Mini map content will be added here --> </div> </div> </div> <!-- Inventory --> <div id="inventory" class="fixed inset-0 bg-gray-900 bg-opacity-90 flex flex-col items-center justify-center z-50 p-4 hidden"> <div class="w-full max-w-md bg-gray-800 rounded-lg p-6"> <h2 class="text-2xl font-bold mb-4 text-yellow-400">INVENTORY</h2> <div class="mb-4"> <h3 class="font-bold mb-2">Weapons</h3> <div id="weapons-container" class="grid grid-cols-2 gap-2"> <!-- Weapons will be added here --> </div> </div> <div class="mb-4"> <h3 class="font-bold mb-2">Healing Items</h3> <div id="healing-container" class="grid grid-cols-3 gap-2"> <!-- Healing items will be added here --> </div> </div> <div class="mt-4"> <button id="close-inventory-btn" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-6 rounded-lg w-full transition"> <i class="fas fa-times mr-2"></i> Close </button> </div> </div> </div> <!-- Pause Menu --> <div id="pause-menu" class="fixed inset-0 bg-gray-900 bg-opacity-90 flex flex-col items-center justify-center z-50 p-4 hidden"> <h2 class="text-4xl font-bold mb-8 text-yellow-400">GAME PAUSED</h2> <div class="flex flex-col gap-4 w-full max-w-xs"> <button id="resume-game-btn" class="bg-green-600 hover:bg-green-700 text-white font-bold py-3 px-6 rounded-lg transition"> <i class="fas fa-play mr-2"></i> Resume </button> <button id="restart-game-btn" class="bg-yellow-600 hover:bg-yellow-700 text-white font-bold py-3 px-6 rounded-lg transition"> <i class="fas fa-redo mr-2"></i> Restart </button> <button id="quit-to-menu-btn" class="bg-red-600 hover:bg-red-700 text-white font-bold py-3 px-6 rounded-lg transition"> <i class="fas fa-sign-out-alt mr-2"></i> Quit to Menu </button> </div> </div> <!-- Game Over Screen --> <div id="game-over" class="fixed inset-0 bg-gray-900 bg-opacity-90 flex flex-col items-center justify-center z-50 p-4 hidden"> <div class="bg-gray-800 rounded-lg p-8 max-w-md w-full text-center"> <h2 id="game-over-title" class="text-4xl font-bold mb-4 text-red-500">DEFEAT</h2> <div class="space-y-4 mb-6"> <div class="flex justify-between"> <span>Kills:</span> <span id="final-kills" class="font-bold">0</span> </div> <div class="flex justify-between"> <span>Damage Dealt:</span> <span id="final-damage" class="font-bold">0</span> </div> <div class="flex justify-between"> <span>Survival Time:</span> <span id="final-time" class="font-bold">0:00</span> </div> <div class="flex justify-between"> <span>Rank:</span> <span id="final-rank" class="font-bold">#24</span> </div> </div> <div class="flex flex-col gap-3"> <button id="play-again-btn" class="bg-green-600 hover:bg-green-700 text-white font-bold py-3 px-6 rounded-lg transition"> <i class="fas fa-redo mr-2"></i> Play Again </button> <button id="game-over-menu-btn" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 px-6 rounded-lg transition"> <i class="fas fa-home mr-2"></i> Main Menu </button> </div> </div> </div> <!-- Victory Screen --> <div id="victory-screen" class="fixed inset-0 bg-gray-900 bg-opacity-90 flex flex-col items-center justify-center z-50 p-4 hidden"> <div class="bg-gray-800 rounded-lg p-8 max-w-md w-full text-center"> <h2 class="text-4xl font-bold mb-4 text-yellow-400">VICTORY!</h2> <p class="text-xl mb-6">You are the last survivor!</p> <div class="space-y-4 mb-6"> <div class="flex justify-between"> <span>Kills:</span> <span id="victory-kills" class="font-bold">0</span> </div> <div class="flex justify-between"> <span>Damage Dealt:</span> <span id="victory-damage" class="font-bold">0</span> </div> <div class="flex justify-between"> <span>Survival Time:</span> <span id="victory-time" class="font-bold">0:00</span> </div> <div class="flex justify-between"> <span>XP Earned:</span> <span id="victory-xp" class="font-bold">1000</span> </div> </div> <div class="flex flex-col gap-3"> <button id="victory-play-again-btn" class="bg-green-600 hover:bg-green-700 text-white font-bold py-3 px-6 rounded-lg transition"> <i class="fas fa-redo mr-2"></i> Play Again </button> <button id="victory-menu-btn" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 px-6 rounded-lg transition"> <i class="fas fa-home mr-2"></i> Main Menu </button> </div> </div> </div> <script> // Game state const gameState = { // Player data player: { x: 500, y: 500, speed: 3, health: 100, maxHealth: 100, direction: 0, // in radians character: 'soldier', kills: 0, damageDealt: 0, survivalTime: 0, inventory: { weapons: [ { id: 'pistol', name: 'Pistol', damage: 10, ammo: 30, maxAmmo: 90, equipped: true, icon: 'fas fa-gun' } ], healing: [ { id: 'bandage', name: 'Bandage', heal: 20, quantity: 3, icon: 'fas fa-band-aid' } ] }, equippedWeapon: 'pistol' }, // Game data enemies: [], loot: [], bullets: [], safeZone: { x: 500, y: 500, radius: 400, nextShrinkTime: 60000, // 1 minute shrinkInterval: 60000, damage: 5, damageInterval: 1000 }, gameTime: 0, playersLeft: 24, gameActive: false, zoomLevel: 1, // Controls joystickActive: false, joystickX: 0, joystickY: 0, // UI elements elements: { mainMenu: document.getElementById('main-menu'), characterSelection: document.getElementById('character-selection'), howToPlay: document.getElementById('how-to-play'), leaderboard: document.getElementById('leaderboard'), gameUI: document.getElementById('game-ui'), inventory: document.getElementById('inventory'), pauseMenu: document.getElementById('pause-menu'), gameOver: document.getElementById('game-over'), victoryScreen: document.getElementById('victory-screen'), // Game UI elements healthBar: document.getElementById('health-bar'), healthText: document.getElementById('health-text'), ammoCount: document.getElementById('ammo-count'), ammoTotal: document.getElementById('ammo-total'), playersLeft: document.getElementById('players-left'), // Map and controls map: document.getElementById('map'), gameView: document.getElementById('game-view'), joystick: document.getElementById('joystick'), shootBtn: document.getElementById('shoot-btn'), // Mini map miniMap: document.getElementById('mini-map') }, // Timers timers: { gameLoop: null, safeZoneShrink: null, safeZoneDamage: null, enemyMovement: null, enemyShooting: null, gameTimeUpdate: null } }; // Initialize the game function initGame() { setupEventListeners(); loadLeaderboard(); // Check for saved game const savedGame = localStorage.getItem('battleRoyaleSave'); if (savedGame) { document.getElementById('continue-game-btn').classList.remove('hidden'); } else { document.getElementById('continue-game-btn').classList.add('hidden'); } } // Set up event listeners function setupEventListeners() { // Main menu buttons document.getElementById('new-game-btn').addEventListener('click', () => { gameState.elements.mainMenu.classList.add('hidden'); gameState.elements.characterSelection.classList.remove('hidden'); }); document.getElementById('continue-game-btn').addEventListener('click', () => { const savedGame = localStorage.getItem('battleRoyaleSave'); if (savedGame) { loadGame(JSON.parse(savedGame)); } }); document.getElementById('leaderboard-btn').addEventListener('click', () => { gameState.elements.mainMenu.classList.add('hidden'); gameState.elements.leaderboard.classList.remove('hidden'); }); document.getElementById('how-to-play-btn').addEventListener('click', () => { gameState.elements.mainMenu.classList.add('hidden'); gameState.elements.howToPlay.classList.remove('hidden'); }); // Character selection buttons document.querySelectorAll('.character-option').forEach(option => { option.addEventListener('click', () => { document.querySelectorAll('.character-option').forEach(opt => { opt.classList.remove('selected'); }); option.classList.add('selected'); gameState.player.character = option.dataset.character; // Set character stats switch (gameState.player.character) { case 'soldier': gameState.player.health = 80; gameState.player.maxHealth = 80; gameState.player.speed = 3; break; case 'scout': gameState.player.health = 60; gameState.player.maxHealth = 60; gameState.player.speed = 4; break; case 'tank': gameState.player.health = 100; gameState.player.maxHealth = 100; gameState.player.speed = 2; break; } }); }); document.getElementById('back-to-menu-btn').addEventListener('click', () => { gameState.elements.characterSelection.classList.add('hidden'); gameState.elements.mainMenu.classList.remove('hidden'); }); document.getElementById('start-game-btn').addEventListener('click', startNewGame); // How to play back button document.getElementById('back-from-help-btn').addEventListener('click', () => { gameState.elements.howToPlay.classList.add('hidden'); gameState.elements.mainMenu.classList.remove('hidden'); }); // Leaderboard back button document.getElementById('back-from-leaderboard-btn').addEventListener('click', () => { gameState.elements.leaderboard.classList.add('hidden'); gameState.elements.mainMenu.classList.remove('hidden'); }); // Game UI buttons document.getElementById('inventory-btn').addEventListener('click', openInventory); document.getElementById('pause-btn').addEventListener('click', pauseGame); // Inventory buttons document.getElementById('close-inventory-btn').addEventListener('click', closeInventory); // Pause menu buttons document.getElementById('resume-game-btn').addEventListener('click', resumeGame); document.getElementById('restart-game-btn').addEventListener('click', confirmRestart); document.getElementById('quit-to-menu-btn').addEventListener('click', quitToMenu); // Game over buttons document.getElementById('play-again-btn').addEventListener('click', startNewGame); document.getElementById('game-over-menu-btn').addEventListener('click', quitToMenu); // Victory screen buttons document.getElementById('victory-play-again-btn').addEventListener('click', startNewGame); document.getElementById('victory-menu-btn').addEventListener('click', quitToMenu); // Zoom controls document.getElementById('zoom-in-btn').addEventListener('click', () => adjustZoom(1.2)); document.getElementById('zoom-out-btn').addEventListener('click', () => adjustZoom(0.8)); // Joystick controls const joystickArea = document.getElementById('joystick-area'); const joystick = document.getElementById('joystick'); joystickArea.addEventListener('touchstart', handleJoystickStart); joystickArea.addEventListener('touchmove', handleJoystickMove); joystickArea.addEventListener('touchend', handleJoystickEnd); // For mouse controls (useful for testing on desktop) joystickArea.addEventListener('mousedown', handleJoystickStart); document.addEventListener('mousemove', handleJoystickMove); document.addEventListener('mouseup', handleJoystickEnd); // Shoot button document.getElementById('shoot-btn').addEventListener('click', playerShoot); document.getElementById('shoot-btn').addEventListener('touchstart', playerShoot); } // Joystick controls function handleJoystickStart(e) { e.preventDefault(); gameState.joystickActive = true; let clientX, clientY; if (e.type === 'touchstart') { clientX = e.touches[0].clientX; clientY = e.touches[0].clientY; } else { clientX = e.clientX; clientY = e.clientY; } const joystickArea = document.getElementById('joystick-area'); const rect = joystickArea.getBoundingClientRect(); const centerX = rect.left + rect.width / 2; const centerY = rect.top + rect.height / 2; gameState.joystickX = clientX - centerX; gameState.joystickY = clientY - centerY; updateJoystickPosition(); } function handleJoystickMove(e) { if (!gameState.joystickActive) return; e.preventDefault(); let clientX, clientY; if (e.type === 'touchmove') { clientX = e.touches[0].clientX; clientY = e.touches[0].clientY; } else { clientX = e.clientX; clientY = e.clientY; } const joystickArea = document.getElementById('joystick-area'); const rect = joystickArea.getBoundingClientRect(); const centerX = rect.left + rect.width / 2; const centerY = rect.top + rect.height / 2; gameState.joystickX = clientX - centerX; gameState.joystickY = clientY - centerY; // Limit joystick to the area const maxDistance = 60; const distance = Math.sqrt(gameState.joystickX * gameState.joystickX + gameState.joystickY * gameState.joystickY); if (distance > maxDistance) { gameState.joystickX = (gameState.joystickX / distance) * maxDistance; gameState.joystickY = (gameState.joystickY / distance) * maxDistance; } updateJoystickPosition(); } function handleJoystickEnd(e) { if (!gameState.joystickActive) return; e.preventDefault(); gameState.joystickActive = false; gameState.joystickX = 0; gameState.joystickY = 0; updateJoystickPosition(); } function updateJoystickPosition() { const joystick = document.getElementById('joystick'); joystick.style.transform = `translate(${gameState.joystickX}px, ${gameState.joystickY}px)`; } // Start a new game function startNewGame() { // Hide all UI screens document.querySelectorAll('[id$="-menu"], [id$="-selection"], [id$="-screen"], [id$="-over"]').forEach(el => { el.classList.add('hidden'); }); // Reset player stats gameState.player = { ...gameState.player, x: 500, y: 500, health: gameState.player.maxHealth, kills: 0, damageDealt: 0, survivalTime: 0, inventory: { weapons: [ { id: 'pistol', name: 'Pistol', damage: 10, ammo: 30, maxAmmo: 90, equipped: true, icon: 'fas fa-gun' } ], healing: [ { id: 'bandage', name: 'Bandage', heal: 20, quantity: 3, icon: 'fas fa-band-aid' } ] }, equippedWeapon: 'pistol' }; // Reset game state gameState.enemies = []; gameState.loot = []; gameState.bullets = []; gameState.safeZone = { x: 500, y: 500, radius: 400, nextShrinkTime: 60000, shrinkInterval: 60000, damage: 5, damageInterval: 1000 }; gameState.gameTime = 0; gameState.playersLeft = 24; gameState.gameActive = true; gameState.zoomLevel = 1; // Create enemies createEnemies(23); // 23 enemies + player = 24 total // Create initial loot createLoot(50); // Update UI updatePlayerUI(); // Show game UI gameState.elements.gameUI.classList.remove('hidden'); // Center view on player centerViewOnPlayer(); // Start game loop startGameLoop(); // Start timers gameState.timers.safeZoneShrink = setInterval(shrinkSafeZone, gameState.safeZone.shrinkInterval); gameState.timers.safeZoneDamage = setInterval(applySafeZoneDamage, gameState.safeZone.damageInterval); gameState.timers.enemyMovement = setInterval(moveEnemies, 100); gameState.timers.enemyShooting = setInterval(enemiesShoot, 1500); gameState.timers.gameTimeUpdate = setInterval(updateGameTime, 1000); } // Load a saved game function loadGame(savedState) { // Hide all UI screens document.querySelectorAll('[id$="-menu"], [id$="-selection"], [id$="-screen"], [id$="-over"]').forEach(el => { el.classList.add('hidden'); }); // Restore game state Object.assign(gameState, savedState); gameState.gameActive = true; // Update UI updatePlayerUI(); // Show game UI gameState.elements.gameUI.classList.remove('hidden'); // Center view on player centerViewOnPlayer(); // Start game loop startGameLoop(); // Start timers gameState.timers.safeZoneShrink = setInterval(shrinkSafeZone, gameState.safeZone.shrinkInterval); gameState.timers.safeZoneDamage = setInterval(applySafeZoneDamage, gameState.safeZone.damageInterval); gameState.timers.enemyMovement = setInterval(moveEnemies, 100); gameState.timers.enemyShooting = setInterval(enemiesShoot, 1500); gameState.timers.gameTimeUpdate = setInterval(updateGameTime, 1000); } // Save the current game state function saveGame() { localStorage.setItem('battleRoyaleSave', JSON.stringify(gameState)); } // Game loop function startGameLoop() { if (gameState.timers.gameLoop) { clearInterval(gameState.timers.gameLoop); } gameState.timers.gameLoop = setInterval(() => { if (!gameState.gameActive) return; // Move player if joystick is active if (gameState.joystickActive) { movePlayer(); } // Move bullets moveBullets(); // Check for loot collection checkLootCollection(); // Update player direction based on movement if (gameState.joystickActive) { gameState.player.direction = Math.atan2(gameState.joystickY, gameState.joystickX); } // Update safe zone timer gameState.safeZone.nextShrinkTime -= 1000 / 60; // Render everything renderGame(); }, 1000 / 60); // 60 FPS } // Move player based on joystick input function movePlayer() { const speed = gameState.player.speed; // Normalize joystick input const distance = Math.sqrt(gameState.joystickX * gameState.joystickX + gameState.joystickY * gameState.joystickY); const normalizedX = gameState.joystickX / distance; const normalizedY = gameState.joystickY / distance; // Calculate new position let newX = gameState.player.x + normalizedX * speed; let newY = gameState.player.y + normalizedY * speed; // Boundary checks newX = Math.max(15, Math.min(985, newX)); newY = Math.max(15, Math.min(985, newY)); gameState.player.x = newX; gameState.player.y = newY; } // Create enemies function createEnemies(count) { for (let i = 0; i < count; i++) { // Random position outside a small radius around the player let x, y; do { x = Math.floor(Math.random() * 900) + 50; y = Math.floor(Math.random() * 900) + 50; } while (Math.sqrt(Math.pow(x - gameState.player.x, 2) + Math.pow(y - gameState.player.y, 2)) < 200); const enemy = { id: `enemy-${i}`, x: x, y: y, health: 100, maxHealth: 100, speed: 2 + Math.random(), direction: Math.random() * Math.PI * 2, changeDirectionTime: 0, targetX: x, targetY: y, weapons: [ { id: 'pistol', name: 'Pistol', damage: 10, ammo: 30, maxAmmo: 90 } ], equippedWeapon: 'pistol', lastShotTime: 0 }; gameState.enemies.push(enemy); } } // Move enemies function moveEnemies() { if (!gameState.gameActive) return; gameState.enemies.forEach(enemy => { // Simple AI: move randomly but generally toward the safe zone if (enemy.changeDirectionTime <= 0) { // Sometimes change direction if (Math.random() < 0.3) { // Move toward safe zone const angleToSafeZone = Math.atan2( gameState.safeZone.y - enemy.y, gameState.safeZone.x - enemy.x ); // Add some randomness enemy.direction = angleToSafeZone + (Math.random() - 0.5) * Math.PI / 2; } else { // Move randomly enemy.direction = Math.random() * Math.PI * 2; } enemy.changeDirectionTime = 1000 + Math.random() * 2000; } else { enemy.changeDirectionTime -= 100; } // Move in current direction enemy.x += Math.cos(enemy.direction) * enemy.speed; enemy.y += Math.sin(enemy.direction) * enemy.speed; // Boundary checks enemy.x = Math.max(15, Math.min(985, enemy.x)); enemy.y = Math.max(15, Math.min(985, enemy.y)); // If outside safe zone, move toward it more aggressively const distanceToSafeZone = Math.sqrt( Math.pow(enemy.x - gameState.safeZone.x, 2) + Math.pow(enemy.y - gameState.safeZone.y, 2) ); if (distanceToSafeZone > gameState.safeZone.radius) { const angleToSafeZone = Math.atan2( gameState.safeZone.y - enemy.y, gameState.safeZone.x - enemy.x ); enemy.direction = angleToSafeZone; enemy.speed = 3; // Move faster toward safe zone } else { enemy.speed = 2 + Math.random(); // Normal speed } }); } // Enemies shoot function enemiesShoot() { if (!gameState.gameActive) return; const now = Date.now(); gameState.enemies.forEach(enemy => { // Check if player is visible to enemy const distanceToPlayer = Math.sqrt( Math.pow(enemy.x - gameState.player.x, 2) + Math.pow(enemy.y - gameState.player.y, 2) ); // Only shoot if player is within range and in line of sight if (distanceToPlayer < 300 && now - enemy.lastShotTime > 2000) { const weapon = enemy.weapons.find(w => w.id === enemy.equippedWeapon); if (weapon && weapon.ammo > 0) { // Calculate direction to player const angleToPlayer = Math.atan2( gameState.player.y - enemy.y, gameState.player.x - enemy.x ); // Add some inaccuracy const inaccuracy = (Math.random() - 0.5) * Math.PI / 8; const direction = angleToPlayer + inaccuracy; // Create bullet gameState.bullets.push({ x: enemy.x, y: enemy.y, direction: direction, speed: 10, damage: weapon.damage, owner: enemy.id, isEnemy: true }); // Reduce ammo weapon.ammo--; enemy.lastShotTime = now; } } }); } // Player shoots function playerShoot() { if (!gameState.gameActive) return; const weapon = gameState.player.inventory.weapons.find(w => w.equipped); if (weapon && weapon.ammo > 0) { // Create bullet gameState.bullets.push({ x: gameState.player.x, y: gameState.player.y, direction: gameState.player.direction, speed: 10, damage: weapon.damage, owner: 'player', isEnemy: false }); // Reduce ammo weapon.ammo--; // Update UI updateAmmoUI(); } } // Move bullets and check for hits function moveBullets() { if (!gameState.gameActive) return; const bulletsToRemove = []; gameState.bullets.forEach((bullet, index) => { // Move bullet bullet.x += Math.cos(bullet.direction) * bullet.speed; bullet.y += Math.sin(bullet.direction) * bullet.speed; // Check if bullet is out of bounds if (bullet.x < 0 || bullet.x > 1000 || bullet.y < 0 || bullet.y > 1000) { bulletsToRemove.push(index); return; } // Check for hits if (bullet.isEnemy) { // Check if hit player const distanceToPlayer = Math.sqrt( Math.pow(bullet.x - gameState.player.x, 2) + Math.pow(bullet.y - gameState.player.y, 2) ); if (distanceToPlayer < 15) { // Player hit radius gameState.player.health -= bullet.damage; createDamageIndicator(bullet.x, bullet.y, bullet.damage); bulletsToRemove.push(index); // Update UI updatePlayerUI(); // Check if player died if (gameState.player.health <= 0) { gameOver(false); } } } else { // Check if hit enemy for (let i = 0; i < gameState.enemies.length; i++) { const enemy = gameState.enemies[i]; const distanceToEnemy = Math.sqrt( Math.pow(bullet.x - enemy.x, 2) + Math.pow(bullet.y - enemy.y, 2) ); if (distanceToEnemy < 15) { // Enemy hit radius enemy.health -= bullet.damage; gameState.player.damageDealt += bullet.damage; createDamageIndicator(bullet.x, bullet.y, bullet.damage); bulletsToRemove.push(index); // Check if enemy died if (enemy.health <= 0) { gameState.player.kills++; gameState.playersLeft--; gameState.enemies.splice(i, 1); // Update UI updatePlayerUI(); // Check if player won if (gameState.playersLeft === 1) { gameOver(true); } } break; } } } }); // Remove bullets that hit or went out of bounds for (let i = bulletsToRemove.length - 1; i >= 0; i--) { gameState.bullets.splice(bulletsToRemove[i], 1); } } // Create loot items function createLoot(count) { const lootTypes = [ { id: 'medkit', name: 'Medkit', heal: 50, icon: 'fas fa-medkit' }, { id: 'bandage', name: 'Bandage', heal: 20, icon: 'fas fa-band-aid' }, { id: 'rifle', name: 'Rifle', damage: 20, ammo: 20, maxAmmo: 60, icon: 'fas fa-gun' }, { id: 'shotgun', name: 'Shotgun', damage: 30, ammo: 5, maxAmmo: 15, icon: 'fas fa-gun' }, { id: 'ammo', name: 'Ammo Pack', ammo: 30, icon: 'fas fa-bullseye' } ]; for (let i = 0; i < count; i++) { const type = lootTypes[Math.floor(Math.random() * lootTypes.length)]; const lootItem = { id: `loot-${i}`, type: type.id, x: Math.floor(Math.random() * 900) + 50, y: Math.floor(Math.random() * 900) + 50, ...type }; gameState.loot.push(lootItem); } } // Check for loot collection function checkLootCollection() { const lootToRemove = []; gameState.loot.forEach((loot, index) => { const distanceToPlayer = Math.sqrt( Math.pow(loot.x - gameState.player.x, 2) + Math.pow(loot.y - gameState.player.y, 2) ); if (distanceToPlayer < 20) { // Loot collection radius // Add to inventory if (loot.type === 'medkit' || loot.type === 'bandage') { // Healing item const existingItem = gameState.player.inventory.healing.find(item => item.id === loot.type); if (existingItem) { existingItem.quantity++; } else { gameState.player.inventory.healing.push({ id: loot.type, name: loot.name, heal: loot.heal, quantity: 1, icon: loot.icon }); } } else if (loot.type === 'ammo') { // Ammo pack - add to equipped weapon const weapon = gameState.player.inventory.weapons.find(w => w.equipped); if (weapon) { weapon.maxAmmo += loot.ammo; } } else { // Weapon const existingWeapon = gameState.player.inventory.weapons.find(w => w.id === loot.type); if (!existingWeapon) { gameState.player.inventory.weapons.push({ id: loot.type, name: loot.name, damage: loot.damage, ammo: loot.ammo, maxAmmo: loot.maxAmmo, equipped: false, icon: loot.icon }); } } lootToRemove.push(index); } }); // Remove collected loot for (let i = lootToRemove.length - 1; i >= 0; i--) { gameState.loot.splice(lootToRemove[i], 1); } } // Shrink safe zone function shrinkSafeZone() { if (!gameState.gameActive) return; // Reduce radius by 20% gameState.safeZone.radius *= 0.8; // Move center randomly but generally toward the center of the map const angle = Math.random() * Math.PI * 2; const distance = Math.random() * 50; gameState.safeZone.x += Math.cos(angle) * distance; gameState.safeZone.y += Math.sin(angle) * distance; // Keep safe zone within map bounds gameState.safeZone.x = Math.max(gameState.safeZone.radius, Math.min(1000 - gameState.safeZone.radius, gameState.safeZone.x)); gameState.safeZone.y = Math.max(gameState.safeZone.radius, Math.min(1000 - gameState.safeZone.radius, gameState.safeZone.y)); // Increase damage outside safe zone gameState.safeZone.damage += 2; } // Apply damage to players outside safe zone function applySafeZoneDamage() { if (!gameState.gameActive) return; // Check player const playerDistance = Math.sqrt( Math.pow(gameState.player.x - gameState.safeZone.x, 2) + Math.pow(gameState.player.y - gameState.safeZone.y, 2) ); if (playerDistance > gameState.safeZone.radius) { gameState.player.health -= gameState.safeZone.damage; createDamageIndicator(gameState.player.x, gameState.player.y, gameState.safeZone.damage); // Update UI updatePlayerUI(); // Check if player died if (gameState.player.health <= 0) { gameOver(false); } } // Check enemies for (let i = 0; i < gameState.enemies.length; i++) { const enemy = gameState.enemies[i]; const enemyDistance = Math.sqrt( Math.pow(enemy.x - gameState.safeZone.x, 2) + Math.pow(enemy.y - gameState.safeZone.y, 2) ); if (enemyDistance > gameState.safeZone.radius) { enemy.health -= gameState.safeZone.damage; createDamageIndicator(enemy.x, enemy.y, gameState.safeZone.damage); // Check if enemy died if (enemy.health <= 0) { gameState.playersLeft--; gameState.enemies.splice(i, 1); i--; // Update UI updatePlayerUI(); // Check if player won if (gameState.playersLeft === 1) { gameOver(true); } } } } } // Update game time function updateGameTime() { if (!gameState.gameActive) return; gameState.player.survivalTime++; gameState.gameTime++; // Update safe zone timer display if needed } // Center view on player function centerViewOnPlayer() { const gameView = gameState.elements.gameView; const map = gameState.elements.map; const viewWidth = gameView.clientWidth; const viewHeight = gameView.clientHeight; const offsetX = viewWidth / 2 - gameState.player.x * gameState.zoomLevel; const offsetY = viewHeight / 2 - gameState.player.y * gameState.zoomLevel; map.style.transform = `translate(${offsetX}px, ${offsetY}px) scale(${gameState.zoomLevel})`; } // Adjust zoom level function adjustZoom(factor) { gameState.zoomLevel *= factor; gameState.zoomLevel = Math.max(0.5, Math.min(2, gameState.zoomLevel)); centerViewOnPlayer(); } // Render game elements function renderGame() { const map = gameState.elements.map; // Clear previous elements map.innerHTML = ''; // Draw safe zone const safeZone = document.createElement('div'); safeZone.className = 'safe-zone'; safeZone.style.width = `${gameState.safeZone.radius * 2}px`; safeZone.style.height = `${gameState.safeZone.radius * 2}px`; safeZone.style.left = `${gameState.safeZone.x - gameState.safeZone.radius}px`; safeZone.style.top = `${gameState.safeZone.y - gameState.safeZone.radius}px`; map.appendChild(safeZone); // Draw loot gameState.loot.forEach(loot => { const lootElement = document.createElement('div'); lootElement.className = 'loot'; lootElement.style.left = `${loot.x - 10}px`; lootElement.style.top = `${loot.y - 10}px`; // Add icon based on loot type const icon = document.createElement('i'); icon.className = loot.icon; lootElement.appendChild(icon); map.appendChild(lootElement); }); // Draw enemies gameState.enemies.forEach(enemy => { const enemyElement = document.createElement('div'); enemyElement.className = 'enemy'; enemyElement.style.left = `${enemy.x - 15}px`; enemyElement.style.top = `${enemy.y - 15}px`; enemyElement.textContent = 'E'; // Health bar const healthBar = document.createElement('div'); healthBar.className = 'health-bar'; const healthFill = document.createElement('div'); healthFill.className = 'health-fill'; healthFill.style.width = `${(enemy.health / enemy.maxHealth) * 100}%`; healthBar.appendChild(healthFill); enemyElement.appendChild(healthBar); map.appendChild(enemyElement); }); // Draw bullets gameState.bullets.forEach(bullet => { const bulletElement = document.createElement('div'); bulletElement.className = 'bullet'; bulletElement.style.left = `${bullet.x - 3}px`; bulletElement.style.top = `${bullet.y - 3}px`; map.appendChild(bulletElement); }); // Draw player const playerElement = document.createElement('div'); playerElement.className = 'player'; playerElement.style.left = `${gameState.player.x - 15}px`; playerElement.style.top = `${gameState.player.y - 15}px`; playerElement.style.backgroundColor = getPlayerColor(); playerElement.textContent = 'P'; // Health bar const healthBar = document.createElement('div'); healthBar.className = 'health-bar'; const healthFill = document.createElement('div'); healthFill.className = 'health-fill'; healthFill.style.width = `${(gameState.player.health / gameState.player.maxHealth) * 100}%`; healthBar.appendChild(healthFill); playerElement.appendChild(healthBar); map.appendChild(playerElement); // Update mini-map updateMiniMap(); } // Get player color based on character function getPlayerColor() { switch (gameState.player.character) { case 'soldier': return 'blue'; case 'scout': return 'green'; case 'tank': return 'red'; default: return 'purple'; } } // Update mini-map function updateMiniMap() { const miniMap = gameState.elements.miniMap; miniMap.innerHTML = ''; // Create mini-map elements with scaled down coordinates const scale = 0.1; // Safe zone const miniSafeZone = document.createElement('div'); miniSafeZone.className = 'safe-zone absolute'; miniSafeZone.style.width = `${gameState.safeZone.radius * 2 * scale}px`; miniSafeZone.style.height = `${gameState.safeZone.radius * 2 * scale}px`; miniSafeZone.style.left = `${gameState.safeZone.x * scale - gameState.safeZone.radius * scale}px`; miniSafeZone.style.top = `${gameState.safeZone.y * scale - gameState.safeZone.radius * scale}px`; miniMap.appendChild(miniSafeZone); // Enemies gameState.enemies.forEach(enemy => { const miniEnemy = document.createElement('div'); miniEnemy.className = 'absolute bg-red-500 rounded-full w-2 h-2'; miniEnemy.style.left = `${enemy.x * scale - 1}px`; miniEnemy.style.top = `${enemy.y * scale - 1}px`; miniMap.appendChild(miniEnemy); }); // Player const miniPlayer = document.createElement('div'); miniPlayer.className = 'absolute rounded-full w-3 h-3 flex items-center justify-center font-bold text-xs'; miniPlayer.style.backgroundColor = getPlayerColor(); miniPlayer.style.left = `${gameState.player.x * scale - 1.5}px`; miniPlayer.style.top = `${gameState.player.y * scale - 1.5}px`; miniPlayer.textContent = 'P'; miniMap.appendChild(miniPlayer); } // Create damage indicator function createDamageIndicator(x, y, amount) { const damageIndicator = document.createElement('div'); damageIndicator.className = 'damage-indicator'; damageIndicator.textContent = `-${amount}`; damageIndicator.style.left = `${x - 10}px`; damageIndicator.style.top = `${y - 20}px`; gameState.elements.map.appendChild(damageIndicator); // Remove after animation setTimeout(() => { damageIndicator.remove(); }, 1000); } // Update player UI function updatePlayerUI() { // Health const healthPercent = (gameState.player.health / gameState.player.maxHealth) * 100; gameState.elements.healthBar.style.width = `${healthPercent}%`; gameState.elements.healthText.textContent = `${Math.max(0, Math.floor(gameState.player.health))}/${gameState.player.maxHealth}`; // Change health bar color based on health level if (healthPercent < 30) { gameState.elements.healthBar.style.backgroundColor = '#f44336'; } else if (healthPercent < 60) { gameState.elements.healthBar.style.backgroundColor = '#ff9800'; } else { gameState.elements.healthBar.style.backgroundColor = '#4CAF50'; } // Ammo const weapon = gameState.player.inventory.weapons.find(w => w.equipped); if (weapon) { gameState.elements.ammoCount.textContent = weapon.ammo; gameState.elements.ammoTotal.textContent = weapon.maxAmmo; } // Players left gameState.elements.playersLeft.textContent = gameState.playersLeft; } // Update ammo UI function updateAmmoUI() { const weapon = gameState.player.inventory.weapons.find(w => w.equipped); if (weapon) { gameState.elements.ammoCount.textContent = weapon.ammo; gameState.elements.ammoTotal.textContent = weapon.maxAmmo; } } // Open inventory function openInventory() { if (!gameState.gameActive) return; // Pause game gameState.gameActive = false; // Show inventory gameState.elements.inventory.classList.remove('hidden'); // Populate weapons const weaponsContainer = document.getElementById('weapons-container'); weaponsContainer.innerHTML = ''; gameState.player.inventory.weapons.forEach(weapon => { const weaponElement = document.createElement('div'); weaponElement.className = `inventory-item ${weapon.equipped ? 'equipped' : ''}`; weaponElement.dataset.id = weapon.id; const icon = document.createElement('i'); icon.className = `${weapon.icon} text-2xl mb-1`; const name = document.createElement('span'); name.className = 'font-bold'; name.textContent = weapon.name; const stats = document.createElement('div'); stats.className = 'text-xs mt-1'; stats.innerHTML = ` <div>Damage: ${weapon.damage}</div> <div>Ammo: ${weapon.ammo}/${weapon.maxAmmo}</div> `; const equipBtn = document.createElement('button'); equipBtn.className = `mt-2 w-full py-1 px-2 rounded ${weapon.equipped ? 'bg-gray-500 cursor-not-allowed' : 'bg-blue-600 hover:bg-blue-700'}`; equipBtn.textContent = weapon.equipped ? 'Equipped' : 'Equip'; equipBtn.disabled = weapon.equipped; equipBtn.addEventListener('click', () => equipWeapon(weapon.id)); weaponElement.appendChild(icon); weaponElement.appendChild(name); weaponElement.appendChild(stats); weaponElement.appendChild(equipBtn); weaponsContainer.appendChild(weaponElement); }); // Populate healing items const healingContainer = document.getElementById('healing-container'); healingContainer.innerHTML = ''; gameState.player.in </html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Offline Battle Royale</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
/* Custom styles */
.game-container {
touch-action: manipulation;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.joystick-area {
position: absolute;
bottom: 20px;
left: 20px;
width: 120px;
height: 120px;
background-color: rgba(255, 255, 255, 0.2);
border-radius: 50%;
}
.joystick {
position: absolute;
width: 60px;
height: 60px;
background-color: rgba(255, 255, 255, 0.5);
border-radius: 50%;
top: 30px;
left: 30px;
}
.action-button {
position: absolute;
bottom: 40px;
right: 40px;
width: 80px;
height: 80px;
background-color: rgba(255, 0, 0, 0.5);
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
color: white;
font-size: 24px;
}
.map {
position: relative;
width: 1000px;
height: 1000px;
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="1000" height="1000" viewBox="0 0 1000 1000"><rect width="100%" height="100%" fill="%234CAF50"/><rect x="100" y="100" width="300" height="300" fill="%238BC34A" stroke="%233E2723" stroke-width="5"/><rect x="600" y="100" width="300" height="300" fill="%238BC34A" stroke="%233E2723" stroke-width="5"/><rect x="100" y="600" width="300" height="300" fill="%238BC34A" stroke="%233E2723" stroke-width="5"/><rect x="600" y="600" width="300" height="300" fill="%238BC34A" stroke="%233E2723" stroke-width="5"/><circle cx="500" cy="500" r="150" fill="%23FFC107" stroke="%233E2723" stroke-width="5"/><path d="M500,100 L500,900 M100,500 L900,500" stroke="%233E2723" stroke-width="3" stroke-dasharray="10,5"/></svg>');
transform-origin: 0 0;
}
.player {
position: absolute;
width: 30px;
height: 30px;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
color: white;
font-weight: bold;
z-index: 10;
}
.enemy {
position: absolute;
width: 30px;
height: 30px;
border-radius: 50%;
background-color: red;
display: flex;
justify-content: center;
align-items: center;
color: white;
font-weight: bold;
z-index: 5;
}
.loot {
position: absolute;
width: 20px;
height: 20px;
border-radius: 50%;
background-color: gold;
z-index: 2;
}
.safe-zone {