Meta Description" name="description" />
<!doctype html>
<html lang="hi"><meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
<title>Road Rush</title>
<style>
html,body{margin:0;height:100%;overflow:hidden;background:#222;font-family:Arial;touch-action:none}
canvas{width:100%;height:100%;display:block}
#score{position:fixed;top:12px;left:14px;color:#fff;font-size:22px;font-weight:bold;text-shadow:0 2px 3px #000}
#go{display:none;position:fixed;inset:0;background:#0009;color:#fff;align-items:center;justify-content:center;flex-direction:column}
button{font-size:20px;padding:13px 25px;border:0;border-radius:12px}
#left,#right{position:fixed;bottom:18px;width:95px;height:58px;opacity:.8}
#left{left:20px}#right{right:20px}
</style>
<canvas id=c></canvas><div id=score>Score: 0</div>
<div id=go><h1>GAME OVER</h1><p id=f></p><button onclick=start()>फिर से खेलें</button></div>
<button id=left>◀</button><button id=right>▶</button>
<script>
const c=document.querySelector('#c'),ctx=c.getContext('2d');let W,H,rx,rw,p,e,s,last,spawn,dead,L=0,R=0;
function size(){W=innerWidth;H=innerHeight;c.width=W*devicePixelRatio;c.height=H*devicePixelRatio;ctx.setTransform(devicePixelRatio,0,0,devicePixelRatio,0,0);rw=Math.min(W*.72,430);rx=(W-rw)/2}size();onresize=size;
function start(){p={x:W/2-23,y:H-145,w:46,h:78};e=[];s=0;spawn=0;dead=0;document.querySelector('#go').style.display='none';last=performance.now();requestAnimationFrame(loop)}
function hold(b,v){if(b==='l')L=v;else R=v}
for(const [id,b] of [['left','l'],['right','r']]){let q=document.getElementById(id);q.onpointerdown=()=>hold(b,1);q.onpointerup=()=>hold(b,0);q.onpointercancel=()=>hold(b,0)}
onkeydown=a=>{if(a.key==='ArrowLeft')L=1;if(a.key==='ArrowRight')R=1};onkeyup=a=>{if(a.key==='ArrowLeft')L=0;if(a.key==='ArrowRight')R=0};
function car(a,b,w,h,col){ctx.fillStyle=col;ctx.fillRect(a,b,w,h);ctx.fillStyle='#bde';ctx.fillRect(a+8,b+10,w-16,18);ctx.fillStyle='#222';ctx.fillRect(a+4,b+5,8,15);ctx.fillRect(a+w-12,b+5,8,15);ctx.fillRect(a+4,b+h-20,8,15);ctx.fillRect(a+w-12,b+h-20,8,15)}
function loop(t){if(dead)return;let d=Math.min((t-last)/16.67,2);last=t;
ctx.fillStyle='#28733d';ctx.fillRect(0,0,W,H);ctx.fillStyle='#555';ctx.fillRect(rx,0,rw,H);ctx.fillStyle='#eee';ctx.fillRect(rx+5,0,5,H);ctx.fillRect(rx+rw-10,0,5,H);
ctx.fillStyle='#fff';let o=(t/6)%80;for(let k=1;k<3;k++)for(let y=-40+o;y<H;y+=80)ctx.fillRect(rx+rw*k/3-3,y,6,45);
if(L)p.x-=7*d;if(R)p.x+=7*d;p.x=Math.max(rx+12,Math.min(rx+rw-p.w-12,p.x));
spawn-=d;if(spawn<=0){let lane=Math.floor(Math.random()*3);e.push({x:rx+rw*(lane+.5)/3-23,y:-90,w:46,h:78,v:3.3+Math.min(s/180,4),col:['#e33','#39f','#fc3'][Math.floor(Math.random()*3)]});spawn=Math.max(25,58-s/18)}
for(let a of e){a.y+=a.v*d;car(a.x,a.y,a.w,a.h,a.col)}e=e.filter(a=>a.y<H+100);s+=.12*d;document.querySelector('#score').textContent='Score: '+Math.floor(s);car(p.x,p.y,p.w,p.h,'#21d36b');
for(let a of e)if(p.x<a.x+a.w-7&&p.x+p.w>a.x+7&&p.y<a.y+a.h-8&&p.y+p.h>a.y+8){dead=1;document.querySelector('#f').textContent='स्कोर: '+Math.floor(s);document.querySelector('#go').style.display='flex'}
if(!dead)requestAnimationFrame(loop)}
start();
</script></html>
1
1
3KB
3KB
148.0ms
192.0ms
148.0ms