🎮ArcadeLab

مسابقه خیابانی MADYAR

by LaserWolf67
82 lines5.5 KB
▶ Play
<!doctype html>
<html lang="fa" dir="rtl">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<title>مسابقه خیابانی MADYAR</title>
<style>
*{box-sizing:border-box} body{margin:0;background:#071326;color:#fff;font-family:Tahoma,Arial,sans-serif;display:flex;min-height:100vh;align-items:center;justify-content:center}
.game{width:min(100vw,520px);padding:12px;text-align:center}
h1{font-size:22px;margin:5px 0 8px;color:#ffd76a}
.info{display:flex;justify-content:space-between;margin:6px 3px;font-size:16px}
canvas{display:block;width:100%;height:auto;aspect-ratio:9/14;border:3px solid #d7b66a;border-radius:12px;background:#253c35;touch-action:none}
.controls{display:flex;gap:12px;margin-top:12px}
button{font: bold 20px Tahoma;border:0;border-radius:12px;padding:15px;background:#e9b84e;color:#142033;flex:1;box-shadow:0 4px #9c6c1c;touch-action:manipulation}
button:active{transform:translateY(3px);box-shadow:0 1px #9c6c1c}
#start{background:#61d79b;color:#062b20;margin-top:10px;width:100%}
.note{font-size:12px;color:#b9c6d8;margin-top:8px}
</style>
</head>
<body>
<div class="game">
<h1>🏁 مسابقه خیابانی MADYAR</h1>
<div class="info"><span>امتیاز: <b id="score">0</b></span><span>رکورد: <b id="best">0</b></span></div>
<canvas id="c" width="450" height="700" aria-label="بازی ماشین"></canvas>
<div class="controls"><button id="left">◀ چپ</button><button id="right">راست ▶</button></div>
<button id="start">شروع بازی</button>
<div class="note">با دکمه‌ها یا کلیدهای ← → حرکت کن و از ماشین‌ها دوری کن.</div>
</div>
<script>
const canvas=document.getElementById('c'),ctx=canvas.getContext('2d');
const scoreEl=document.getElementById('score'),bestEl=document.getElementById('best'),startBtn=document.getElementById('start');
let best=0;try{best=Number(localStorage.getItem('madyarBest')||0)}catch(e){}
bestEl.textContent=best;
const W=450,H=700, road={x:65,w:320};
let player={lane:1,x:0,y:565,w:52,h:88}, cars=[],score=0,speed=4,spawn=0,playing=false,over=false,roadOffset=0;
function laneX(l){return road.x+road.w*(l+.5)/3}
function reset(){player.lane=1;player.x=laneX(1);cars=[];score=0;speed=4;spawn=0;roadOffset=0;scoreEl.textContent='0';playing=true;over=false;startBtn.textContent='شروع دوباره';}
function drawCar(x,y,color,playerCar=false){
 ctx.save();ctx.translate(x,y);
 ctx.fillStyle='rgba(0,0,0,.25)';ctx.fillRect(-25+5,5,50,82);
 ctx.fillStyle=color;roundRect(-26,0,52,82,10);ctx.fill();
 ctx.fillStyle=playerCar?'#bfeaff':'#d9e7ef';roundRect(-17,10,34,22,5);ctx.fill();
 ctx.fillStyle='#16243a';roundRect(-17,43,34,25,5);ctx.fill();
 ctx.fillStyle='#fff3a1';ctx.fillRect(-22,5,9,5);ctx.fillRect(13,5,9,5);
 ctx.fillStyle='#121923';ctx.fillRect(-30,17,6,18);ctx.fillRect(24,17,6,18);ctx.fillRect(-30,55,6,18);ctx.fillRect(24,55,6,18);
 if(playerCar){ctx.fillStyle='#ffe16b';ctx.fillRect(-4,29,8,15)}
 ctx.restore();
}
function roundRect(x,y,w,h,r){ctx.beginPath();ctx.roundRect(x,y,w,h,r)}
function draw(){
 ctx.clearRect(0,0,W,H);
 // scenery
 ctx.fillStyle='#1b573d';ctx.fillRect(0,0,W,H);
 for(let y=-40;y<H;y+=100){let yy=(y+roadOffset)%H;ctx.fillStyle='#276c49';ctx.fillRect(0,yy,54,50);ctx.fillRect(396,yy,54,50);ctx.fillStyle='#d4c27a';ctx.fillRect(24,yy+12,12,22);ctx.fillRect(414,yy+12,12,22)}
 ctx.fillStyle='#343b49';ctx.fillRect(road.x,0,road.w,H);
 ctx.fillStyle='#e8dca7';ctx.fillRect(road.x,0,7,H);ctx.fillRect(road.x+road.w-7,0,7,H);
 for(let i=1;i<3;i++){ctx.fillStyle='#f5f0cf';for(let y=-70;y<H;y+=140){ctx.fillRect(road.x+road.w*i/3-3,(y+roadOffset)%H,6,72)}}
 // cars
 cars.forEach(c=>drawCar(laneX(c.lane),c.y,c.color));
 drawCar(player.x,player.y,'#e34e5c',true);
 if(!playing){ctx.fillStyle='rgba(2,9,22,.72)';ctx.fillRect(0,0,W,H);ctx.fillStyle='#fff';ctx.textAlign='center';ctx.font='bold 32px Tahoma';ctx.fillText(over?'تصادف شد!':'آماده‌ای؟',W/2,300);ctx.font='20px Tahoma';ctx.fillText(over?'امتیاز: '+score:'برای شروع دکمه را بزن',W/2,345)}
}
function move(dir){if(!playing)return;player.lane=Math.max(0,Math.min(2,player.lane+dir));player.x=laneX(player.lane)}
function frame(){
 if(playing){
  score++;scoreEl.textContent=Math.floor(score/8);speed=4+Math.min(5,score/450);roadOffset=(roadOffset+speed)%140;spawn++;
  if(spawn>Math.max(30,75-score/30)){spawn=0;let lane=Math.floor(Math.random()*3);cars.push({lane,y:-100,color:['#438de0','#f2b544','#8d71d8','#4ec5a2'][Math.floor(Math.random()*4)]})}
  cars.forEach(c=>c.y+=speed);
  cars=cars.filter(c=>c.y<H+100);
  for(const c of cars){if(c.lane===player.lane&&c.y+72>player.y+8&&c.y<player.y+player.h-8){playing=false;over=true;let final=Math.floor(score/8);if(final>best){best=final;bestEl.textContent=best;try{localStorage.setItem('madyarBest',best)}catch(e){}}break}}
 }
 draw();requestAnimationFrame(frame)
}
startBtn.addEventListener('click',reset);
document.getElementById('left').addEventListener('pointerdown',e=>{e.preventDefault();move(-1)});
document.getElementById('right').addEventListener('pointerdown',e=>{e.preventDefault();move(1)});
window.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==='Enter')&&!playing)reset()});
canvas.addEventListener('pointerdown',e=>{if(!playing)reset();else{const r=canvas.getBoundingClientRect();move(e.clientX<r.left+r.width/2?-1:1)}});
draw();requestAnimationFrame(frame);
</script>
</body>
</html>

Game Source: مسابقه خیابانی MADYAR

Creator: LaserWolf67

Libraries: none

Complexity: moderate (82 lines, 5.5 KB)

The full source code is displayed above on this page.

Remix Instructions

To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: madyar-laserwolf67" to link back to the original. Then publish at arcadelab.ai/publish.