릴스에서 본 레고 느낌 로드스터 달리기 게임이에요. 코드를 한 줄씩 짠 게 아니라 AI에게 말로 시켜서 만들었어요.
여기에 두 가지를 담았어요.
- 바로 해 보는 연습판: 맨 아래 「코드 전체」 한 장을 붙여 넣으면 바로 달려요.
- 처음부터 내가 만드는 법: 클로드에 그대로 붙여 넣는 첫 지시문과, 게임을 키워 가는 말들.
영상 속 게임은 Claude Code로 만든 뒤 여러 번 고쳐 가며 아이폰 앱으로 다듬은 판이에요. 여기 연습판은 같은 방식으로 따라 할 수 있게 파일 한 장으로 줄였어요.
1. 바로 해 보기
- 맨 아래 「5. 코드 전체」 상자를 통째로 복사해요.
- 둘 중 편한 길로 열어요.
- 클로드: 대화창에 붙여 넣고 「이 파일 그대로 아티팩트로 실행해 줘」라고 하면 바로 화면에 떠요.
- 컴퓨터: 메모장(맥은 텍스트 편집기)에 붙여 넣고
로드스터.html이라는 이름으로 저장 → 그 파일을 더블클릭하면 브라우저에서 열려요.
- 「달리기 시작」을 누르면 출발해요.
| 컴퓨터 | 폰 | |
|---|---|---|
| 차선 바꾸기 | ← → (또는 A · D) | ◀ ▶ 버튼 · 화면을 좌우로 밀기 |
| 점프(두 번까지) | 스페이스 · ↑ | 「점프」 버튼 · 화면 톡 |
- 트럭은 높아서 2단 점프로만 넘어가요.
- 「⚠ 바리케이드 접근!」이 뜨면 차선을 바꾸거나 뛰어넘어요.
- 부딪히면 차가 블록 조각으로 흩어지고 기록 카드가 떠요. 최고 기록은 그 브라우저에 남아요.
2. 처음부터 내가 만들기
클로드 대화창(또는 Claude Code)에 아래 지시문을 그대로 붙여 넣으세요. 차 색 · 배경 · 장애물은 마음대로 바꿔 적어도 돼요.
레고 블록 느낌의 3D 자동차 달리기 게임을 HTML 파일 한 장으로 만들어 줘.
- three.js 사용, 폰과 컴퓨터 브라우저에서 모두 돌아가게
- 내 차: 흰색 로드스터, 위에 레고 돌기가 있는 블록 모양
- 배경: 보라·분홍 노을 하늘, 줄무늬 해, 분홍 건물, 야자수, 빨강·흰 난간이 있는 4차선 도로
- 앞에서 블록 자동차·경찰차·트럭·바리케이드가 다가오고, 차선을 바꾸거나 점프해서 피함
- 점프는 공중에서 한 번 더 눌러 2단 점프까지
- 조작: 컴퓨터는 방향키·스페이스, 폰은 화면 아래 ◀ 점프 ▶ 버튼과 좌우 밀기
- 위에 달린 거리(m)·속도·최고 기록, 시간이 갈수록 빨라짐
- 부딪히면 차가 블록 조각으로 흩어지고 「다시 달리기」 카드
- 소리는 파일 없이 코드로(엔진 소리·점프·충돌)
- 화면 글자는 전부 한국어이렇게 키워 가요(한 번에 하나씩)
한 판 해 보고 마음에 안 드는 걸 한 줄씩 말하면 돼요. 영상 속 게임도 이렇게 키웠어요.
- 「장애물이 너무 늦게 와. 더 자주, 더 가까이에서 나오게 해 줘」
- 「바리케이드가 다가오면 화면 위에 '⚠ 바리케이드 접근!'을 띄워 줘」
- 「500m마다 '속도가 빨라져요' 알림을 띄워 줘」
- 「점프 게이지(공기 탱크)를 만들어서, 다 쓰면 잠깐 점프를 못 하게 해 줘」
- 「신스웨이브 배경 음악을 코드로 만들어서 켜고 끄는 버튼을 달아 줘」
- 「폰을 세로로 들었을 때 차가 너무 커. 카메라를 조금 뒤로 빼 줘」
화면이 하얗게 뜨거나 오류 글자가 보이면, 그 글자를 그대로 복사해서 「이 오류 고쳐 줘」라고 붙여 넣으면 돼요.
3. 내 폰에서 하기
- 가장 쉬운 길: 클로드 아티팩트 화면의 「Publish(게시)」를 누르면 주소가 생겨요. 그 주소를 폰에서 열고 공유 버튼 → 「홈 화면에 추가」를 누르면 앱처럼 아이콘이 생겨요. 게시한 주소는 아는 사람 누구나 열 수 있어요.
- 영상처럼 아이폰 앱으로: 맥 + Xcode(무료) + Claude Code가 필요해요. Claude Code에 「이 HTML 게임을 WKWebView로 띄우는 SwiftUI 아이폰 앱 프로젝트로 만들어 줘」라고 시키고, Xcode로 열어 내 아이폰을 연결한 뒤 실행해요. 무료 애플 계정으로 깐 앱은 7일마다 다시 설치해야 해요.
4. 알아 둘 것
- 연습판은 three.js를 인터넷에서 불러와요. 처음 열 때 인터넷이 연결돼 있어야 해요.
- 코드 맨 위 「바꿔 보기 좋은 숫자」(시작속도 · 최고속도 · 점프힘 · 점프횟수 · 내차색)를 바꾸면 느낌이 확 달라져요. 점프횟수를
3으로 바꾸면 3단 점프예요. - 실제 자동차 회사 이름 · 로고는 게임 안에 넣지 마세요. 혼자 즐기는 건 괜찮아도 남에게 공개하면 상표 문제가 생길 수 있어요. 그래서 연습판 이름도 「블록 로드스터」예요.
- 이런 걸 내 일에 맞는 도구로 직접 만드는 법, 원데이 클래스에서 하루 동안 옆에서 같이 해요. → 대니의 AI 원데이 클래스 보러 가기
5. 코드 전체
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>블록 로드스터</title>
<style>
html, body { margin: 0; height: 100%; overflow: hidden; background: #1a0b3d; font-family: -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif; touch-action: none; user-select: none; -webkit-user-select: none; }
canvas { display: block; }
#hud { position: fixed; top: 14px; left: 0; right: 0; text-align: center; color: #fff; pointer-events: none; text-shadow: 0 2px 6px rgba(0,0,0,.45); }
#dist { font-size: 44px; font-weight: 800; letter-spacing: -1px; }
#dist small { font-size: 20px; margin-left: 2px; }
#sub { font-size: 13px; opacity: .85; margin-top: 2px; }
#toast { position: fixed; top: 108px; left: 50%; transform: translateX(-50%); padding: 6px 14px; border-radius: 999px; background: rgba(255,255,255,.92); color: #e0245e; font-weight: 800; font-size: 15px; opacity: 0; transition: opacity .2s; pointer-events: none; white-space: nowrap; }
#pads { position: fixed; bottom: 22px; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: 0 22px; pointer-events: none; }
.pad { pointer-events: auto; width: 64px; height: 64px; border-radius: 50%; border: 2px solid rgba(255,255,255,.7); background: rgba(255,255,255,.18); color: #fff; font-size: 26px; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.pad.jump { width: 84px; height: 84px; font-size: 18px; background: rgba(255,255,255,.9); color: #3b1d8f; }
#sound { position: fixed; top: 16px; right: 16px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255,255,255,.2); color: #fff; font-size: 18px; }
#card { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(20,8,50,.35); }
#card .box { background: #fff; border-radius: 22px; padding: 24px 26px; width: min(80vw, 320px); text-align: center; box-shadow: 0 12px 40px rgba(0,0,0,.35); }
#card h1 { margin: 0; font-size: 15px; color: #e0245e; }
#card .big { font-size: 46px; font-weight: 800; color: #1a1033; margin: 6px 0 2px; }
#card .small { font-size: 13px; color: #6b6585; margin-bottom: 16px; line-height: 1.5; }
#card button { width: 100%; padding: 14px; border: 0; border-radius: 14px; background: #3b1d8f; color: #fff; font-size: 17px; font-weight: 800; }
.hide { display: none !important; }
</style>
</head>
<body>
<div id="hud"><div id="dist">0<small>m</small></div><div id="sub">0 km/h · 최고 0m</div></div>
<div id="toast"></div>
<button id="sound">🔊</button>
<div id="pads"><div class="pad" id="left">◀</div><div class="pad jump" id="jump">점프</div><div class="pad" id="right">▶</div></div>
<div id="card"><div class="box">
<h1 id="cardTitle">블록 로드스터</h1>
<div class="big" id="cardBig">🏁</div>
<div class="small" id="cardSmall">◀ ▶ 로 차선 바꾸기 · 점프는 두 번까지<br>컴퓨터: 방향키 · 스페이스 / 폰: 버튼 · 밀기 · 화면 톡</div>
<button id="startBtn">달리기 시작</button>
</div></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
// ===== 바꿔 보기 좋은 숫자 =====
const 시작속도 = 28; // 처음 속도
const 최고속도 = 70; // 점점 빨라지는 끝
const 점프힘 = 10; // 클수록 높이 뜀
const 점프횟수 = 2; // 2 = 2단 점프
const 내차색 = 0xf4f4f8; // 내 차 색(16진수)
const 차선 = [-4.5, -1.5, 1.5, 4.5];
// ===== 장면 · 카메라 =====
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xb44ab8, 60, 190);
const camera = new THREE.PerspectiveCamera(60, 1, 0.1, 400);
function resize() { renderer.setSize(innerWidth, innerHeight); camera.aspect = innerWidth / innerHeight; camera.fov = innerWidth < innerHeight ? 72 : 60; camera.updateProjectionMatrix(); }
addEventListener('resize', resize); resize();
// 하늘(보라 → 분홍) + 줄무늬 해
function canvasTex(w, h, draw) { const c = document.createElement('canvas'); c.width = w; c.height = h; draw(c.getContext('2d'), w, h); return new THREE.CanvasTexture(c); }
scene.background = canvasTex(2, 256, (g, w, h) => { const gr = g.createLinearGradient(0, 0, 0, h); gr.addColorStop(0, '#2a0f6b'); gr.addColorStop(0.55, '#7b2fbf'); gr.addColorStop(1, '#ff7ac8'); g.fillStyle = gr; g.fillRect(0, 0, w, h); });
const sunTex = canvasTex(256, 256, (g, w, h) => {
const gr = g.createLinearGradient(0, 0, 0, h); gr.addColorStop(0, '#fff3b0'); gr.addColorStop(1, '#ff5fa2');
g.fillStyle = gr; g.beginPath(); g.arc(w / 2, h / 2, w / 2, 0, Math.PI * 2); g.fill();
g.globalCompositeOperation = 'destination-out';
for (let i = 0; i < 7; i++) { const y = h * 0.55 + i * 16; g.fillRect(0, y, w, 3 + i * 1.4); }
});
const sun = new THREE.Mesh(new THREE.PlaneGeometry(90, 90), new THREE.MeshBasicMaterial({ map: sunTex, transparent: true, fog: false }));
sun.position.set(0, 26, -260); scene.add(sun);
scene.add(new THREE.HemisphereLight(0xffd6f5, 0x3a1670, 0.9));
const light = new THREE.DirectionalLight(0xffffff, 0.8); light.position.set(-6, 14, 8); scene.add(light);
// 블록(레고) 부품: 상자 + 위에 동그란 돌기
const box = new THREE.BoxGeometry(1, 1, 1);
const stud = new THREE.CylinderGeometry(0.16, 0.16, 0.14, 12);
const mats = {};
function mat(c) { return mats[c] || (mats[c] = new THREE.MeshLambertMaterial({ color: c })); }
function brick(group, c, w, h, d, x, y, z, studs) {
const m = new THREE.Mesh(box, mat(c)); m.scale.set(w, h, d); m.position.set(x, y, z); group.add(m);
if (studs) for (let i = -w / 2 + 0.3; i < w / 2; i += 0.6) for (let k = -d / 2 + 0.3; k < d / 2; k += 0.6) { const s = new THREE.Mesh(stud, mat(c)); s.position.set(x + i, y + h / 2 + 0.07, z + k); group.add(s); }
return m;
}
function wheels(g, len) { for (const sx of [-0.85, 0.85]) for (const sz of [-len * 0.32, len * 0.32]) brick(g, 0x15151c, 0.3, 0.6, 0.6, sx, 0.3, sz); }
function makeRoadster() {
const g = new THREE.Group();
brick(g, 내차색, 1.8, 0.5, 3.6, 0, 0.55, 0, false);
brick(g, 0x111122, 1.5, 0.45, 1.3, 0, 1.02, 0.25, true);
brick(g, 0xff3355, 1.7, 0.15, 0.2, 0, 0.7, 1.82, false); // 뒤 미등
brick(g, 0xfff2a8, 1.5, 0.15, 0.15, 0, 0.62, -1.82, false); // 앞 등
wheels(g, 3.6); return g;
}
function makeCar(kind) {
const g = new THREE.Group();
const colors = [0xffc93c, 0x2ecc71, 0x2d6cff, 0xff4fa3, 0x9b5cff, 0xff7a2f];
if (kind === 'truck') {
brick(g, 0xeeeeee, 2.0, 2.2, 4.2, 0, 1.45, 0.5, true);
brick(g, colors[(Math.random() * colors.length) | 0], 2.0, 1.3, 1.5, 0, 1.0, -2.3, true);
wheels(g, 5.5); g.userData = { h: 2.6, len: 5.8, kind };
} else if (kind === 'police') {
brick(g, 0xffffff, 1.8, 0.6, 3.4, 0, 0.6, 0, false);
brick(g, 0x15151c, 1.5, 0.5, 1.4, 0, 1.1, 0.1, false);
g.userData = { h: 1.6, len: 3.6, kind, lights: [brick(g, 0xff2244, 0.6, 0.2, 0.3, -0.35, 1.45, 0.1, false), brick(g, 0x2266ff, 0.6, 0.2, 0.3, 0.35, 1.45, 0.1, false)] };
wheels(g, 3.4);
} else if (kind === 'barricade') {
for (let i = 0; i < 5; i++) brick(g, i % 2 ? 0xffffff : 0xff3344, 0.56, 0.5, 0.4, -1.1 + i * 0.55, 0.75, 0, false);
brick(g, 0x333333, 0.15, 0.5, 0.15, -1.1, 0.25, 0, false); brick(g, 0x333333, 0.15, 0.5, 0.15, 1.1, 0.25, 0, false);
g.userData = { h: 1.05, len: 0.6, kind };
} else {
brick(g, colors[(Math.random() * colors.length) | 0], 1.8, 0.65, 3.4, 0, 0.62, 0, true);
brick(g, 0x1b1b2a, 1.5, 0.45, 1.4, 0, 1.15, 0.2, false);
wheels(g, 3.4); g.userData = { h: 1.45, len: 3.6, kind: 'car' };
}
return g;
}
// 도로 · 난간 · 풍경
const road = new THREE.Mesh(new THREE.PlaneGeometry(14, 600), mat(0x3c2f5c)); road.rotation.x = -Math.PI / 2; road.position.z = -250; scene.add(road);
const ground = new THREE.Mesh(new THREE.PlaneGeometry(400, 600), mat(0x5a1f86)); ground.rotation.x = -Math.PI / 2; ground.position.set(0, -0.05, -250); scene.add(ground);
const movers = []; // 끝없이 되돌아오는 것들(줄 · 난간 · 건물 · 야자수)
function addLoop(obj, z) { obj.position.z = z; scene.add(obj); movers.push(obj); }
for (let z = 0; z > -240; z -= 8) for (const x of [-3, 0, 3]) { const d = new THREE.Mesh(box, mat(0xffffff)); d.scale.set(0.15, 0.02, 3); d.position.x = x; addLoop(d, z); }
for (let z = 0; z > -240; z -= 2) for (const x of [-7.2, 7.2]) { const r = new THREE.Mesh(box, mat((z / 2) % 2 ? 0xffffff : 0xff3b5c)); r.scale.set(0.5, 0.9, 2); r.position.set(x, 0.45, 0); addLoop(r, z); }
for (let z = 0; z > -240; z -= 12) for (const side of [-1, 1]) {
const b = new THREE.Mesh(box, mat([0xff7ad9, 0xd15cff, 0xff9ee6][(Math.random() * 3) | 0]));
const h = 8 + Math.random() * 22; b.scale.set(8 + Math.random() * 6, h, 8); b.position.set(side * (30 + Math.random() * 14), h / 2, 0); addLoop(b, z);
const p = new THREE.Group(); brick(p, 0x7a4a2a, 0.4, 5, 0.4, 0, 2.5, 0, false);
for (let a = 0; a < 5; a++) { const leaf = brick(p, 0x1fbf8f, 2.6, 0.18, 0.6, 0, 5, 0, false); leaf.rotation.y = a * 1.26; leaf.rotation.z = 0.25; leaf.position.set(Math.cos(a * 1.26) * 0.9, 4.9, -Math.sin(a * 1.26) * 0.9); }
p.position.x = side * 10; addLoop(p, z - 6);
}
// ===== 상태 =====
const player = makeRoadster(); scene.add(player);
let lane = 1, speed = 시작속도, dist = 0, vy = 0, jumpsLeft = 점프횟수, playing = false, crashed = false;
let best = +(localStorage.getItem('roadsterBest') || 0), spawnTimer = 0, warned = null;
const obstacles = [], debris = [];
const $ = (id) => document.getElementById(id);
// ===== 소리(파일 없이 코드로 냄) =====
let ac = null, motor = null, soundOn = true;
function ensureAudio() {
if (ac) return; ac = new (window.AudioContext || window.webkitAudioContext)();
const o = ac.createOscillator(), f = ac.createBiquadFilter(), gn = ac.createGain();
o.type = 'sawtooth'; f.type = 'lowpass'; f.frequency.value = 500; gn.gain.value = 0;
o.connect(f); f.connect(gn); gn.connect(ac.destination); o.start(); motor = { o, gn };
}
function beep(freq, len, type = 'square', vol = 0.12) {
if (!ac || !soundOn) return; const o = ac.createOscillator(), g = ac.createGain();
o.type = type; o.frequency.setValueAtTime(freq, ac.currentTime); o.frequency.exponentialRampToValueAtTime(freq * 1.8, ac.currentTime + len);
g.gain.setValueAtTime(vol, ac.currentTime); g.gain.exponentialRampToValueAtTime(0.001, ac.currentTime + len);
o.connect(g); g.connect(ac.destination); o.start(); o.stop(ac.currentTime + len);
}
$('sound').onclick = (e) => { e.stopPropagation(); soundOn = !soundOn; $('sound').textContent = soundOn ? '🔊' : '🔇'; };
// ===== 조작 =====
function move(d) { if (playing) lane = Math.max(0, Math.min(차선.length - 1, lane + d)); }
function jump() {
if (!playing || jumpsLeft <= 0) return;
vy = 점프힘; jumpsLeft--; beep(jumpsLeft === 점프횟수 - 1 ? 420 : 620, 0.18);
if (jumpsLeft < 점프횟수 - 1) toast(`${점프횟수 - jumpsLeft}단 점프!`);
}
addEventListener('keydown', (e) => {
if (e.key === 'ArrowLeft' || e.key === 'a') move(-1);
if (e.key === 'ArrowRight' || e.key === 'd') move(1);
if (e.key === ' ' || e.key === 'ArrowUp' || e.key === 'w') { e.preventDefault(); playing ? jump() : start(); }
});
for (const [id, fn] of [['left', () => move(-1)], ['right', () => move(1)], ['jump', jump]]) $(id).addEventListener('pointerdown', (e) => { e.stopPropagation(); fn(); });
let tx = null, ty = null;
renderer.domElement.addEventListener('pointerdown', (e) => { tx = e.clientX; ty = e.clientY; });
renderer.domElement.addEventListener('pointerup', (e) => {
if (tx === null) return; const dx = e.clientX - tx, dy = e.clientY - ty; tx = null;
if (Math.abs(dx) > 30 && Math.abs(dx) > Math.abs(dy)) move(dx > 0 ? 1 : -1); else jump();
});
let toastT = 0;
function toast(t) { $('toast').textContent = t; $('toast').style.opacity = 1; toastT = 0.9; }
function start() {
ensureAudio(); if (ac.state === 'suspended') ac.resume();
for (const o of obstacles) scene.remove(o); obstacles.length = 0;
for (const d of debris) scene.remove(d); debris.length = 0;
lane = 1; speed = 시작속도; dist = 0; vy = 0; jumpsLeft = 점프횟수; spawnTimer = 0.5; warned = null;
player.visible = true; player.position.set(차선[lane], 0, 0); player.rotation.set(0, 0, 0);
crashed = false; playing = true; $('card').classList.add('hide');
}
$('startBtn').onclick = start;
function spawn() {
// 한 줄에 장애물 1~2개 · 빈 차선 하나는 꼭 남김
const free = (Math.random() * 차선.length) | 0;
const count = Math.random() < 0.45 ? 2 : 1;
const lanes = 차선.map((_, i) => i).filter((i) => i !== free).sort(() => Math.random() - 0.5).slice(0, count);
for (const li of lanes) {
const r = Math.random();
const kind = r < 0.15 ? 'barricade' : r < 0.3 ? 'police' : r < 0.45 ? 'truck' : 'car';
const o = makeCar(kind); o.position.set(차선[li], 0, -130 - Math.random() * 10);
o.userData.own = kind === 'barricade' ? 0 : 0.15 + Math.random() * 0.15; // 같은 방향으로 달리는 속도(내 속도 대비)
scene.add(o); obstacles.push(o);
}
}
function crash() {
playing = false; crashed = true; beep(90, 0.6, 'sawtooth', 0.25); $('toast').style.opacity = 0;
player.visible = false;
for (let i = 0; i < 26; i++) {
const d = new THREE.Mesh(box, mat(i % 3 ? 내차색 : 0x111122)); d.scale.set(0.5, 0.35, 0.5);
d.position.copy(player.position).add(new THREE.Vector3((Math.random() - 0.5) * 1.6, 0.6 + Math.random(), (Math.random() - 0.5) * 3));
d.userData.v = new THREE.Vector3((Math.random() - 0.5) * 10, 4 + Math.random() * 8, (Math.random() - 0.3) * 10);
scene.add(d); debris.push(d);
}
const m = Math.floor(dist); if (m > best) { best = m; localStorage.setItem('roadsterBest', best); }
setTimeout(() => {
$('cardTitle').textContent = '꽝! 충돌'; $('cardBig').textContent = m.toLocaleString() + 'm';
$('cardSmall').textContent = `최고 기록 ${best.toLocaleString()}m`; $('startBtn').textContent = '다시 달리기';
$('card').classList.remove('hide');
}, 900);
}
// ===== 매 프레임 =====
const clock = new THREE.Clock();
function tick() {
const dt = Math.min(clock.getDelta(), 0.05);
if (playing) {
speed = Math.min(최고속도, speed + dt * 0.9);
dist += speed * dt * 0.5;
// 차선 이동 · 점프
player.position.x += (차선[lane] - player.position.x) * Math.min(1, dt * 12);
player.rotation.z = (player.position.x - 차선[lane]) * 0.06;
vy -= 28 * dt; player.position.y = Math.max(0, player.position.y + vy * dt);
if (player.position.y === 0) { vy = 0; jumpsLeft = 점프횟수; }
player.rotation.x = player.position.y > 0 ? -0.08 : 0;
// 장애물
spawnTimer -= dt; if (spawnTimer <= 0) { spawn(); spawnTimer = Math.max(0.45, 1.25 - speed / 120); }
warned = null;
for (let i = obstacles.length - 1; i >= 0; i--) {
const o = obstacles[i], u = o.userData;
o.position.z += speed * (1 - u.own) * dt;
if (u.lights) { const on = Math.floor(performance.now() / 150) % 2; u.lights[0].material = mat(on ? 0xff2244 : 0x551122); u.lights[1].material = mat(on ? 0x112255 : 0x2266ff); }
if (u.kind === 'barricade' && o.position.z > -60 && o.position.z < -8) warned = '⚠ 바리케이드 접근!';
if (o.position.z > 20) { scene.remove(o); obstacles.splice(i, 1); continue; }
const hitX = Math.abs(o.position.x - player.position.x) < (u.kind === 'barricade' ? 1.9 : 1.6);
const hitZ = Math.abs(o.position.z - player.position.z) < (u.len + 3.4) / 2;
if (hitX && hitZ && player.position.y < u.h - 0.15) { crash(); break; }
}
if (warned && toastT <= 0) { $('toast').textContent = warned; $('toast').style.opacity = 1; } else if (!warned && toastT <= 0) $('toast').style.opacity = 0;
for (const m of movers) { m.position.z += speed * dt; if (m.position.z > 12) m.position.z -= 240; }
$('dist').innerHTML = Math.floor(dist).toLocaleString() + '<small>m</small>';
$('sub').textContent = `${Math.round(speed * 3.2)} km/h · 최고 ${Math.max(best, Math.floor(dist)).toLocaleString()}m`;
}
if (toastT > 0) { toastT -= dt; if (toastT <= 0) $('toast').style.opacity = 0; }
for (const d of debris) { d.userData.v.y -= 20 * dt; d.position.addScaledVector(d.userData.v, dt); if (d.position.y < 0.17) { d.position.y = 0.17; d.userData.v.multiplyScalar(0.5); d.userData.v.y *= -0.4; } d.rotation.x += dt * 4; d.rotation.y += dt * 3; }
if (motor) motor.gn.gain.setTargetAtTime(playing && soundOn ? 0.05 : 0, ac.currentTime, 0.1), motor.o.frequency.setTargetAtTime(40 + speed * 1.6, ac.currentTime, 0.2);
camera.position.set(player.position.x * 0.6, (innerWidth < innerHeight ? 5 : 4.2) + player.position.y * 0.4, innerWidth < innerHeight ? 10.5 : 8.5);
camera.lookAt(player.position.x * 0.8, 1.2, -12);
renderer.render(scene, camera);
requestAnimationFrame(tick);
}
player.position.set(차선[lane], 0, 0);
tick();
</script>
</body>
</html>


