Красивый 3д симулятор ходьбы от 3 лица как в gta 5
Browse files
README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
---
|
| 2 |
-
title: 3
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: ---------3----------------------3-------
|
| 3 |
+
colorFrom: purple
|
| 4 |
+
colorTo: green
|
| 5 |
+
emoji: 🐳
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite-v3
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Welcome to your new DeepSite project!
|
| 13 |
+
This project was created with [DeepSite](https://deepsite.hf.co).
|
index.html
CHANGED
|
@@ -1,19 +1,97 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>3D Walker Simulator</title>
|
| 7 |
+
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
|
| 8 |
+
<link rel="stylesheet" href="style.css">
|
| 9 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 10 |
+
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
| 11 |
+
<script src="https://unpkg.com/feather-icons"></script>
|
| 12 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
| 13 |
+
</head>
|
| 14 |
+
<body class="bg-black text-white overflow-hidden">
|
| 15 |
+
<!-- Loading Screen -->
|
| 16 |
+
<div id="loadingScreen" class="fixed inset-0 bg-gradient-to-b from-gray-900 to-black z-50 flex items-center justify-center">
|
| 17 |
+
<div class="text-center">
|
| 18 |
+
<div class="mb-8">
|
| 19 |
+
<div class="w-32 h-32 mx-auto border-4 border-blue-500 border-t-transparent rounded-full animate-spin"></div>
|
| 20 |
+
</div>
|
| 21 |
+
<h1 class="text-4xl font-bold mb-4 bg-gradient-to-r from-blue-400 to-purple-500 bg-clip-text text-transparent">3D Walker Simulator</h1>
|
| 22 |
+
<p class="text-gray-400">Loading world...</p>
|
| 23 |
+
</div>
|
| 24 |
+
</div>
|
| 25 |
+
|
| 26 |
+
<!-- Game Canvas -->
|
| 27 |
+
<canvas id="gameCanvas" class="fixed inset-0"></canvas>
|
| 28 |
+
|
| 29 |
+
<!-- HUD Overlay -->
|
| 30 |
+
<div id="hud" class="fixed inset-0 pointer-events-none hidden">
|
| 31 |
+
<!-- Crosshair -->
|
| 32 |
+
<div class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2">
|
| 33 |
+
<div class="w-4 h-4 border-2 border-white/50 rounded-full"></div>
|
| 34 |
+
</div>
|
| 35 |
+
|
| 36 |
+
<!-- Mini Map -->
|
| 37 |
+
<div class="absolute top-4 right-4 w-48 h-48 bg-black/50 backdrop-blur-sm rounded-lg border border-white/20 p-2">
|
| 38 |
+
<canvas id="miniMap" class="w-full h-full rounded"></canvas>
|
| 39 |
+
</div>
|
| 40 |
+
|
| 41 |
+
<!-- Stats Panel -->
|
| 42 |
+
<div class="absolute top-4 left-4 bg-black/50 backdrop-blur-sm rounded-lg border border-white/20 p-4">
|
| 43 |
+
<div class="flex items-center gap-2 mb-2">
|
| 44 |
+
<i data-feather="map-pin" class="w-4 h-4 text-green-400"></i>
|
| 45 |
+
<span class="text-sm">Position: <span id="position">0, 0</span></span>
|
| 46 |
+
</div>
|
| 47 |
+
<div class="flex items-center gap-2 mb-2">
|
| 48 |
+
<i data-feather="trending-up" class="w-4 h-4 text-blue-400"></i>
|
| 49 |
+
<span class="text-sm">Speed: <span id="speed">0</span> km/h</span>
|
| 50 |
+
</div>
|
| 51 |
+
<div class="flex items-center gap-2">
|
| 52 |
+
<i data-feather="clock" class="w-4 h-4 text-yellow-400"></i>
|
| 53 |
+
<span class="text-sm">Time: <span id="gameTime">12:00</span></span>
|
| 54 |
+
</div>
|
| 55 |
+
</div>
|
| 56 |
+
|
| 57 |
+
<!-- Controls Help -->
|
| 58 |
+
<div class="absolute bottom-4 left-4 bg-black/50 backdrop-blur-sm rounded-lg border border-white/20 p-4">
|
| 59 |
+
<h3 class="font-semibold mb-2 text-sm">Controls</h3>
|
| 60 |
+
<div class="text-xs space-y-1 text-gray-300">
|
| 61 |
+
<div><kbd class="px-1 py-0.5 bg-gray-700 rounded">W A S D</kbd> Move</div>
|
| 62 |
+
<div><kbd class="px-1 py-0.5 bg-gray-700 rounded">Mouse</kbd> Look Around</div>
|
| 63 |
+
<div><kbd class="px-1 py-0.5 bg-gray-700 rounded">Shift</kbd> Run</div>
|
| 64 |
+
<div><kbd class="px-1 py-0.5 bg-gray-700 rounded">Space</kbd> Jump</div>
|
| 65 |
+
</div>
|
| 66 |
+
</div>
|
| 67 |
+
|
| 68 |
+
<!-- Action Buttons -->
|
| 69 |
+
<div class="absolute bottom-4 right-4 pointer-events-auto">
|
| 70 |
+
<button id="toggleMusic" class="bg-purple-600 hover:bg-purple-700 px-4 py-2 rounded-lg flex items-center gap-2 transition-colors mb-2">
|
| 71 |
+
<i data-feather="volume-2" class="w-4 h-4"></i>
|
| 72 |
+
<span>Music</span>
|
| 73 |
+
</button>
|
| 74 |
+
<button id="togglePause" class="bg-blue-600 hover:bg-blue-700 px-4 py-2 rounded-lg flex items-center gap-2 transition-colors">
|
| 75 |
+
<i data-feather="pause" class="w-4 h-4"></i>
|
| 76 |
+
<span>Pause</span>
|
| 77 |
+
</button>
|
| 78 |
+
</div>
|
| 79 |
+
</div>
|
| 80 |
+
|
| 81 |
+
<!-- Start Screen -->
|
| 82 |
+
<div id="startScreen" class="fixed inset-0 bg-gradient-to-b from-gray-900 to-black z-40 flex items-center justify-center">
|
| 83 |
+
<div class="text-center max-w-2xl px-8">
|
| 84 |
+
<h1 class="text-6xl font-bold mb-4 bg-gradient-to-r from-blue-400 to-purple-500 bg-clip-text text-transparent">3D Walker Simulator</h1>
|
| 85 |
+
<p class="text-xl text-gray-400 mb-8">Explore the open world in third person</p>
|
| 86 |
+
<button id="startButton" class="bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-700 hover:to-purple-700 px-8 py-4 rounded-lg text-xl font-semibold transition-all transform hover:scale-105">
|
| 87 |
+
Start Walking
|
| 88 |
+
</button>
|
| 89 |
+
</div>
|
| 90 |
+
</div>
|
| 91 |
+
|
| 92 |
+
<script src="style.css"></script>
|
| 93 |
+
<script src="script.js"></script>
|
| 94 |
+
<script>feather.replace();</script>
|
| 95 |
+
<script src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veSpeed = 0.1;
|
| 5 |
+
let runSpeed = 0.2;
|
| 6 |
+
let jumpHeight = 0.3;
|
| 7 |
+
let isJumping = false;
|
| 8 |
+
let velocity = { x: 0, y: 0, z: 0 };
|
| 9 |
+
let keys = {};
|
| 10 |
+
let mouseX = 0, mouseY = 0;
|
| 11 |
+
let isPaused = false;
|
| 12 |
+
let gameStartTime = Date.now();
|
| 13 |
+
let buildings = [];
|
| 14 |
+
let ground;
|
| 15 |
+
let clock = new THREE.Clock();
|
| 16 |
+
|
| 17 |
+
// Initialize Game
|
| 18 |
+
function init() {
|
| 19 |
+
// Create Scene
|
| 20 |
+
scene = new THREE.Scene();
|
| 21 |
+
scene.fog = new THREE.Fog(0x87CEEB, 10, 100);
|
| 22 |
+
scene.background = new THREE.Color(0x87CEEB);
|
| 23 |
+
|
| 24 |
+
// Setup Camera
|
| 25 |
+
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
| 26 |
+
camera.position.set(0, 5, 10);
|
| 27 |
+
|
| 28 |
+
// Setup Renderer
|
| 29 |
+
renderer = new THREE.WebGLRenderer({
|
| 30 |
+
canvas: document.getElementById('gameCanvas'),
|
| 31 |
+
antialias: true
|
| 32 |
+
});
|
| 33 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 34 |
+
renderer.shadowMap.enabled = true;
|
| 35 |
+
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
| 36 |
+
|
| 37 |
+
// Create Lighting
|
| 38 |
+
setupLighting();
|
| 39 |
+
|
| 40 |
+
// Create World
|
| 41 |
+
createGround();
|
| 42 |
+
createBuildings();
|
| 43 |
+
createPlayer();
|
| 44 |
+
|
| 45 |
+
// Setup Controls
|
| 46 |
+
setupControls();
|
| 47 |
+
|
| 48 |
+
// Start Game Loop
|
| 49 |
+
animate();
|
| 50 |
+
|
| 51 |
+
// Hide Loading Screen
|
| 52 |
+
setTimeout(() => {
|
| 53 |
+
document.getElementById('loadingScreen').style.display = 'none';
|
| 54 |
+
}, 2000);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
function setupLighting() {
|
| 58 |
+
// Ambient Light
|
| 59 |
+
const ambientLight = new THREE.AmbientLight(0x404040, 0.6);
|
| 60 |
+
scene.add(ambientLight);
|
| 61 |
+
|
| 62 |
+
// Directional Light (Sun)
|
| 63 |
+
const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
|
| 64 |
+
directionalLight.position.set(50, 100, 50);
|
| 65 |
+
directionalLight.castShadow = true;
|
| 66 |
+
directionalLight.shadow.camera.left = -50;
|
| 67 |
+
directionalLight.shadow.camera.right = 50;
|
| 68 |
+
directionalLight.shadow.camera.top = 50;
|
| 69 |
+
directionalLight.shadow.camera.bottom = -50;
|
| 70 |
+
directionalLight.shadow.camera.near = 0.1;
|
| 71 |
+
directionalLight.shadow.camera.far = 200;
|
| 72 |
+
directionalLight.shadow.mapSize.width = 2048;
|
| 73 |
+
directionalLight.shadow.mapSize.height = 2048;
|
| 74 |
+
scene.add(directionalLight);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
function createGround() {
|
| 78 |
+
const groundGeometry = new THREE.PlaneGeometry(200, 200);
|
| 79 |
+
const groundMaterial = new THREE.MeshLambertMaterial({
|
| 80 |
+
color: 0x3a5f3a,
|
| 81 |
+
side: THREE.DoubleSide
|
| 82 |
+
});
|
| 83 |
+
ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
| 84 |
+
ground.rotation.x = -Math.PI / 2;
|
| 85 |
+
ground.receiveShadow = true;
|
| 86 |
+
scene.add(ground);
|
| 87 |
+
|
| 88 |
+
// Add road
|
| 89 |
+
const roadGeometry = new THREE.PlaneGeometry(10, 200);
|
| 90 |
+
const roadMaterial = new THREE.MeshLambertMaterial({ color: 0x333333 });
|
| 91 |
+
const road = new THREE.Mesh(roadGeometry, roadMaterial);
|
| 92 |
+
road.rotation.x = -Math.PI / 2;
|
| 93 |
+
road.position.y = 0.01;
|
| 94 |
+
road.receiveShadow = true;
|
| 95 |
+
scene.add(road);
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
function createBuildings() {
|
| 99 |
+
const buildingPositions = [
|
| 100 |
+
{ x: -20, z: -20, height: 30, width: 10, depth: 10 },
|
| 101 |
+
{ x: 20, z: -20, height: 25, width: 12, depth: 8 },
|
| 102 |
+
{ x: -20, z: 20, height: 35, width: 8, depth: 12 },
|
| 103 |
+
{ x: 20, z: 20, height: 40, width: 15, depth: 10 },
|
| 104 |
+
{ x: -40, z: 0, height: 20, width: 10, depth: 10 },
|
| 105 |
+
{ x: 40, z: 0, height: 28, width: 10, depth: 10 },
|
| 106 |
+
{ x: 0, z: -40, height: 32, width: 12, depth: 12 },
|
| 107 |
+
{ x: 0, z: 40, height: 24, width: 10, depth: 10 }
|
| 108 |
+
];
|
| 109 |
+
|
| 110 |
+
buildingPositions.forEach(pos => {
|
| 111 |
+
const buildingGeometry = new THREE.BoxGeometry(pos.width, pos.height, pos.depth);
|
| 112 |
+
const buildingMaterial = new THREE.MeshLambertMaterial({
|
| 113 |
+
color: new THREE.Color().setHSL(Math.random() * 0.1 + 0.5, 0.5, 0.6)
|
| 114 |
+
});
|
| 115 |
+
const building = new THREE.Mesh(buildingGeometry, buildingMaterial);
|
| 116 |
+
building.position.set(pos.x, pos.height / 2, pos.z);
|
| 117 |
+
building.castShadow = true;
|
| 118 |
+
building.receiveShadow = true;
|
| 119 |
+
buildings.push(building);
|
| 120 |
+
scene.add(building);
|
| 121 |
+
});
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
function createPlayer() {
|
| 125 |
+
// Player group
|
| 126 |
+
player = new THREE.Group();
|
| 127 |
+
|
| 128 |
+
// Body
|
| 129 |
+
const bodyGeometry = new THREE.CapsuleGeometry(0.5, 1.5, 4, 8);
|
| 130 |
+
const bodyMaterial = new THREE.MeshLambertMaterial({ color: 0x4169e1 });
|
| 131 |
+
const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
|
| 132 |
+
body.position.y = 1.5;
|
| 133 |
+
body.castShadow = true;
|
| 134 |
+
player.add(body);
|
| 135 |
+
|
| 136 |
+
// Head
|
| 137 |
+
const headGeometry = new THREE.SphereGeometry(0.3, 16, 16);
|
| 138 |
+
const headMaterial = new THREE.MeshLambertMaterial({ color: 0xffdbac });
|
| 139 |
+
const head = new THREE.Mesh(headGeometry, headMaterial);
|
| 140 |
+
head.position.y = 2.7;
|
| 141 |
+
head.castShadow = true;
|
| 142 |
+
player.add(head);
|
| 143 |
+
|
| 144 |
+
player.position.set(0, 0, 0);
|
| 145 |
+
playerModel = player;
|
| 146 |
+
scene.add(player);
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
function setupControls() {
|
| 150 |
+
// Keyboard controls
|
| 151 |
+
document.addEventListener('keydown', (event) => {
|
| 152 |
+
keys[event.code] = true;
|
| 153 |
+
|
| 154 |
+
if (event.code === 'Space' && !isJumping) {
|
| 155 |
+
velocity.y = jumpHeight;
|
| 156 |
+
isJumping = true;
|
| 157 |
+
}
|
| 158 |
+
});
|
| 159 |
+
|
| 160 |
+
document.addEventListener('keyup', (event) => {
|
| 161 |
+
keys[event.code] = false;
|
| 162 |
+
});
|
| 163 |
+
|
| 164 |
+
// Mouse controls
|
| 165 |
+
document.addEventListener('mousemove', (event) => {
|
| 166 |
+
mouseX = (event.clientX / window.innerWidth) * 2 - 1;
|
| 167 |
+
mouseY = -(event.clientY / window.innerHeight) * 2 + 1;
|
| 168 |
+
});
|
| 169 |
+
|
| 170 |
+
// Window resize
|
| 171 |
+
window.addEventListener('resize', () => {
|
| 172 |
+
camera.aspect = window.innerWidth / window.innerHeight;
|
| 173 |
+
camera.updateProjectionMatrix();
|
| 174 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 175 |
+
});
|
| 176 |
+
|
| 177 |
+
// UI Controls
|
| 178 |
+
document.getElementById('startButton').addEventListener('click', () => {
|
| 179 |
+
document.getElementById('startScreen').style.display = 'none';
|
| 180 |
+
document.getElementById('hud').classList.remove('hidden');
|
| 181 |
+
document.body.requestPointerLock();
|
| 182 |
+
});
|
| 183 |
+
|
| 184 |
+
document.getElementById('togglePause').addEventListener('click', () => {
|
| 185 |
+
isPaused = !isPaused;
|
| 186 |
+
const btn = document.getElementById('togglePause');
|
| 187 |
+
btn.innerHTML = isPaused ?
|
| 188 |
+
'<i data-feather="play" class="w-4 h-4"></i><span>Resume</span>' :
|
| 189 |
+
'<i data-feather="pause" class="w-4 h-4"></i><span>Pause</span>';
|
| 190 |
+
feather.replace();
|
| 191 |
+
});
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
function updatePlayer() {
|
| 195 |
+
if (isPaused) return;
|
| 196 |
+
|
| 197 |
+
const speed = keys['ShiftLeft'] ? runSpeed : moveSpeed;
|
| 198 |
+
const moveVector = new THREE.Vector3();
|
| 199 |
+
|
| 200 |
+
// Calculate movement
|
| 201 |
+
if (keys['KeyW']) moveVector.z -= speed;
|
| 202 |
+
if (keys['KeyS']) moveVector.z += speed;
|
| 203 |
+
if (keys['KeyA']) moveVector.x -= speed;
|
| 204 |
+
if (keys['KeyD']) moveVector.x += speed;
|
| 205 |
+
|
| 206 |
+
// Apply movement relative to camera direction
|
| 207 |
+
const angle = camera.rotation.y;
|
| 208 |
+
const rotatedVector = moveVector.applyAxisAngle(new THREE.Vector3(0, 1, 0), angle);
|
| 209 |
+
|
| 210 |
+
player.position.x += rotatedVector.x;
|
| 211 |
+
player.position.z += rotatedVector.z;
|
| 212 |
+
|
| 213 |
+
// Apply gravity
|
| 214 |
+
velocity.y -= 0.015;
|
| 215 |
+
player.position.y += velocity.y;
|
| 216 |
+
|
| 217 |
+
// Ground collision
|
| 218 |
+
if (player.position.y <= 0) {
|
| 219 |
+
player.position.y = 0;
|
| 220 |
+
velocity.y = 0;
|
| 221 |
+
isJumping = false;
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
// Building collision (simple)
|
| 225 |
+
buildings.forEach(building => {
|
| 226 |
+
const distance = player.position.distanceTo(building.position);
|
| 227 |
+
const minDistance = 5; // Simple collision radius
|
| 228 |
+
if (distance < minDistance) {
|
| 229 |
+
const direction = new THREE.Vector3()
|
| 230 |
+
.subVectors(player.position, building.position)
|
| 231 |
+
.normalize();
|
| 232 |
+
player.position.copy(building.position).add(direction.multiplyScalar(minDistance));
|
| 233 |
+
}
|
| 234 |
+
});
|
| 235 |
+
|
| 236 |
+
// Update camera to follow player
|
| 237 |
+
const cameraOffset = new THREE.Vector3(0, 5, 10);
|
| 238 |
+
cameraOffset.applyAxisAngle(new THREE.Vector3(0, 1, 0), angle);
|
| 239 |
+
camera.position.copy(player.position).add(cameraOffset);
|
| 240 |
+
camera.lookAt(player.position);
|
| 241 |
+
|
| 242 |
+
// Camera rotation with mouse
|
| 243 |
+
camera.rotation.y = mouseX * Math.PI;
|
| 244 |
+
camera.rotation.x = mouseY * Math.PI / 4;
|
| 245 |
+
|
| 246 |
+
// Update HUD
|
| 247 |
+
updateHUD();
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
function updateHUD() {
|
| 251 |
+
// Position
|
| 252 |
+
document.getElementById('position').textContent =
|
| 253 |
+
`${Math.round(player.position.x)}, ${Math.round(player.position.z)}`;
|
| 254 |
+
|
| 255 |
+
// Speed
|
| 256 |
+
const currentSpeed = Math.sqrt(velocity.x ** 2 + velocity.z ** 2) * 100;
|
| 257 |
+
document.getElementById('speed').textContent = Math.round(currentSpeed);
|
| 258 |
+
|
| 259 |
+
// Game Time
|
| 260 |
+
const elapsed = Date.now() - gameStartTime;
|
| 261 |
+
const minutes = Math.floor(elapsed / 60000);
|
| 262 |
+
const seconds = Math.floor((elapsed % 60000) / 1000);
|
| 263 |
+
document.getElementById('gameTime').textContent =
|
| 264 |
+
`${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
|
| 265 |
+
|
| 266 |
+
// Update mini map
|
| 267 |
+
updateMiniMap();
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
function updateMiniMap() {
|
| 271 |
+
const canvas = document.getElementById('miniMap');
|
| 272 |
+
const ctx = canvas.getContext('2d');
|
| 273 |
+
canvas.width = 192;
|
| 274 |
+
canvas.height = 192;
|
| 275 |
+
|
| 276 |
+
// Clear
|
| 277 |
+
ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
|
| 278 |
+
ctx.fillRect(0, 0, 192, 192);
|
| 279 |
+
|
| 280 |
+
// Draw player position
|
| 281 |
+
const mapX = (player.position.x + 100) * 0.96;
|
| 282 |
+
const mapZ = (player.position.z + 100) * 0.96;
|
| 283 |
+
|
| 284 |
+
ctx.fillStyle = '#4ade80';
|
| 285 |
+
ctx.beginPath();
|
| 286 |
+
ctx.arc(mapX, mapZ, 3, 0, Math.PI * 2);
|
| 287 |
+
ctx.fill();
|
| 288 |
+
|
| 289 |
+
// Draw buildings on map
|
| 290 |
+
ctx.fillStyle = '#6b7280';
|
| 291 |
+
buildings.forEach(building => {
|
| 292 |
+
const bX = (building.position.x + 100) * 0.96;
|
| 293 |
+
const bZ = (building.position.z + 100) * 0.96;
|
| 294 |
+
ctx.fillRect(bX - 5, bZ - 5, 10, 10);
|
| 295 |
+
});
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
function animate() {
|
| 299 |
+
requestAnimationFrame(animate);
|
| 300 |
+
|
| 301 |
+
if (!isPaused) {
|
| 302 |
+
updatePlayer();
|
| 303 |
+
|
| 304 |
+
// Animate player model (simple bobbing)
|
| 305 |
+
if (keys['KeyW'] || keys['KeyS'] || keys['KeyA'] || keys['KeyD']) {
|
| 306 |
+
player.rotation.y = camera.rotation.y;
|
| 307 |
+
player.position.y = Math.sin(Date.now() * 0.01) * 0.05;
|
| 308 |
+
}
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
renderer.render(scene, camera);
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
// Start the game when page loads
|
| 315 |
+
window.addEventListener('load', init);
|
style.css
CHANGED
|
@@ -1,28 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
body {
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
}
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
}
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
font-size: 15px;
|
| 14 |
-
margin-bottom: 10px;
|
| 15 |
-
margin-top: 5px;
|
| 16 |
}
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
border: 1px solid lightgray;
|
| 23 |
-
border-radius: 16px;
|
| 24 |
}
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 28 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Global Styles */
|
| 2 |
+
* {
|
| 3 |
+
margin: 0;
|
| 4 |
+
padding: 0;
|
| 5 |
+
box-sizing: border-box;
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
body {
|
| 9 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
| 10 |
+
cursor: crosshair;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
/* Canvas Styles */
|
| 14 |
+
#gameCanvas {
|
| 15 |
+
display: block;
|
| 16 |
+
width: 100vw;
|
| 17 |
+
height: 100vh;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
/* Loading Animation */
|
| 21 |
+
@keyframes pulse {
|
| 22 |
+
0%, 100% { opacity: 1; }
|
| 23 |
+
50% { opacity: 0.5; }
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
/* HUD Elements */
|
| 27 |
+
.backdrop-blur-sm {
|
| 28 |
+
backdrop-filter: blur(4px);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
/* Keyboard Key Style */
|
| 32 |
+
kbd {
|
| 33 |
+
font-family: monospace;
|
| 34 |
+
font-size: 0.75em;
|
| 35 |
+
font-weight: 600;
|
| 36 |
+
letter-spacing: 0.05em;
|
| 37 |
+
border: 1px solid rgba(255, 255, 255, 0.2);
|
| 38 |
+
border-radius: 0.25rem;
|
| 39 |
+
padding: 0.125rem 0.25rem;
|
| 40 |
+
background-color: rgba(0, 0, 0, 0.5);
|
| 41 |
+
color: rgba(255, 255, 255, 0.9);
|
| 42 |
}
|
| 43 |
|
| 44 |
+
/* Smooth Transitions */
|
| 45 |
+
.transition-all {
|
| 46 |
+
transition: all 0.3s ease;
|
| 47 |
}
|
| 48 |
|
| 49 |
+
.transition-colors {
|
| 50 |
+
transition: color 0.3s ease, background-color 0.3s ease;
|
|
|
|
|
|
|
|
|
|
| 51 |
}
|
| 52 |
|
| 53 |
+
/* Gradient Text */
|
| 54 |
+
.bg-clip-text {
|
| 55 |
+
-webkit-background-clip: text;
|
| 56 |
+
background-clip: text;
|
|
|
|
|
|
|
| 57 |
}
|
| 58 |
|
| 59 |
+
/* Custom Scrollbar */
|
| 60 |
+
::-webkit-scrollbar {
|
| 61 |
+
width: 8px;
|
| 62 |
}
|
| 63 |
+
|
| 64 |
+
::-webkit-scrollbar-track {
|
| 65 |
+
background: rgba(0, 0, 0, 0.1);
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
::-webkit-scrollbar-thumb {
|
| 69 |
+
background: rgba(255, 255, 255, 0.2);
|
| 70 |
+
border-radius: 4px;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
::-webkit-scrollbar-thumb:hover {
|
| 74 |
+
background: rgba(255, 255, 255, 0.3);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
/* Performance Optimizations */
|
| 78 |
+
.will-change-transform {
|
| 79 |
+
will-change: transform;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
.hardware-accelerated {
|
| 83 |
+
transform: translateZ(0);
|
| 84 |
+
backface-visibility: hidden;
|
| 85 |
+
perspective: 1000px;
|
| 86 |
+
}
|