<!doctype html>
<html lang="id">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<meta name="theme-color" content="#090d12">
<title>Drag Bike Indonesia 3D — Prototype</title>
<style>
:root{--red:#ff3038;--bg:#090d12;--panel:#151d27;--muted:#9eabb9}
*{box-sizing:border-box;touch-action:manipulation}
html,body{margin:0;width:100%;height:100%;overflow:hidden;background:var(--bg);color:#fff;font-family:system-ui,Arial,sans-serif}
#game{position:fixed;inset:0;width:100%;height:100%;display:block;background:#111}
.hud{position:fixed;inset:0;pointer-events:none;padding:12px;display:flex;flex-direction:column;justify-content:space-between}
.top{display:flex;justify-content:space-between;gap:8px;align-items:flex-start}
.panel{background:#0a1019d9;border:1px solid #ffffff24;border-radius:12px;padding:9px 12px;backdrop-filter:blur(5px);box-shadow:0 4px 18px #0006}
.brand{font-weight:900;letter-spacing:1px;font-size:13px}.brand span{color:var(--red)}
.small{font-size:10px;color:var(--muted);letter-spacing:.8px}
.stats{display:flex;gap:7px;flex-wrap:wrap;justify-content:flex-end}
.stat{text-align:center;min-width:58px}.value{font-size:20px;font-weight:900;font-variant-numeric:tabular-nums}.unit{font-size:9px;color:var(--muted)}
.middle{display:flex;justify-content:space-between;align-items:center;margin-top:auto;margin-bottom:auto}
.center-msg{text-align:center;margin:auto;text-shadow:0 3px 12px #000;font-weight:900;font-size:clamp(28px,8vw,54px);letter-spacing:2px}
.bottom{display:flex;justify-content:space-between;align-items:flex-end;gap:10px}
.controls{display:flex;gap:9px;align-items:flex-end;pointer-events:auto}
button{border:1px solid #ffffff35;color:#fff;background:#182331eF;border-radius:15px;font-weight:900;min-width:66px;height:66px;padding:8px;box-shadow:0 5px 0 #05080c;user-select:none;-webkit-user-select:none}
button:active,button.active{transform:translateY(3px);box-shadow:0 2px 0 #05080c;background:#a91d28}
button.gas{background:linear-gradient(145deg,#fa4249,#9c111c);width:86px;height:86px;font-size:14px}
button.shift{background:linear-gradient(145deg,#e8a52a,#88500b);height:76px}
button.brake{height:60px}
button.menu{height:42px;min-width:74px;font-size:11px}
#toast{position:fixed;left:50%;top:48%;transform:translate(-50%,-50%);font-size:46px;font-weight:1000;text-shadow:0 4px 15px #000;pointer-events:none}
#result{display:none;position:fixed;inset:0;background:#05080deF;z-index:5;align-items:center;justify-content:center;padding:20px}
.card{width:min(440px,100%);background:#151e29;border:1px solid #ffffff28;border-radius:20px;padding:22px;text-align:center}
.card h1{margin:0 0 5px;font-size:26px}.card p{color:var(--muted)}
.resultgrid{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin:18px 0}
.resultgrid div{background:#0a111a;border-radius:12px;padding:12px}
.resultgrid strong{display:block;font-size:23px}
#startscreen{position:fixed;inset:0;z-index:4;display:flex;align-items:center;justify-content:center;padding:20px;background:linear-gradient(#060a10a8,#060a10ed)}
.startcard{width:min(460px,100%);background:#111a25;border:1px solid #ffffff26;border-radius:20px;padding:22px}
.startcard h1{font-size:clamp(25px,7vw,36px);line-height:1.05;margin:0 0 8px}.startcard h1 em{color:var(--red);font-style:normal}
.startcard p{color:#b5c0cb;font-size:13px;line-height:1.5}
.specs{display:flex;gap:8px;flex-wrap:wrap;margin:14px 0}.chip{font-size:11px;border:1px solid #ffffff25;border-radius:20px;padding:6px 9px;color:#dce4eb}
.primary{width:100%;height:54px;background:linear-gradient(90deg,#ff3942,#a30f1a);font-size:15px;margin-top:8px}
.note{font-size:10px!important;color:#8997a5!important}
@media(max-width:380px){.panel{padding:7px 9px}.value{font-size:17px}button{min-width:57px;height:59px}.gas{width:76px!important;height:78px!important}}
</style>
</head>
<body>
<canvas id="game"></canvas>
<div class="hud">
<div class="top">
<div class="panel"><div class="brand">DRAG BIKE <span>INDONESIA</span></div><div class="small">PROTOTYPE 0.1 • 201 METER</div></div>
<div class="stats">
<div class="panel stat"><div class="value" id="speed">0</div><div class="unit">KM/JAM</div></div>
<div class="panel stat"><div class="value" id="rpm">1.5</div><div class="unit">RPM × 1000</div></div>
<div class="panel stat"><div class="value" id="gear">1</div><div class="unit">GIGI</div></div>
<div class="panel stat"><div class="value" id="dist">0</div><div class="unit">METER</div></div>
</div>
</div>
<div class="middle"><div class="center-msg" id="message"></div></div>
<div class="bottom">
<div class="controls">
<button class="brake" id="brake">REM<br>▼</button>
<button class="menu" id="reset">ULANG</button>
</div>
<div class="controls">
<button class="shift" id="shift">OPER<br>GIGI ▲</button>
<button class="gas" id="gas">GAS<br>TAHAN</button>
</div>
</div>
</div>
<div id="toast"></div>
<div id="startscreen">
<div class="startcard">
<div class="small">MOBILE DRAG RACING SIMULATOR</div>
<h1>DRAG BIKE<br><em>INDONESIA 3D</em></h1>
<p>Prototype balap drag 201 meter dengan perspektif jalan 3D, kontrol sentuh, perpindahan gigi semi-otomatis, RPM, kecepatan, dan catatan waktu.</p>
<div class="specs"><span class="chip">Kelas: Bebas</span><span class="chip">Lintasan: 201 m</span><span class="chip">Kontrol: Semi otomatis</span></div>
<button class="primary" id="start">MULAI BALAP</button>
<p class="note">Versi awal memakai grafis perspektif 2.5D ringan agar dapat berjalan di HP Android RAM 4 GB. Belum merupakan APK native atau simulasi 3D penuh.</p>
</div>
</div>
<div id="result"><div class="card">
<div class="small">HASIL BALAP</div><h1 id="resultTitle">FINISH!</h1><p id="resultSub">Catatan waktu kamu</p>
<div class="resultgrid">
<div><span class="small">WAKTU</span><strong id="timeOut">0.00 s</strong></div>
<div><span class="small">KECEPATAN AKHIR</span><strong id="speedOut">0 km/j</strong></div>
<div><span class="small">RPM PUNCAK</span><strong id="rpmOut">0</strong></div>
<div><span class="small">BEST TIME</span><strong id="bestOut">—</strong></div>
</div>
<button class="primary" id="again">BALAP LAGI</button>
</div></div>
<script>
(()=>{
const canvas=document.getElementById('game'),ctx=canvas.getContext('2d');
let W=0,H=0,dpr=1;
function resize(){dpr=Math.min(devicePixelRatio||1,1.5);W=innerWidth;H=innerHeight;canvas.width=W*dpr;canvas.height=H*dpr;ctx.setTransform(dpr,0,0,dpr,0,0)}
addEventListener('resize',resize);resize();
const $=id=>document.getElementById(id);
let state='ready',speed=0,rpm=1500,gear=1,distance=0,elapsed=0,peak=0,finishSpeed=0,gas=false,brake=false,last=0,countdown=0,runTime=0,shiftLock=0,best=Number(localStorage.getItem('dbi_best')||0);
const ratios=[0,2.75,1.85,1.40,1.12,0.94,0.82],finalDrive=3.2,redline=10500;
function reset(){state='ready';speed=0;rpm=1500;gear=1;distance=0;elapsed=0;peak=0;finishSpeed=0;gas=false;brake=false;countdown=0;runTime=0;shiftLock=0;$('result').style.display='none';$('startscreen').style.display='flex';$('message').textContent='';$('toast').textContent='';updateHud()}
function start(){ $('startscreen').style.display='none';state='count';countdown=3;runTime=0;last=performance.now();$('message').textContent='3';}
function updateHud(){$('speed').textContent=Math.round(speed);$('rpm').textContent=(rpm/1000).toFixed(1);$('gear').textContent=gear;$('dist').textContent=Math.min(201,Math.floor(distance))}
function shift(){if(state!=='race'||shiftLock>0)return;if(gear<6){gear++;shiftLock=.22;rpm=Math.max(2200,rpm*.68)}}
function finish(){state='finished';finishSpeed=speed;let t=elapsed.toFixed(2);if(!best||elapsed<best){best=elapsed;localStorage.setItem('dbi_best',best)}$('timeOut').textContent=t+' s';$('speedOut').textContent=Math.round(finishSpeed)+' km/j';$('rpmOut').textContent=Math.round(peak);$('bestOut').textContent=best.toFixed(2)+' s';$('resultTitle').textContent='FINISH!';$('resultSub').textContent='201 meter berhasil ditempuh';$('result').style.display='flex';$('message').textContent='';}
function physics(dt){
if(state==='count'){countdown-=dt;if(countdown<=0){state='race';$('message').textContent='GO!';setTimeout(()=>{if(state==='race')$('message').textContent=''},500)}else $('message').textContent=Math.ceil(countdown);return}
if(state!=='race')return;
elapsed+=dt;shiftLock=Math.max(0,shiftLock-dt);
const wheelRPM=speed/3.6/(Math.PI*.29)*60;
const target= speed<2 ? (gas?5200:1500) : wheelRPM*ratios[gear]*finalDrive;
const throttle=gas?1:0;
rpm += (Math.max(1300,Math.min(redline+500,target+(throttle*800)))-rpm)*Math.min(1,dt*5);
if(rpm>redline){rpm=redline+(rpm-redline)*.15}
const band=Math.max(.25,1-Math.abs(rpm-7800)/8500);
const torque=throttle*(gear===1?3.9:3.25)*band;
let accel=torque*2.25/(1+speed/90);
if(!gas)accel-=.8+speed*.012;
if(brake)accel-=8;
if(rpm>redline)accel-=5;
// Semi-automatic shift assistance: shift up near limiter if the player holds throttle.
if(gas&&rpm>10000&&gear<6&&shiftLock<=0)shift();
speed=Math.max(0,Math.min(190,speed+accel*dt));
distance+=speed/3.6*dt;
peak=Math.max(peak,rpm);
if(distance>=201){distance=201;finish()}
updateHud();
}
function polygon(points,fill,stroke){ctx.beginPath();points.forEach((p,i)=>i?ctx.lineTo(p[0],p[1]):ctx.moveTo(p[0],p[1]));ctx.closePath();ctx.fillStyle=fill;ctx.fill();if(stroke){ctx.strokeStyle=stroke;ctx.stroke()}}
function drawBike(x,y,s){
ctx.save();ctx.translate(x,y);ctx.scale(s,s);
// wheels
ctx.fillStyle='#080b0f';ctx.beginPath();ctx.ellipse(-24,0,9,24,-.12,0,Math.PI*2);ctx.fill();ctx.beginPath();ctx.ellipse(28,-1,9,24,.12,0,Math.PI*2);ctx.fill();
ctx.strokeStyle='#9ca7b2';ctx.lineWidth=2;ctx.beginPath();ctx.moveTo(-24,-18);ctx.lineTo(-24,18);ctx.moveTo(28,-18);ctx.lineTo(28,18);ctx.stroke();
// rear frame, engine and body
polygon([[-32,-15],[-20,-30],[8,-31],[29,-18],[23,-9],[-16,-7]],'#d51d2b','#ff6971');
polygon([[-17,-31],[-8,-42],[12,-40],[22,-29],[5,-25]],'#171f2a','#6f7d8b');
polygon([[-10,-10],[-4,-26],[13,-26],[20,-10],[7,-4]],'#b7c1ca','#333');
polygon([[-9,-29],[-1,-44],[10,-45],[18,-30]],'#e8e9eb');
// rider
ctx.strokeStyle='#101820';ctx.lineWidth=9;ctx.lineCap='round';
ctx.beginPath();ctx.moveTo(0,-39);ctx.lineTo(-10,-53);ctx.lineTo(-24,-48);ctx.moveTo(-10,-53);ctx.lineTo(8,-57);ctx.stroke();
ctx.fillStyle='#f1f3f5';ctx.beginPath();ctx.arc(2,-62,9,0,Math.PI*2);ctx.fill();ctx.fillStyle='#cf1d2a';ctx.fillRect(-5,-65,14,5);
ctx.restore();
}
function draw(){
ctx.clearRect(0,0,W,H);
const horizon=H*.36,vanX=W*.5,roadBottom=H*1.08,roadTop=W*.11;
const sky=ctx.createLinearGradient(0,0,0,horizon);sky.addColorStop(0,'#101d2c');sky.addColorStop(1,'#66727b');ctx.fillStyle=sky;ctx.fillRect(0,0,W,H);
// distant silhouettes and trackside lights
ctx.fillStyle='#17232a';for(let i=0;i<15;i++){let x=i*W/12-W*.1;let hh=25+(i*17%65);ctx.fillRect(x,horizon-hh,Math.max(10,W/18),hh)}
// ground
ctx.fillStyle='#27312f';ctx.fillRect(0,horizon,W,H-horizon);
// road perspective
polygon([[vanX-roadTop,horizon],[vanX+roadTop,horizon],[W*.96,roadBottom],[W*.04,roadBottom]],'#242a30');
polygon([[vanX-roadTop-5,horizon],[vanX-roadTop,horizon],[W*.04,roadBottom],[0,roadBottom]],'#c9c7b7');
polygon([[vanX+roadTop,horizon],[vanX+roadTop+5,horizon],[W,roadBottom],[W*.96,roadBottom]],'#c9c7b7');
// lane dashes animate with distance
const phase=(distance*1.6)%1;
for(let i=0;i<12;i++){let z=(i/12+phase/12);let p=z*z;let y=horizon+p*(roadBottom-horizon);let half=roadTop+p*(W*.46-roadTop);let dashW=2+p*8;let dashH=2+p*26;ctx.fillStyle='#e6e4d7';ctx.fillRect(vanX-dashW/2,y,dashW,dashH)}
// side barriers
for(let side of [-1,1]){for(let i=0;i<18;i++){let z=((i/18+(distance*.006)%1)%1);let p=z*z;let y=horizon+p*(roadBottom-horizon);let x=vanX+side*(roadTop+p*(W*.49-roadTop));ctx.fillStyle=i%2?'#d9dce0':'#c52a32';ctx.fillRect(x-4-p*9,y,8+p*18,3+p*8)}}
// finish banner
let remain=201-distance;if(remain<55&&state==='race'){let k=Math.max(.1,1-remain/65);ctx.fillStyle='#fff';ctx.fillRect(W*.28,horizon+30*k,W*.44,4*k);ctx.fillStyle='#e21f2c';ctx.font=`bold ${Math.max(9,14*k)}px sans-serif`;ctx.textAlign='center';ctx.fillText('FINISH',W/2,horizon+23*k)}
// bike
let bounce=state==='race'&&gas?Math.sin(performance.now()*.025)*2:0;
drawBike(W*.5,H*.79+bounce,Math.min(1.25,Math.max(.8,W/390)));
// vignette
const vg=ctx.createRadialGradient(W/2,H/2,H*.1,W/2,H/2,H*.8);vg.addColorStop(0,'#0000');vg.addColorStop(1,'#0007');ctx.fillStyle=vg;ctx.fillRect(0,0,W,H);
}
function loop(ts){let dt=Math.min(.04,(ts-last)/1000||0);last=ts;physics(dt);draw();requestAnimationFrame(loop)}
requestAnimationFrame(loop);
function bindHold(id,set){const b=$(id);const on=e=>{e.preventDefault();set(true);b.classList.add('active')};const off=e=>{e.preventDefault();set(false);b.classList.remove('active')};b.addEventListener('pointerdown',on);['pointerup','pointercancel','pointerleave'].forEach(ev=>b.addEventListener(ev,off))}
bindHold('gas',v=>gas=v);bindHold('brake',v=>brake=v);
$('shift').addEventListener('pointerdown',e=>{e.preventDefault();shift()});
$('start').onclick=start;$('again').onclick=reset;$('reset').onclick=reset;
document.addEventListener('keydown',e=>{if(e.code==='ArrowUp'||e.code==='Space')gas=true;if(e.code==='ArrowDown')brake=true;if(e.code==='ArrowRight'||e.code==='KeyE')shift();if(e.code==='Enter'&&state==='ready')start()});
document.addEventListener('keyup',e=>{if(e.code==='ArrowUp'||e.code==='Space')gas=false;if(e.code==='ArrowDown')brake=false});
updateHud();
})();
</script>
</body>
</html>1
1
14KB
14KB
189.0ms
308.0ms
190.0ms