Ыбый лдь рдйййй ы
шшыыш
Большой лабиринт
Раскладка для телефона
Зеленые стены, желтоватый
Один выход
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
<title>Лабиринт 3D</title>
<style>
html,body{margin:0;overflow:hidden;background:#111;height:100%;font-family:sans-serif;touch-action:none}
canvas{display:block}
#pad{position:fixed;bottom:20px;left:20px;width:150px;height:150px;display:grid;
grid-template-columns:repeat(3,50px);grid-template-rows:repeat(3,50px);gap:0;opacity:.7}
#pad div{background:#fff3;border-radius:8px;display:flex;align-items:center;justify-content:center;
color:#fff;font-size:22px;user-select:none;margin:2px}
#pad div:active{background:#fff6}
#win{position:fixed;inset:0;display:none;align-items:center;justify-content:center;
color:#ffe;font-size:34px;background:#000a;text-align:center}
</style>
</head>
<body>
<canvas id="c"></canvas>
<div id="pad">
<div></div><div data-k="w">▲</div><div></div>
<div data-k="a">◀</div><div></div><div data-k="d">▶</div>
<div></div><div data-k="s">▼</div><div></div>
</div>
<div id="win">ВЫХОД!</div>
<script src="https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.min.js"></script>
<script>
// 1 = стена, 0 = проход, 2 = выход
const M = [
"111111111111111111111111",
"100000000000000000000001",
"101111111111111111111101",
"101000000000000000001101",
"101011111111111111101101",
"101010000000000000101101",
"101010111111111110101101",
"101010100000000010101101",
"101010101111111010101101",
"101010101000001010101101",
"101010101011101010101101",
"101010101010101010101101",
"101010101010101010101101",
"101010101010001010101101",
"101010101011111010101101",
"101010101000000010101101",
"101010101111111110101101",
"101010100000000000101101",
"101011111111111111101101",
"101000000000000000001101",
"101111111111111111111101",
"100000000000000000000002",
"111111111111111111111111"
];
const cols = M[0].length, rows = M.length;
const SIZE = 3;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x202028);
scene.fog = new THREE.Fog(0x202028, 10, 45);
const camera = new THREE.PerspectiveCamera(70, innerWidth/innerHeight, 0.1, 200);
const renderer = new THREE.WebGLRenderer({canvas:document.getElementById('c'),antialias:true});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio,2));
scene.add(new THREE.AmbientLight(0xffffff, 0.7));
const dl = new THREE.DirectionalLight(0xffffcc, 0.8);
dl.position.set(1,2,1); scene.add(dl);
// Пол
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(cols*SIZE, rows*SIZE),
new THREE.MeshLambertMaterial({color:0xeedd99})
);
floor.rotation.x = -Math.PI/2;
floor.position.set(cols*SIZE/2, 0, rows*SIZE/2);
scene.add(floor);
// Стены
const wallGeo = new THREE.BoxGeometry(SIZE, SIZE*1.2, SIZE);
const wallMat = new THREE.MeshLambertMaterial({color:0x33cc44});
const exitMat = new THREE.MeshLambertMaterial({color:0xffdd00, emissive:0x554400});
let exitPos = null;
for (let y=0;y<rows;y++) for (let x=0;x<cols;x++){
const ch = M[y][x];
if (ch==='1'){
const w = new THREE.Mesh(wallGeo, wallMat);
w.position.set(x*SIZE, SIZE*0.6, y*SIZE);
scene.add(w);
} else if (ch==='2'){
exitPos = new THREE.Vector3(x*SIZE, 0, y*SIZE);
const e = new THREE.Mesh(new THREE.CylinderGeometry(1.2,1.2,0.2,24), exitMat);
e.position.set(x*SIZE, 0.15, y*SIZE);
scene.add(e);
const light = new THREE.PointLight(0xffdd00, 2, 15);
light.position.set(x*SIZE, 2, y*SIZE);
scene.add(light);
}
}
// Игрок
const player = {x: SIZE*1.5, z: SIZE*1.5, r: 0.9};
const pos = new THREE.Vector3(player.x, 1.4, player.z);
const keys = {};
const dir = new THREE.Vector3();
function isFree(x, z){
const cx = Math.floor(x/SIZE), cz = Math.floor(z/SIZE);
const r = player.r;
for (let dy=-1; dy<=1; dy++) for (let dx=-1; dx<=1; dx++){
const nx = Math.floor((x+dx*r)/SIZE), nz = Math.floor((z+dy*r)/SIZE);
if (nz<0||nz>=rows||nx<0||nx>=cols) return false;
if (M[nz][nx]==='1') return false;
}
return true;
}
function move(ax, az){
const nx = player.x + ax, nz = player.z + az;
if (isFree(nx, player.z)) player.x = nx;
if (isFree(player.x, nz)) player.z = nz;
}
document.addEventListener('keydown', e=>keys[e.key.toLowerCase()]=true);
document.addEventListener('keyup', e=>keys[e.key.toLowerCase()]=false);
document.querySelectorAll('#pad div[data-k]').forEach(el=>{
const k = el.dataset.k;
const on = e=>{e.preventDefault();keys[k]=true;};
const off = e=>{e.preventDefault();keys[k]=false;};
el.addEventListener('touchstart',on); el.addEventListener('touchend',off);
el.addEventListener('mousedown',on); el.addEventListener('mouseup',off);
el.addEventListener('mouseleave',off);
});
function update(dt){
const speed = 6*dt;
let ax = 0, az = 0;
if (keys['w']||keys['ц']||keys['arrowup']) az -= 1;
if (keys['s']||keys['ы']||keys['arrowdown']) az += 1;
if (keys['a']||keys['ф']||keys['arrowleft']) ax -= 1;
if (keys['d']||keys['в']||keys['arrowright']) ax += 1;
if (ax||az){
const l = Math.hypot(ax,az);
move(ax/l*speed, az/l*speed);
}
// плавное следование камеры
pos.x += (player.x - pos.x)*0.15;
pos.z += (player.z - pos.z)*0.15;
camera.position.set(pos.x, 1.5, pos.z - 0.01);
const look = new THREE.Vector3(pos.x + 0, 1.3, pos.z - 1);
camera.lookAt(look);
camera.position.y = 1.5;
if (exitPos && Math.hypot(player.x-exitPos.x, player.z-exitPos.z) < 2){
document.getElementById('win').style.display='flex';
}
}
let last = performance.now();
function loop(t){
const dt = Math.min(0.05,(t-last)/1000); last = t;
update(dt);
renderer.render(scene, camera);
requestAnimationFrame(loop);
}
requestAnimationFrame(loop);
addEventListener('resize', ()=>{
camera.aspect = innerWidth/innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
</script>
</body>
</html>
```
Большой лабиринт 23×22, стены зелёные, пол желтоватый, один выход (жёлтый круг в правом нижнем углу). Камера от первого лица; на телефоне — экранный крестовик внизу слева, на ПК — WASD/стрелки. Дойди до светящегося выхода, появится «ВЫХОД!».
