test / index.html
toastiselite's picture
Add 3 files
410ba5d verified
Raw History Blame Contribute Delete
38.5 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Arcane Dystopia</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
body {
margin: 0;
overflow: hidden;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
#game-container {
position: relative;
width: 100vw;
height: 100vh;
}
#ui-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
}
.ui-panel {
pointer-events: auto;
background-color: rgba(20, 20, 30, 0.8);
border: 1px solid #4a5568;
border-radius: 8px;
padding: 10px;
color: #e2e8f0;
}
.ability {
transition: all 0.3s ease;
}
.ability:hover {
transform: scale(1.05);
box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}
.cooldown {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background-color: rgba(255, 0, 0, 0.5);
transition: height 0.1s linear;
}
.quest-active {
border-left: 3px solid #48bb78;
}
.inventory-item {
transition: all 0.2s ease;
}
.inventory-item:hover {
transform: scale(1.1);
box-shadow: 0 0 5px rgba(255, 255, 255, 0.3);
}
#crosshair {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 20px;
height: 20px;
border: 2px solid rgba(255, 255, 255, 0.8);
border-radius: 50%;
pointer-events: none;
}
#crosshair::before, #crosshair::after {
content: '';
position: absolute;
background-color: rgba(255, 255, 255, 0.8);
}
#crosshair::before {
width: 2px;
height: 8px;
top: -10px;
left: 50%;
transform: translateX(-50%);
}
#crosshair::after {
width: 8px;
height: 2px;
left: -10px;
top: 50%;
transform: translateY(-50%);
}
</style>
</head>
<body class="bg-gray-900 text-white">
<div id="game-container">
<div id="ui-overlay" class="flex flex-col justify-between p-4">
<!-- Top Bar -->
<div class="flex justify-between items-start">
<!-- Player Stats -->
<div class="ui-panel flex space-x-6">
<div class="flex items-center space-x-2">
<i class="fas fa-heart text-red-500"></i>
<span id="health">100/100</span>
</div>
<div class="flex items-center space-x-2">
<i class="fas fa-bolt text-yellow-400"></i>
<span id="mana">150/150</span>
</div>
<div class="flex items-center space-x-2">
<i class="fas fa-coins text-yellow-300"></i>
<span id="gold">250</span>
</div>
</div>
<!-- Quest Info -->
<div id="quest-info" class="ui-panel max-w-xs hidden">
<div class="flex justify-between items-center mb-2">
<h3 class="font-bold" id="quest-title">Current Quest</h3>
<button id="close-quest" class="text-gray-400 hover:text-white">
<i class="fas fa-times"></i>
</button>
</div>
<p id="quest-description">No active quest</p>
<div class="mt-2">
<div class="w-full bg-gray-700 rounded-full h-2">
<div id="quest-progress" class="bg-green-500 h-2 rounded-full" style="width: 0%"></div>
</div>
<p class="text-xs mt-1 text-right" id="quest-progress-text">0%</p>
</div>
</div>
</div>
<!-- Center UI -->
<div class="flex justify-center">
<div id="crosshair"></div>
</div>
<!-- Bottom Bar -->
<div class="flex justify-between items-end">
<!-- Abilities -->
<div class="ui-panel flex space-x-4">
<div class="ability relative w-16 h-16 bg-gray-800 rounded-lg flex items-center justify-center cursor-pointer" data-ability="fireball">
<div class="cooldown" style="height: 0%"></div>
<i class="fas fa-fire text-2xl text-orange-500"></i>
<div class="absolute bottom-0 right-0 bg-gray-900 text-xs px-1 rounded-tl">Q</div>
</div>
<div class="ability relative w-16 h-16 bg-gray-800 rounded-lg flex items-center justify-center cursor-pointer" data-ability="frost-nova">
<div class="cooldown" style="height: 0%"></div>
<i class="fas fa-snowflake text-2xl text-blue-300"></i>
<div class="absolute bottom-0 right-0 bg-gray-900 text-xs px-1 rounded-tl">E</div>
</div>
<div class="ability relative w-16 h-16 bg-gray-800 rounded-lg flex items-center justify-center cursor-pointer" data-ability="lightning">
<div class="cooldown" style="height: 0%"></div>
<i class="fas fa-bolt text-2xl text-yellow-400"></i>
<div class="absolute bottom-0 right-0 bg-gray-900 text-xs px-1 rounded-tl">R</div>
</div>
<div class="ability relative w-16 h-16 bg-gray-800 rounded-lg flex items-center justify-center cursor-pointer" data-ability="teleport">
<div class="cooldown" style="height: 0%"></div>
<i class="fas fa-location-arrow text-2xl text-purple-400"></i>
<div class="absolute bottom-0 right-0 bg-gray-900 text-xs px-1 rounded-tl">F</div>
</div>
</div>
<!-- Inventory Button -->
<button id="inventory-btn" class="ui-panel p-3 rounded-full hover:bg-gray-700 transition">
<i class="fas fa-backpack text-xl"></i>
</button>
</div>
<!-- Inventory Modal -->
<div id="inventory-modal" class="hidden fixed inset-0 bg-black bg-opacity-70 flex items-center justify-center z-50">
<div class="ui-panel w-full max-w-2xl">
<div class="flex justify-between items-center mb-4">
<h2 class="text-xl font-bold">Inventory</h2>
<button id="close-inventory" class="text-gray-400 hover:text-white">
<i class="fas fa-times"></i>
</button>
</div>
<div class="grid grid-cols-4 gap-4" id="inventory-grid">
<!-- Inventory items will be added here -->
</div>
</div>
</div>
<!-- Quests Modal -->
<div id="quests-modal" class="hidden fixed inset-0 bg-black bg-opacity-70 flex items-center justify-center z-50">
<div class="ui-panel w-full max-w-2xl">
<div class="flex justify-between items-center mb-4">
<h2 class="text-xl font-bold">Quests</h2>
<button id="close-quests" class="text-gray-400 hover:text-white">
<i class="fas fa-times"></i>
</button>
</div>
<div class="space-y-4" id="quests-list">
<!-- Quests will be added here -->
</div>
</div>
</div>
<!-- Controls Help -->
<div id="controls-help" class="ui-panel absolute bottom-4 right-4 text-xs opacity-70 hover:opacity-100 transition">
<p>WASD: Move | SPACE: Jump | Q/E/R/F: Abilities | I: Inventory | J: Quests</p>
</div>
</div>
</div>
<script>
// Game State
const gameState = {
player: {
health: 100,
maxHealth: 100,
mana: 150,
maxMana: 150,
gold: 250,
position: { x: 0, y: 0, z: 0 },
rotation: { x: 0, y: 0 },
velocity: { x: 0, y: 0, z: 0 },
isGrounded: false,
abilities: {
fireball: { cooldown: 0, maxCooldown: 3, cost: 20 },
frostNova: { cooldown: 0, maxCooldown: 8, cost: 35 },
lightning: { cooldown: 0, maxCooldown: 15, cost: 50 },
teleport: { cooldown: 0, maxCooldown: 10, cost: 40 }
}
},
inventory: [
{ id: 'health-potion', name: 'Health Potion', icon: 'fa-flask', quantity: 3 },
{ id: 'mana-potion', name: 'Mana Potion', icon: 'fa-flask', quantity: 2 },
{ id: 'ancient-scroll', name: 'Ancient Scroll', icon: 'fa-scroll', quantity: 1 },
{ id: 'magic-orb', name: 'Magic Orb', icon: 'fa-globe', quantity: 1 }
],
quests: [
{
id: 'initiation',
title: 'Arcane Initiation',
description: 'Prove your worth by casting 5 spells in the training grounds.',
progress: 0,
goal: 5,
reward: { gold: 100, item: 'enchanted-ring' },
completed: false
},
{
id: 'rebellion',
title: 'Spark of Rebellion',
description: 'Find and destroy 3 surveillance drones in the district.',
progress: 0,
goal: 3,
reward: { gold: 200, item: 'cloak-of-shadows' },
completed: false
},
{
id: 'artifact',
title: 'Lost Artifact',
description: 'Recover the ancient artifact from the ruins beneath the city.',
progress: 0,
goal: 1,
reward: { gold: 500, item: 'staff-of-power' },
completed: false
}
],
activeQuest: 'initiation',
keys: {
w: false,
a: false,
s: false,
d: false,
space: false
},
scene: null,
camera: null,
renderer: null,
controls: null,
clock: new THREE.Clock(),
lastTime: 0
};
// Initialize Three.js scene
function initScene() {
const container = document.getElementById('game-container');
// Scene
gameState.scene = new THREE.Scene();
gameState.scene.background = new THREE.Color(0x111122);
gameState.scene.fog = new THREE.FogExp2(0x111122, 0.002);
// Camera
gameState.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
gameState.camera.position.set(0, 2, 5);
// Renderer
gameState.renderer = new THREE.WebGLRenderer({ antialias: true });
gameState.renderer.setSize(window.innerWidth, window.innerHeight);
gameState.renderer.shadowMap.enabled = true;
container.appendChild(gameState.renderer.domElement);
// Controls
gameState.controls = new THREE.OrbitControls(gameState.camera, gameState.renderer.domElement);
gameState.controls.enableDamping = true;
gameState.controls.dampingFactor = 0.25;
gameState.controls.enableZoom = false;
gameState.controls.enablePan = false;
// Lights
const ambientLight = new THREE.AmbientLight(0x404040);
gameState.scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
directionalLight.position.set(1, 1, 1);
directionalLight.castShadow = true;
gameState.scene.add(directionalLight);
// Ground
const groundGeometry = new THREE.PlaneGeometry(100, 100);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x333344,
roughness: 0.8,
metalness: 0.2
});
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
gameState.scene.add(ground);
// Buildings
const buildingGeometry = new THREE.BoxGeometry(10, 15, 10);
const buildingMaterial = new THREE.MeshStandardMaterial({
color: 0x222233,
roughness: 0.7,
metalness: 0.3
});
for (let i = 0; i < 20; i++) {
const building = new THREE.Mesh(buildingGeometry, buildingMaterial);
building.position.x = (Math.random() - 0.5) * 80;
building.position.z = (Math.random() - 0.5) * 80;
building.position.y = 7.5;
building.castShadow = true;
building.receiveShadow = true;
gameState.scene.add(building);
}
// Player
const playerGeometry = new THREE.CapsuleGeometry(0.5, 1, 4, 8);
const playerMaterial = new THREE.MeshStandardMaterial({
color: 0x4a5568,
roughness: 0.5,
metalness: 0.5
});
gameState.player.mesh = new THREE.Mesh(playerGeometry, playerMaterial);
gameState.player.mesh.position.set(0, 1, 0);
gameState.player.mesh.castShadow = true;
gameState.scene.add(gameState.player.mesh);
// Event listeners
window.addEventListener('resize', onWindowResize);
document.addEventListener('keydown', onKeyDown);
document.addEventListener('keyup', onKeyUp);
// UI Event Listeners
document.querySelectorAll('.ability').forEach(ability => {
ability.addEventListener('click', () => castSpell(ability.dataset.ability));
});
document.getElementById('inventory-btn').addEventListener('click', openInventory);
document.getElementById('close-inventory').addEventListener('click', closeInventory);
document.getElementById('close-quest').addEventListener('click', () => {
document.getElementById('quest-info').classList.add('hidden');
});
// Initialize UI
updateUI();
loadInventory();
updateQuestUI();
// Start game loop
animate();
}
// Game loop
function animate() {
requestAnimationFrame(animate);
const deltaTime = gameState.clock.getDelta();
const time = gameState.clock.getElapsedTime();
// Update player movement
updatePlayer(deltaTime);
// Update cooldowns
updateCooldowns(deltaTime);
// Update controls
gameState.controls.update();
// Render scene
gameState.renderer.render(gameState.scene, gameState.camera);
// Update UI every 10 frames
if (Math.floor(time * 10) % 10 === 0) {
updateUI();
}
gameState.lastTime = time;
}
// Update player movement
function updatePlayer(deltaTime) {
const moveSpeed = 5;
const jumpForce = 8;
const gravity = -20;
// Movement direction
const direction = new THREE.Vector3();
if (gameState.keys.w) direction.z -= 1;
if (gameState.keys.s) direction.z += 1;
if (gameState.keys.a) direction.x -= 1;
if (gameState.keys.d) direction.x += 1;
// Normalize direction
if (direction.length() > 0) {
direction.normalize();
}
// Apply movement
const moveDistance = moveSpeed * deltaTime;
direction.multiplyScalar(moveDistance);
// Apply rotation to movement direction
direction.applyEuler(new THREE.Euler(0, gameState.camera.rotation.y, 0));
gameState.player.velocity.x = direction.x;
gameState.player.velocity.z = direction.z;
// Jumping
if (gameState.keys.space && gameState.player.isGrounded) {
gameState.player.velocity.y = jumpForce;
gameState.player.isGrounded = false;
}
// Apply gravity
gameState.player.velocity.y += gravity * deltaTime;
// Update position
gameState.player.mesh.position.x += gameState.player.velocity.x;
gameState.player.mesh.position.y += gameState.player.velocity.y;
gameState.player.mesh.position.z += gameState.player.velocity.z;
// Ground collision
if (gameState.player.mesh.position.y < 1) {
gameState.player.mesh.position.y = 1;
gameState.player.velocity.y = 0;
gameState.player.isGrounded = true;
}
// Update camera position to follow player
gameState.camera.position.x = gameState.player.mesh.position.x;
gameState.camera.position.z = gameState.player.mesh.position.z + 5;
gameState.camera.position.y = gameState.player.mesh.position.y + 2;
gameState.camera.lookAt(
gameState.player.mesh.position.x,
gameState.player.mesh.position.y + 1,
gameState.player.mesh.position.z
);
}
// Update ability cooldowns
function updateCooldowns(deltaTime) {
for (const ability in gameState.player.abilities) {
if (gameState.player.abilities[ability].cooldown > 0) {
gameState.player.abilities[ability].cooldown -= deltaTime;
if (gameState.player.abilities[ability].cooldown < 0) {
gameState.player.abilities[ability].cooldown = 0;
}
// Update UI
const abilityElement = document.querySelector(`.ability[data-ability="${ability}"]`);
if (abilityElement) {
const cooldownElement = abilityElement.querySelector('.cooldown');
const cooldownPercent = (gameState.player.abilities[ability].cooldown /
gameState.player.abilities[ability].maxCooldown) * 100;
cooldownElement.style.height = `${cooldownPercent}%`;
}
}
}
}
// Cast a spell
function castSpell(spellName) {
const ability = gameState.player.abilities[spellName];
// Check if ability is on cooldown or not enough mana
if (ability.cooldown > 0 || gameState.player.mana < ability.cost) {
// Play error sound or show feedback
return;
}
// Deduct mana
gameState.player.mana -= ability.cost;
ability.cooldown = ability.maxCooldown;
// Spell effects
switch (spellName) {
case 'fireball':
createFireball();
break;
case 'frost-nova':
createFrostNova();
break;
case 'lightning':
createLightning();
break;
case 'teleport':
teleportPlayer();
break;
}
// Update quest progress if it's the initiation quest
if (gameState.activeQuest === 'initiation' && !gameState.quests[0].completed) {
gameState.quests[0].progress++;
if (gameState.quests[0].progress >= gameState.quests[0].goal) {
completeQuest('initiation');
}
updateQuestUI();
}
updateUI();
}
// Create a fireball projectile
function createFireball() {
const fireballGeometry = new THREE.SphereGeometry(0.3, 16, 16);
const fireballMaterial = new THREE.MeshStandardMaterial({
color: 0xff6600,
emissive: 0xff3300,
emissiveIntensity: 1,
roughness: 0.1,
metalness: 0.3
});
const fireball = new THREE.Mesh(fireballGeometry, fireballMaterial);
// Position fireball in front of player
fireball.position.copy(gameState.player.mesh.position);
fireball.position.y += 1;
// Add light
const fireballLight = new THREE.PointLight(0xff6600, 2, 10);
fireball.add(fireballLight);
gameState.scene.add(fireball);
// Fireball direction
const direction = new THREE.Vector3(0, 0, -1);
direction.applyQuaternion(gameState.camera.quaternion);
direction.normalize();
// Fireball speed
const speed = 20;
// Animate fireball
const fireballInterval = setInterval(() => {
fireball.position.x += direction.x * speed * 0.016;
fireball.position.y += direction.y * speed * 0.016;
fireball.position.z += direction.z * speed * 0.016;
// Check if fireball is out of bounds
if (fireball.position.length() > 50) {
clearInterval(fireballInterval);
gameState.scene.remove(fireball);
}
// Check for collisions (simplified)
// In a real game, you'd use a physics engine for this
}, 16);
// Remove fireball after 3 seconds
setTimeout(() => {
clearInterval(fireballInterval);
gameState.scene.remove(fireball);
}, 3000);
}
// Create a frost nova effect
function createFrostNova() {
const frostGeometry = new THREE.SphereGeometry(5, 32, 32);
const frostMaterial = new THREE.MeshStandardMaterial({
color: 0x00aaff,
transparent: true,
opacity: 0.5,
roughness: 0.2,
metalness: 0.7
});
const frostNova = new THREE.Mesh(frostGeometry, frostMaterial);
frostNova.position.copy(gameState.player.mesh.position);
frostNova.position.y += 1;
// Add light
const frostLight = new THREE.PointLight(0x00aaff, 3, 10);
frostNova.add(frostLight);
gameState.scene.add(frostNova);
// Animate frost nova
let scale = 0.1;
const frostInterval = setInterval(() => {
scale += 0.1;
frostNova.scale.set(scale, scale, scale);
if (scale >= 1) {
clearInterval(frostInterval);
// Fade out
let opacity = 0.5;
const fadeInterval = setInterval(() => {
opacity -= 0.05;
frostMaterial.opacity = opacity;
if (opacity <= 0) {
clearInterval(fadeInterval);
gameState.scene.remove(frostNova);
}
}, 50);
}
}, 50);
}
// Create a lightning strike
function createLightning() {
const lightningGroup = new THREE.Group();
lightningGroup.position.copy(gameState.player.mesh.position);
lightningGroup.position.y += 10;
// Create multiple lightning bolts
for (let i = 0; i < 5; i++) {
const points = [];
const height = 10 + Math.random() * 5;
const segments = 10;
for (let j = 0; j <= segments; j++) {
const offset = j === 0 || j === segments ? 0 : Math.random() * 0.5 - 0.25;
points.push(new THREE.Vector3(
offset,
-height * (j / segments),
offset
));
}
const lightningGeometry = new THREE.BufferGeometry().setFromPoints(points);
const lightningMaterial = new THREE.LineBasicMaterial({
color: 0x88ccff,
transparent: true,
opacity: 0.8
});
const lightning = new THREE.Line(lightningGeometry, lightningMaterial);
lightningGroup.add(lightning);
}
gameState.scene.add(lightningGroup);
// Add light
const lightningLight = new THREE.PointLight(0x88ccff, 5, 20);
lightningGroup.add(lightningLight);
// Fade out
let opacity = 0.8;
const fadeInterval = setInterval(() => {
opacity -= 0.05;
lightningGroup.children.forEach(child => {
if (child.material) child.material.opacity = opacity;
});
if (opacity <= 0) {
clearInterval(fadeInterval);
gameState.scene.remove(lightningGroup);
}
}, 50);
}
// Teleport player forward
function teleportPlayer() {
const distance = 8;
const direction = new THREE.Vector3(0, 0, -1);
direction.applyQuaternion(gameState.camera.quaternion);
direction.normalize();
gameState.player.mesh.position.x += direction.x * distance;
gameState.player.mesh.position.z += direction.z * distance;
// Create teleport effect
const teleportGeometry = new THREE.SphereGeometry(1, 32, 32);
const teleportMaterial = new THREE.MeshStandardMaterial({
color: 0xaa00ff,
transparent: true,
opacity: 0.7,
roughness: 0.1,
metalness: 0.8
});
const teleportStart = new THREE.Mesh(teleportGeometry, teleportMaterial);
teleportStart.position.copy(gameState.player.mesh.position);
teleportStart.position.y += 1;
const teleportEnd = new THREE.Mesh(teleportGeometry, teleportMaterial);
teleportEnd.position.copy(gameState.player.mesh.position);
teleportEnd.position.x -= direction.x * distance;
teleportEnd.position.z -= direction.z * distance;
teleportEnd.position.y += 1;
gameState.scene.add(teleportStart);
gameState.scene.add(teleportEnd);
// Add lights
const teleportLightStart = new THREE.PointLight(0xaa00ff, 3, 5);
teleportStart.add(teleportLightStart);
const teleportLightEnd = new THREE.PointLight(0xaa00ff, 3, 5);
teleportEnd.add(teleportLightEnd);
// Fade out
let scale = 1;
const teleportInterval = setInterval(() => {
scale += 0.1;
teleportStart.scale.set(scale, scale, scale);
teleportEnd.scale.set(scale, scale, scale);
teleportMaterial.opacity -= 0.05;
if (teleportMaterial.opacity <= 0) {
clearInterval(teleportInterval);
gameState.scene.remove(teleportStart);
gameState.scene.remove(teleportEnd);
}
}, 50);
}
// Complete a quest
function completeQuest(questId) {
const questIndex = gameState.quests.findIndex(q => q.id === questId);
if (questIndex === -1) return;
gameState.quests[questIndex].completed = true;
// Give rewards
const reward = gameState.quests[questIndex].reward;
gameState.gold += reward.gold;
if (reward.item) {
// Add item to inventory
const existingItem = gameState.inventory.find(item => item.id === reward.item);
if (existingItem) {
existingItem.quantity++;
} else {
// Define new items here
const newItems = {
'enchanted-ring': { id: 'enchanted-ring', name: 'Enchanted Ring', icon: 'fa-ring', quantity: 1 },
'cloak-of-shadows': { id: 'cloak-of-shadows', name: 'Cloak of Shadows', icon: 'fa-vest', quantity: 1 },
'staff-of-power': { id: 'staff-of-power', name: 'Staff of Power', icon: 'fa-magic', quantity: 1 }
};
if (newItems[reward.item]) {
gameState.inventory.push(newItems[reward.item]);
}
}
loadInventory();
}
// Update UI
updateUI();
updateQuestUI();
// Move to next quest if available
if (questId === 'initiation') {
gameState.activeQuest = 'rebellion';
} else if (questId === 'rebellion') {
gameState.activeQuest = 'artifact';
}
}
// Open inventory
function openInventory() {
document.getElementById('inventory-modal').classList.remove('hidden');
}
// Close inventory
function closeInventory() {
document.getElementById('inventory-modal').classList.add('hidden');
}
// Load inventory items into UI
function loadInventory() {
const inventoryGrid = document.getElementById('inventory-grid');
inventoryGrid.innerHTML = '';
gameState.inventory.forEach(item => {
const itemElement = document.createElement('div');
itemElement.className = 'inventory-item ui-panel flex flex-col items-center p-2 cursor-pointer';
itemElement.innerHTML = `
<i class="fas ${item.icon} text-2xl mb-1"></i>
<span class="text-sm text-center">${item.name}</span>
${item.quantity > 1 ? `<span class="absolute top-0 right-0 bg-gray-700 text-xs px-1 rounded-bl">${item.quantity}</span>` : ''}
`;
// Add click handler for potions
if (item.id.includes('potion')) {
itemElement.addEventListener('click', () => useItem(item.id));
}
inventoryGrid.appendChild(itemElement);
});
}
// Use an item
function useItem(itemId) {
const itemIndex = gameState.inventory.findIndex(item => item.id === itemId);
if (itemIndex === -1) return;
const item = gameState.inventory[itemIndex];
switch (itemId) {
case 'health-potion':
gameState.player.health = Math.min(gameState.player.health + 30, gameState.player.maxHealth);
break;
case 'mana-potion':
gameState.player.mana = Math.min(gameState.player.mana + 40, gameState.player.maxMana);
break;
}
// Remove item or decrement quantity
if (item.quantity > 1) {
item.quantity--;
} else {
gameState.inventory.splice(itemIndex, 1);
}
// Update UI
updateUI();
loadInventory();
}
// Update quest UI
function updateQuestUI() {
const activeQuest = gameState.quests.find(q => q.id === gameState.activeQuest);
if (!activeQuest) return;
document.getElementById('quest-title').textContent = activeQuest.title;
document.getElementById('quest-description').textContent = activeQuest.description;
const progressPercent = (activeQuest.progress / activeQuest.goal) * 100;
document.getElementById('quest-progress').style.width = `${progressPercent}%`;
document.getElementById('quest-progress-text').textContent = `${Math.round(progressPercent)}%`;
// Show quest info if not already shown
if (document.getElementById('quest-info').classList.contains('hidden')) {
document.getElementById('quest-info').classList.remove('hidden');
}
}
// Update UI elements
function updateUI() {
document.getElementById('health').textContent =
`${Math.floor(gameState.player.health)}/${gameState.player.maxHealth}`;
document.getElementById('mana').textContent =
`${Math.floor(gameState.player.mana)}/${gameState.player.maxMana}`;
document.getElementById('gold').textContent = gameState.player.gold;
}
// Window resize handler
function onWindowResize() {
gameState.camera.aspect = window.innerWidth / window.innerHeight;
gameState.camera.updateProjectionMatrix();
gameState.renderer.setSize(window.innerWidth, window.innerHeight);
}
// Key down handler
function onKeyDown(event) {
switch (event.key.toLowerCase()) {
case 'w': gameState.keys.w = true; break;
case 'a': gameState.keys.a = true; break;
case 's': gameState.keys.s = true; break;
case 'd': gameState.keys.d = true; break;
case ' ': gameState.keys.space = true; break;
case 'q': castSpell('fireball'); break;
case 'e': castSpell('frost-nova'); break;
case 'r': castSpell('lightning'); break;
case 'f': castSpell('teleport'); break;
case 'i': openInventory(); break;
case 'j':
document.getElementById('quest-info').classList.toggle('hidden');
break;
}
}
// Key up handler
function onKeyUp(event) {
switch (event.key.toLowerCase()) {
case 'w': gameState.keys.w = false; break;
case 'a': gameState.keys.a = false; break;
case 's': gameState.keys.s = false; break;
case 'd': gameState.keys.d = false; break;
case ' ': gameState.keys.space = false; break;
}
}
// Initialize the game when the page loads
window.onload = initScene;
</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=toastiselite/test" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>