بهترین پنالتیزن
by LaserWolf6776 lines5.7 KB
<!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>بهترین پنالتیزن</title>
<style>
*{box-sizing:border-box}body{margin:0;background:#071b2a;color:#fff;font-family:Tahoma,Arial;display:flex;justify-content:center}
main{width:min(100%,520px);padding:12px;text-align:center}h1{margin:8px 0;color:#ffd86a;font-size:23px}.bar{display:flex;justify-content:space-between;font-size:15px;margin:8px 2px}
canvas{width:100%;height:auto;aspect-ratio:9/13;background:#173d2b;border:3px solid #d2b46a;border-radius:10px;touch-action:none;display:block}
p{font-size:13px;color:#d2ddeb;margin:8px 0}.controls{display:flex;gap:10px;margin-top:10px}button{border:0;border-radius:11px;padding:14px 8px;font:bold 17px Tahoma;background:#f2c34d;color:#142033;flex:1;box-shadow:0 4px #a77b20}button:active{transform:translateY(2px);box-shadow:0 2px #a77b20}#again{background:#60d99c}
</style></head>
<body><main>
<h1>⚽ بهترین پنالتیزن</h1>
<div class="bar"><span>گل: <b id="goals">0</b></span><span>شوت: <b id="shots">0</b></span><span>رکورد: <b id="best">0</b></span></div>
<canvas id="game" width="450" height="650"></canvas>
<p id="msg">برای نشانهگیری، روی دروازه لمس کن؛ سپس «شوت بزن» را بزن.</p>
<div class="controls"><button id="shoot">شوت بزن ⚽</button><button id="again">شروع دوباره</button></div>
<p>هر جا از داخل دروازه هدف بگیری، توپ به همان سمت میرود. دروازهبان تلاش میکند توپ را بگیرد!</p>
</main>
<script>
const cv=document.getElementById('game'),c=cv.getContext('2d'),W=450,H=650;
let aim={x:225,y:180},ball={x:225,y:520},keeper={x:225,y:265},flight=null,goals=0,shots=0,best=0,feedback='هدف را انتخاب کن!';
try{best=+localStorage.getItem('bestPen')||0}catch(e){}
const $=id=>document.getElementById(id);$('best').textContent=best;
function field(){
c.clearRect(0,0,W,H);
let g=c.createLinearGradient(0,0,0,H);g.addColorStop(0,'#247748');g.addColorStop(1,'#0b4b2e');c.fillStyle=g;c.fillRect(0,0,W,H);
// pitch stripes
for(let y=0;y<H;y+=130){c.fillStyle='rgba(255,255,255,.035)';c.fillRect(0,y,W,65)}
c.strokeStyle='rgba(255,255,255,.65)';c.lineWidth=3;c.strokeRect(35,70,380,330);c.strokeRect(105,70,240,170);
// goal
c.fillStyle='#f3f4f4';c.fillRect(74,70,302,12);c.fillRect(74,70,12,145);c.fillRect(364,70,12,145);
c.strokeStyle='rgba(255,255,255,.35)';c.lineWidth=1;
for(let x=90;x<365;x+=25){c.beginPath();c.moveTo(x,82);c.lineTo(x,210);c.stroke()}
for(let y=100;y<210;y+=22){c.beginPath();c.moveTo(86,y);c.lineTo(364,y);c.stroke()}
// penalty spot and ball
c.fillStyle='#fff';c.beginPath();c.arc(225,520,5,0,Math.PI*2);c.fill();
c.beginPath();c.arc(ball.x,ball.y,flight?Math.max(5,13-flight.t*.08):13,0,Math.PI*2);c.fill();c.strokeStyle='#111';c.lineWidth=2;c.stroke();
// ball pattern
c.fillStyle='#111';c.beginPath();c.arc(ball.x,ball.y,4,0,Math.PI*2);c.fill();
// keeper
drawKeeper(keeper.x,keeper.y,flight&&flight.keeperDive?flight.keeperDive:0);
// aim marker
if(!flight){c.strokeStyle='#ffe16a';c.lineWidth=3;c.beginPath();c.arc(aim.x,aim.y,14,0,Math.PI*2);c.stroke();c.beginPath();c.moveTo(aim.x-20,aim.y);c.lineTo(aim.x+20,aim.y);c.moveTo(aim.x,aim.y-20);c.lineTo(aim.x,aim.y+20);c.stroke()}
// message overlay
c.fillStyle='rgba(4,14,22,.6)';c.fillRect(20,570,410,55);c.fillStyle='#fff';c.font='bold 22px Tahoma';c.textAlign='center';c.fillText(feedback,225,605);
}
function drawKeeper(x,y,dive){
c.save();c.translate(x,y);c.rotate(dive*.45);
// legs
c.strokeStyle='#f2c34d';c.lineWidth=15;c.lineCap='round';c.beginPath();c.moveTo(-8,20);c.lineTo(-25,53);c.moveTo(8,20);c.lineTo(25,53);c.stroke();
c.fillStyle='#ef6a45';c.fillRect(-25,-22,50,52);
c.fillStyle='#e9b78b';c.beginPath();c.arc(0,-38,18,0,Math.PI*2);c.fill();
c.strokeStyle='#e9b78b';c.lineWidth=12;c.beginPath();c.moveTo(-20,-14);c.lineTo(-43+dive*25,-32);c.moveTo(20,-14);c.lineTo(43+dive*25,-32);c.stroke();
c.fillStyle='#fff';c.beginPath();c.arc(-44+dive*25,-33,9,0,Math.PI*2);c.arc(44+dive*25,-33,9,0,Math.PI*2);c.fill();
c.restore();
}
function sync(){ $('goals').textContent=goals;$('shots').textContent=shots;$('best').textContent=best}
function tap(e){if(flight)return;const r=cv.getBoundingClientRect(),x=(e.clientX-r.left)*W/r.width,y=(e.clientY-r.top)*H/r.height;
if(y<250&&x>75&&x<375){aim.x=Math.max(90,Math.min(360,x));aim.y=Math.max(90,Math.min(205,y));feedback='نشانه آماده است!';field()}}
cv.addEventListener('pointerdown',tap);
function shoot(){if(flight)return;shots++;let dx=aim.x-225,dy=aim.y-180;
let dive=(Math.random()*2-1),save=Math.abs(dx)<52&&Math.abs(dive)<.55&&aim.y>125;
flight={t:0,sx:225,sy:520,tx:aim.x,ty:aim.y,keeperDive:dive,save};
feedback='شوووت!';sync();anim()}
function anim(){if(!flight)return;flight.t+=1;let t=Math.min(1,flight.t/36),f=flight;
ball.x=f.sx+(f.tx-f.sx)*t;ball.y=f.sy+(f.ty-f.sy)*t-120*Math.sin(Math.PI*t);
keeper.x=225+(f.save?f.keeperDive*80:f.keeperDive*35)*Math.min(1,t*1.6);keeper.y=265-20*Math.min(1,t);
if(t>=1){let scored=!f.save; if(scored){goals++;feedback='گــــل! عالی بود ⚽'}else{feedback='دروازهبان گرفت!';}
if(goals>best){best=goals;try{localStorage.setItem('bestPen',best)}catch(e){}}
flight=null;ball={x:225,y:520};keeper={x:225,y:265};aim={x:225,y:180};sync();field();return}
field();requestAnimationFrame(anim)}
$('shoot').addEventListener('click',shoot);
$('again').addEventListener('click',()=>{goals=0;shots=0;flight=null;ball={x:225,y:520};keeper={x:225,y:265};aim={x:225,y:180};feedback='هدف را انتخاب کن!';sync();field()});
field();
</script></body></html>Game Source: بهترین پنالتیزن
Creator: LaserWolf67
Libraries: none
Complexity: moderate (76 lines, 5.7 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: game-laserwolf67" to link back to the original. Then publish at arcadelab.ai/publish.