browser-blitz-boom / index.html
Joe9745's picture
An FPS game I can play right in the browser using JavaScript
2e6b81d verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Browser Blitz Boom - FPS Game</title>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<script src="https://unpkg.com/feather-icons"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vanta@latest/dist/vanta.globe.min.js"></script>
<style>
#gameCanvas {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
.crosshair {
position: absolute;
top: 50%;
left: 50%;
width: 20px;
height: 20px;
transform: translate(-50%, -50%);
pointer-events: none;
}
.health-bar {
transition: width 0.3s ease;
}
.weapon-selector {
transition: all 0.2s ease;
}
.weapon-selector:hover {
transform: scale(1.1);
}
</style>
</head>
<body class="bg-gray-900 text-white overflow-hidden">
<canvas id="gameCanvas"></canvas>
<!-- Crosshair -->
<div class="crosshair">
<div class="w-full h-full flex items-center justify-center">
<div class="w-4 h-4 border-2 border-red-500 rounded-full"></div>
</div>
</div>
<!-- Game UI -->
<div class="fixed inset-0 pointer-events-none">
<!-- Health Bar -->
<div class="absolute top-4 left-4 w-64 bg-gray-800 rounded-full h-4 overflow-hidden">
<div id="healthBar" class="health-bar h-full bg-red-500" style="width: 100%;"></div>
</div>
<!-- Ammo Counter -->
<div class="absolute bottom-4 right-4 text-right">
<div class="text-4xl font-bold" id="ammoCounter">30/120</div>
<div class="text-xl opacity-75" id="weaponName">Assault Rifle</div>
</div>
<!-- Weapon Selector -->
<div class="absolute bottom-4 left-4 flex gap-2">
<div class="weapon-selector bg-gray-800 bg-opacity-70 p-3 rounded-lg cursor-pointer pointer-events-auto" onclick="selectWeapon(0)">
<i data-feather="gun" class="w-8 h-8"></i>
</div>
<div class="weapon-selector bg-gray-800 bg-opacity-50 p-3 rounded-lg cursor-pointer pointer-events-auto" onclick="selectWeapon(1)">
<i data-feather="zap" class="w-8 h-8"></i>
</div>
<div class="weapon-selector bg-gray-800 bg-opacity-50 p-3 rounded-lg cursor-pointer pointer-events-auto" onclick="selectWeapon(2)">
<i data-feather="package" class="w-8 h-8"></i>
</div>
</div>
<!-- Score -->
<div class="absolute top-4 right-4 text-right">
<div class="text-2xl font-bold">Score: <span id="score">0</span></div>
<div class="text-lg opacity-75" id="enemiesLeft">Enemies: 10</div>
</div>
</div>
<!-- Start Screen -->
<div id="startScreen" class="fixed inset-0 bg-black bg-opacity-90 flex flex-col items-center justify-center z-10">
<h1 class="text-6xl font-bold mb-4 text-red-500">BROWSER BLITZ BOOM</h1>
<p class="text-xl mb-8">An FPS experience right in your browser</p>
<button onclick="startGame()" class="px-8 py-4 bg-red-600 hover:bg-red-700 rounded-lg text-2xl font-bold transition-all transform hover:scale-105">
START GAME
</button>
<div class="mt-8 text-gray-400">
<p>Controls: WASD to move | Mouse to aim | Left click to shoot</p>
<p>Space to jump | R to reload | 1-3 to switch weapons</p>
</div>
</div>
<!-- Game Over Screen -->
<div id="gameOverScreen" class="fixed inset-0 bg-black bg-opacity-90 flex flex-col items-center justify-center z-10 hidden">
<h1 class="text-6xl font-bold mb-4 text-red-500">GAME OVER</h1>
<p class="text-2xl mb-8">Final Score: <span id="finalScore">0</span></p>
<button onclick="restartGame()" class="px-8 py-4 bg-red-600 hover:bg-red-700 rounded-lg text-2xl font-bold transition-all transform hover:scale-105">
PLAY AGAIN
</button>
</div>
<script>
// Game variables
let gameStarted = false;
let health = 100;
let score = 0;
let enemiesRemaining = 10;
let currentWeapon = 0;
const weapons = [
{ name: "Assault Rifle", ammo: 30, maxAmmo: 120, icon: "gun" },
{ name: "Plasma Gun", ammo: 15, maxAmmo: 60, icon: "zap" },
{ name: "Grenade Launcher", ammo: 5, maxAmmo: 15, icon: "package" }
];
// DOM elements
const healthBar = document.getElementById('healthBar');
const ammoCounter = document.getElementById('ammoCounter');
const weaponName = document.getElementById('weaponName');
const scoreElement = document.getElementById('score');
const enemiesLeft = document.getElementById('enemiesLeft');
const startScreen = document.getElementById('startScreen');
const gameOverScreen = document.getElementById('gameOverScreen');
const finalScore = document.getElementById('finalScore');
// Game functions
function startGame() {
gameStarted = true;
startScreen.classList.add('hidden');
health = 100;
score = 0;
enemiesRemaining = 10;
updateUI();
// Initialize game logic here
// This would typically involve Three.js or other WebGL setup
console.log("Game started!");
}
function gameOver() {
gameStarted = false;
gameOverScreen.classList.remove('hidden');
finalScore.textContent = score;
}
function restartGame() {
gameOverScreen.classList.add('hidden');
startGame();
}
function takeDamage(amount) {
if (!gameStarted) return;
health = Math.max(0, health - amount);
updateUI();
if (health <= 0) {
gameOver();
}
}
function addScore(points) {
if (!gameStarted) return;
score += points;
enemiesRemaining = Math.max(0, enemiesRemaining - 1);
updateUI();
}
function selectWeapon(index) {
currentWeapon = index;
updateUI();
}
function updateUI() {
healthBar.style.width = `${health}%`;
ammoCounter.textContent = `${weapons[currentWeapon].ammo}/${weapons[currentWeapon].maxAmmo}`;
weaponName.textContent = weapons[currentWeapon].name;
scoreElement.textContent = score;
enemiesLeft.textContent = `Enemies: ${enemiesRemaining}`;
}
// Simulate game events for demo
function simulateGameEvents() {
// Simulate taking damage
setTimeout(() => {
takeDamage(20);
}, 3000);
// Simulate scoring points
setTimeout(() => {
addScore(100);
}, 5000);
// Simulate weapon change
setTimeout(() => {
selectWeapon(1);
weapons[1].ammo = 15;
updateUI();
}, 7000);
}
// Event listeners
document.addEventListener('keydown', (e) => {
if (!gameStarted) return;
// Weapon switching
if (e.key >= '1' && e.key <= '3') {
selectWeapon(parseInt(e.key) - 1);
}
// Reload
if (e.key.toLowerCase() === 'r') {
weapons[currentWeapon].ammo = weapons[currentWeapon].maxAmmo;
updateUI();
}
});
// Mouse click for shooting
document.addEventListener('click', (e) => {
if (!gameStarted || e.target.closest('.weapon-selector')) return;
if (weapons[currentWeapon].ammo > 0) {
weapons[currentWeapon].ammo--;
updateUI();
addScore(10);
// Play shooting sound or effect here
} else {
// Play empty click sound
}
});
// Initialize
feather.replace();
// Background effect
VANTA.GLOBE({
el: "#gameCanvas",
mouseControls: false,
touchControls: false,
gyroControls: false,
minHeight: 200.00,
minWidth: 200.00,
scale: 1.00,
scaleMobile: 1.00,
color: 0xff2222,
backgroundColor: 0x101010,
size: 0.8
});
// For demo purposes
setTimeout(simulateGameEvents, 1000);
</script>
</body>
</html>