-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcom.html
More file actions
442 lines (379 loc) · 21.3 KB
/
Copy pathcom.html
File metadata and controls
442 lines (379 loc) · 21.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mega Craft Racer 3D</title>
<style>
body {
margin: 0; overflow: hidden; background-color: #05050a;
font-family: 'Courier New', monospace; user-select: none;
}
#ui {
position: absolute; top: 20px; left: 20px; color: #fff;
font-size: 22px; font-weight: bold; text-shadow: 3px 3px 0px #000;
display: none; z-index: 5; line-height: 1.4;
}
.screen {
position: absolute; top: 0; left: 0; width: 100%; height: 100%;
background: radial-gradient(circle, #1a1525 0%, #07050a 100%);
display: flex; flex-direction: column; justify-content: center; align-items: center;
z-index: 10; color: #fff;
}
h1 {
font-size: 52px; color: #ff0055; text-shadow: 4px 4px 0px #00ffff;
margin-bottom: 5px; text-align: center; font-weight: 900;
}
.subtitle { color: #888; margin-bottom: 35px; font-size: 16px; letter-spacing: 1px;}
.btn {
padding: 14px 40px; font-size: 22px; font-family: inherit;
background: #00ffff; border: 4px solid #fff; color: #000;
cursor: pointer; font-weight: bold; box-shadow: 5px 5px 0px #ff0055;
transition: transform 0.1s, box-shadow 0.1s;
}
.btn:hover { transform: translate(-2px, -2px); box-shadow: 7px 7px 0px #ff0055; }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0px #ff0055; }
#game-over-screen { display: none; }
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
</head>
<body>
<div id="ui">
СКОРОСТЬ: <span id="speed" style="color: #00ffff;">0</span> КМ/Ч<br>
ДИСТАНЦИЯ: <span id="distance" style="color: #ff0055;">0</span> М
</div>
<div id="main-menu" class="screen">
<h1>CRAFT RACER</h1>
<div class="subtitle">ДЕТАЛИЗИРОВАННОЕ РЕТРО ИЗ ВОВОКСЕЛЕЙ</div>
<button class="btn" onclick="startGame()">ИГРАТЬ</button>
</div>
<div id="game-over-screen" class="screen">
<h1 style="color: #ff3333; text-shadow: 3px 3px 0px #000;">СТОЛКНОВЕНИЕ</h1>
<p id="final-score" style="font-size: 22px; margin-bottom: 30px; color: #ffff00; text-shadow: 1px 1px 0px #000;"></p>
<button class="btn" style="background:#ff3333; box-shadow: 5px 5px 0px #00ffff;" onclick="restartGame()">РЕСТАРТ</button>
</div>
<script>
// --- ДВИЖОК ИГРЫ И НАСТРОЙКИ ---
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x06050b);
scene.fog = new THREE.FogExp2(0x06050b, 0.022);
const camera = new THREE.PerspectiveCamera(55, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ antialias: false }); // Отключаем размытие ради пиксельной четкости
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Свет
const ambientLight = new THREE.AmbientLight(0xffffff, 0.7);
scene.add(ambientLight);
const dirLight = new THREE.DirectionalLight(0xfff5ea, 0.8);
dirLight.position.set(15, 35, 10);
scene.add(dirLight);
// --- ГЕНЕРАТОР ВЫСОКОКАЧЕСТВЕННЫХ PIXEL ART ТЕКСТУР ИЗ SVG ---
function makePixelTex(svgString) {
const v = encodeURIComponent(svgString);
const img = new Image();
img.src = `data:image/svg+xml;charset=utf-8,${v}`;
const texture = new THREE.Texture(img);
texture.magFilter = THREE.NearestFilter; // Важно: убирает размытие, делая честные майнкрафт-пиксели
texture.minFilter = THREE.NearestFilter;
img.onload = () => texture.needsUpdate = true;
return texture;
}
// Сложные пиксельные паттерны шума и деталей вместо монотонного цвета
const roadSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 8 8">
<rect width="8" height="8" fill="#25252b"/>
<rect x="0" y="0" width="2" height="2" fill="#212126"/>
<rect x="4" y="3" width="2" height="2" fill="#2a2a30"/>
<rect x="1" y="6" width="3" height="1" fill="#1e1e22"/>
<rect x="3" y="0" width="2" height="8" fill="#ffffcc" fill-opacity="0.15"/> </svg>`;
const grassSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 8 8">
<rect width="8" height="8" fill="#1b4d22"/>
<rect x="0" y="2" width="2" height="2" fill="#143d1a"/>
<rect x="4" y="1" width="3" height="2" fill="#225c2a"/>
<rect x="2" y="5" width="2" height="2" fill="#1a4720"/>
<rect x="5" y="6" width="2" height="1" fill="#276b30"/>
</svg>`;
const carSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 16 16">
<rect width="16" height="16" fill="#cc113c"/>
<rect x="2" y="2" width="12" height="2" fill="#aa0c30"/> <rect x="1" y="12" width="14" height="3" fill="#1e1e24"/> <rect x="2" y="13" width="3" height="2" fill="#ff3300"/> <rect x="11" y="13" width="3" height="2" fill="#ff3300"/> <rect x="5" y="0" width="6" height="2" fill="#111"/> </svg>`;
const barkSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 4 4">
<rect width="4" height="4" fill="#4a3319"/>
<rect x="0" y="0" width="1" height="4" fill="#362410"/>
<rect x="2" y="1" width="1" height="2" fill="#5c4122"/>
</svg>`;
const leafSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 8 8">
<rect width="8" height="8" fill="#2d7a36"/>
<rect x="0" y="0" width="4" height="4" fill="#22632a"/>
<rect x="4" y="4" width="3" height="3" fill="#399144"/>
</svg>`;
const stoneSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 8 8">
<rect width="8" height="8" fill="#61616b"/>
<rect x="0" y="0" width="4" height="3" fill="#4e4e57"/>
<rect x="4" y="4" width="4" height="2" fill="#73737d"/>
</svg>`;
// Создаем материалы с текстурами
const roadMat = new THREE.MeshLambertMaterial({ map: makePixelTex(roadSvg) });
const grassMat = new THREE.MeshLambertMaterial({ map: makePixelTex(grassSvg) });
const carMat = new THREE.MeshLambertMaterial({ map: makePixelTex(carSvg) });
const barkMat = new THREE.MeshLambertMaterial({ map: makePixelTex(barkSvg) });
const leafMat = new THREE.MeshLambertMaterial({ map: makePixelTex(leafSvg) });
const stoneMat = new THREE.MeshLambertMaterial({ map: makePixelTex(stoneSvg) });
// Светящиеся материалы для элементов декора
const neonBrakeMat = new THREE.MeshLambertMaterial({ color: 0xff0000, emissive: 0x990000 });
const beaconMat = new THREE.MeshLambertMaterial({ color: 0x00ffff, emissive: 0x00ffff });
// --- СОЗДАНИЕ ДЕТАЛИЗИРОВАННОЙ МАШИНЫ ИГРОКА ---
const car = new THREE.Group();
// Нижняя юбка/бамперы
const baseMesh = new THREE.Mesh(new THREE.BoxGeometry(1.54, 0.15, 2.94), new THREE.MeshLambertMaterial({color: 0x15151c}));
baseMesh.position.y = 0.15;
car.add(baseMesh);
// Основной текстурированный кузов
const carBody = new THREE.Mesh(new THREE.BoxGeometry(1.5, 0.5, 2.8), carMat);
carBody.position.y = 0.45;
car.add(carBody);
// Кабина с рамками стекол
const cabinBase = new THREE.Mesh(new THREE.BoxGeometry(1.1, 0.45, 1.3), new THREE.MeshLambertMaterial({ color: 0x0c0c10 }));
cabinBase.position.set(0, 0.85, -0.1);
car.add(cabinBase);
// Спойлер спорткара из блоков
const spoilerWing = new THREE.Mesh(new THREE.BoxGeometry(1.6, 0.1, 0.3), new THREE.MeshLambertMaterial({color: 0xaa0c30}));
spoilerWing.position.set(0, 0.85, -1.3);
const spoilerLegL = new THREE.Mesh(new THREE.BoxGeometry(0.1, 0.4, 0.1), new THREE.MeshLambertMaterial({color: 0x111}));
spoilerLegL.position.set(-0.6, 0.65, -1.3);
const spoilerLegR = spoilerLegL.clone();
spoilerLegR.position.x = 0.6;
car.add(spoilerWing, spoilerLegL, spoilerLegR);
// Светящиеся стоп-сигналы
const brakeLightL = new THREE.Mesh(new THREE.BoxGeometry(0.25, 0.12, 0.05), neonBrakeMat);
brakeLightL.position.set(-0.5, 0.5, -1.41);
const brakeLightR = brakeLightL.clone();
brakeLightR.position.x = 0.5;
car.add(brakeLightL, brakeLightR);
// Колеса с прорисованными дисками
const wheels = [];
[ [0.82, 0.25, 0.8], [-0.82, 0.25, 0.8], [0.82, 0.25, -0.8], [-0.82, 0.25, -0.8] ].forEach(pos => {
const wGroup = new THREE.Group();
const tire = new THREE.Mesh(new THREE.BoxGeometry(0.22, 0.5, 0.5), new THREE.MeshLambertMaterial({ color: 0x111115 }));
const rim = new THREE.Mesh(new THREE.BoxGeometry(0.24, 0.25, 0.25), new THREE.MeshLambertMaterial({ color: 0xcccccc }));
wGroup.add(tire, rim);
wGroup.position.set(pos[0], pos[1], pos[2]);
car.add(wGroup);
wheels.push(wGroup);
});
scene.add(car);
// --- УПРАВЛЕНИЕ И СБАЛАНСИРОВАННАЯ ФИЗИКА ---
let speed = 0;
const maxSpeed = 0.34;
const accel = 0.0035;
const deccel = 0.0055;
let carX = 0;
let isPlaying = false;
const keys = { Forward: false, Brake: false, Left: false, Right: false };
const handleKey = (e, isDown) => {
if (e.key === 'ArrowUp' || e.key === 'w' || e.key === 'W') keys.Forward = isDown;
if (e.key === 'ArrowDown' || e.key === 's' || e.key === 'S') keys.Brake = isDown;
if (e.key === 'ArrowLeft' || e.key === 'a' || e.key === 'A') keys.Left = isDown;
if (e.key === 'ArrowRight' || e.key === 'd' || e.key === 'D') keys.Right = isDown;
};
window.addEventListener('keydown', (e) => handleKey(e, true));
window.addEventListener('keyup', (e) => handleKey(e, false));
// --- СИСТЕМА ЧЕСТИЦ (ВЫХЛОПНОЙ ДЫМ КУБАМИ) ---
let particles = [];
function spawnExhaustSmoke() {
if(speed < 0.05) return;
const p = new THREE.Mesh(new THREE.BoxGeometry(0.12, 0.12, 0.12), new THREE.MeshLambertMaterial({color: 0x666677, transparent: true, opacity: 0.6}));
p.position.set(0.4, 0.2, car.position.z + 1.4);
scene.add(p);
particles.push({ mesh: p, vx: (Math.random()-0.5)*0.03, vy: Math.random()*0.02, life: 1.0 });
}
function updateParticles() {
for(let i = particles.length-1; i >= 0; i--) {
const p = particles[i];
p.mesh.position.x += p.vx;
p.mesh.position.y += p.vy;
p.mesh.position.z += speed * 0.5; // Слегка отстают от машины
p.life -= 0.04;
p.mesh.material.opacity = p.life;
if(p.life <= 0) {
scene.remove(p.mesh);
particles.splice(i, 1);
}
}
}
// --- ДЕТАЛИЗИРОВАННЫЙ СТРОГИЙ ДЕКОР И ТРАФИК ---
let traffic = [];
let segments = [];
let lastSegmentZ = 0;
const segmentLength = 12;
const maxSegments = 14;
const lanes = [-2.5, 0, 2.5];
function createSegment(z) {
const group = new THREE.Group();
// Полотно дороги (Стыкующиеся плиты)
const road = new THREE.Mesh(new THREE.BoxGeometry(8.6, 0.2, segmentLength), roadMat);
road.position.set(0, -0.1, z - segmentLength / 2);
group.add(road);
// Текстурированный газон
const grass = new THREE.Mesh(new THREE.BoxGeometry(40, 0.12, segmentLength), grassMat);
grass.position.set(0, -0.16, z - segmentLength / 2);
group.add(grass);
// Придорожные светящиеся неоновые столбики (для атмосферы ретро)
if (Math.abs(z) % 24 === 0) {
const beaconL = new THREE.Mesh(new THREE.BoxGeometry(0.15, 0.9, 0.15), beaconMat);
beaconL.position.set(-4.5, 0.45, z);
const beaconR = beaconL.clone(); beaconR.position.x = 4.5;
group.add(beaconL, beaconR);
}
// РАЗНООБРАЗНЫЙ ДЕКОР (Деревья и камни) по бокам трассы
const sideIdx = Math.random() > 0.5 ? 1 : -1;
const decorX = sideIdx * (6 + Math.random() * 6);
const decorZ = z - Math.random() * segmentLength;
if (Math.random() > 0.4) {
// Сложное воксельное дерево
const tree = new THREE.Group();
const trunk = new THREE.Mesh(new THREE.BoxGeometry(0.5, 2.5, 0.5), barkMat); trunk.position.y = 1.25;
// Крона из 3 пересекающихся детализированных блоков
const leaves1 = new THREE.Mesh(new THREE.BoxGeometry(2.4, 1.4, 2.4), leafMat); leaves1.position.y = 2.8;
const leaves2 = new THREE.Mesh(new THREE.BoxGeometry(1.8, 1.0, 1.8), leafMat); leaves2.position.y = 3.6;
tree.add(trunk, leaves1, leaves2);
tree.position.set(decorX, 0, decorZ);
group.add(tree);
} else if (Math.random() > 0.7) {
// Воксельные каменные валуны
const rock = new THREE.Mesh(new THREE.BoxGeometry(1.2 + Math.random(), 0.6 + Math.random(), 1.2), stoneMat);
rock.position.set(decorX, 0.3, decorZ);
rock.rotation.y = Math.random() * 2;
group.add(rock);
}
// Спавн трафика (Строго по полосам, редко, без наложений)
if (Math.abs(z) > 80 && Math.random() > 0.93) {
const targetLane = lanes[Math.floor(Math.random() * lanes.length)];
let laneClear = true;
traffic.forEach(t => { if(Math.abs(t.position.z - z) < 18 && t.userData.lane === targetLane) laneClear = false; });
if (laneClear) {
spawnTrafficCar(z - segmentLength / 2, targetLane);
}
}
scene.add(group);
segments.push({ z: z, mesh: group });
}
function spawnTrafficCar(z, laneX) {
const tCar = new THREE.Group();
// Трафик использует тот же материал кузова, но выглядит иначе архитектурно
const tBody = new THREE.Mesh(new THREE.BoxGeometry(1.4, 0.52, 2.6), roadMat); // Более темная палитра
tBody.position.y = 0.36;
tCar.add(tBody);
const tCabin = new THREE.Mesh(new THREE.BoxGeometry(1.0, 0.42, 1.1), new THREE.MeshLambertMaterial({color: 0x15151a}));
tCabin.position.set(0, 0.78, 0.1);
tCar.add(tCabin);
// Белые передние фары ботов
const lightL = new THREE.Mesh(new THREE.BoxGeometry(0.2, 0.1, 0.05), new THREE.MeshLambertMaterial({color:0xffffff, emissive:0xaaaaaa}));
lightL.position.set(-0.45, 0.45, 1.31);
const lightR = lightL.clone(); lightR.position.x = 0.45;
tCar.add(lightL, lightR);
tCar.position.set(laneX, 0, z);
tCar.userData = { speed: 0.05 + Math.random() * 0.04, lane: laneX };
scene.add(tCar);
traffic.push(tCar);
}
function updateWorld() {
while (lastSegmentZ > car.position.z - maxSegments * segmentLength) {
createSegment(lastSegmentZ);
lastSegmentZ -= segmentLength;
}
for (let i = segments.length - 1; i >= 0; i--) {
if (segments[i].z > car.position.z + 24) {
scene.remove(segments[i].mesh);
segments.splice(i, 1);
}
}
for (let i = traffic.length - 1; i >= 0; i--) {
const tCar = traffic[i];
tCar.position.z += tCar.userData.speed; // Плавное сближение
if (tCar.position.z > car.position.z + 24) {
scene.remove(tCar);
traffic.splice(i, 1);
}
}
}
// --- ГЛАВНЫЙ ИГРОВОЙ ЦИКЛ ---
function animate() {
requestAnimationFrame(animate);
if (isPlaying) {
// Физика разгона и торможения
if (keys.Forward) {
speed = Math.min(speed + accel, maxSpeed);
} else if (keys.Brake) {
speed = Math.max(0, speed - deccel * 1.8);
} else {
speed = Math.max(0, speed - deccel);
}
// Интерактивный неон стоп-сигналов при торможении
if(keys.Brake && speed > 0.01) {
neonBrakeMat.emissive.setHex(0xff0000);
} else {
neonBrakeMat.emissive.setHex(0x550000);
}
// Рулежка
if (keys.Left && speed > 0.02) carX -= 0.055;
if (keys.Right && speed > 0.02) carX += 0.055;
// Невидимые отбойники дороги
if (carX < -3.6) carX = -3.6;
if (carX > 3.6) carX = 3.6;
car.position.z -= speed;
car.position.x = carX;
// Анимация вращения колес
wheels.forEach(w => w.rotation.x -= speed * 1.5);
// Эффекты дыма и частиц
if(Math.random() > 0.4) spawnExhaustSmoke();
updateParticles();
// Обработка аварий (Выверенные хитбоксы блоков)
traffic.forEach(tCar => {
const dX = Math.abs(car.position.x - tCar.position.x);
const dZ = Math.abs(car.position.z - tCar.position.z);
if (dX < 1.35 && dZ < 2.5) {
gameOver();
}
});
updateWorld();
// Вывод читаемых данных в UI
document.getElementById('speed').innerText = Math.round(speed * 360);
document.getElementById('distance').innerText = Math.round(Math.abs(car.position.z));
}
// Плавное следование камеры (Идеальный угол обзора)
camera.position.set(car.position.x * 0.45, 3.0, car.position.z + 5.2);
camera.lookAt(car.position.x, 0.65, car.position.z - 3.5);
renderer.render(scene, camera);
}
// --- МЕНЕДЖМЕНТ ЭКРАНОВ ---
function startGame() {
document.getElementById('main-menu').style.display = 'none';
document.getElementById('ui').style.display = 'block';
isPlaying = true;
}
function gameOver() {
isPlaying = false;
document.getElementById('ui').style.display = 'none';
document.getElementById('final-score').innerText = `Счёт: ${Math.round(Math.abs(car.position.z))} очков`;
document.getElementById('game-over-screen').style.display = 'flex';
}
function restartGame() {
speed = 0; carX = 0;
car.position.set(0, 0, 0);
traffic.forEach(tCar => scene.remove(tCar));
traffic = [];
segments.forEach(s => scene.remove(s.mesh));
segments = [];
lastSegmentZ = 0;
document.getElementById('game-over-screen').style.display = 'none';
document.getElementById('ui').style.display = 'block';
isPlaying = true;
}
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
animate();
</script>
</body>
</html>