🎮ArcadeLab

لعبة طخ العلب - 20 سلاح

by ChromeFlame24
348 lines15.7 KB
▶ Play
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>لعبة طخ العلب - 20 سلاح</title>
<style>
  *{box-sizing:border-box; font-family: Tahoma, Arial, sans-serif;}
  body{margin:0; background:#1a1a1a; color:#fff; overflow-x:hidden;}
  .top{padding:12px; display:flex; justify-content:space-between; align-items:center; background:#222; border-bottom:2px solid #ffcc00; flex-wrap:wrap; gap:10px;}
  .top h1{margin:0; font-size:20px; color:#ffcc00;}
  .stats{display:flex; gap:15px; font-weight:bold; font-size:16px;}
  .stats span{color:#ffcc00;}
  #gameWrap{position:relative; max-width:950px; margin:15px auto; padding:0 10px;}
  canvas{width:100%; height:520px; background:linear-gradient(#87ceeb 0%, #c2e8ff 55%, #8b5a2b 55%, #6b4423 100%); border:3px solid #ffcc00; border-radius:12px; cursor:crosshair; display:block;}
  #flash{position:absolute; top:55%; left:50%; width:90px; height:90px; background:radial-gradient(circle, #fff 0%, #ffcc00 30%, #ff6600 60%, transparent 70%); border-radius:50%; pointer-events:none; opacity:0; transform:translate(-50%,-50%); mix-blend-mode:screen;}
  #weapons{display:grid; grid-template-columns:repeat(auto-fill,minmax(130px,1fr)); gap:8px; max-width:950px; margin:0 auto 20px; padding:0 10px;}
  .wbtn{background:#2a2a2a; border:2px solid #444; color:#fff; padding:10px 8px; border-radius:10px; cursor:pointer; text-align:center; transition:0.15s;}
  .wbtn small{display:block; color:#bbb; font-size:11px; margin-top:4px;}
  .wbtn.active{background:#ffcc00; color:#000; border-color:#ffcc00; transform:scale(1.03);}
  .wbtn.active small{color:#222;}
  .hint{text-align:center; color:#ccc; font-size:13px; padding-bottom:20px;}
  .hint b{color:#ffcc00;}
</style>
</head>
<body>

<div class="top">
  <h1>🎯 لعبة طخ العلب - 20 سلاح حقيقي</h1>
  <div class="stats">
    <div>السلاح: <span id="curName">AK-47</span></div>
    <div>الطلقات: <span id="ammo">30 / 30</span></div>
    <div>النقاط: <span id="score">0</span></div>
    <div>العلب: <span id="hits">0</span></div>
  </div>
</div>

<div id="gameWrap">
  <canvas id="c" width="920" height="520"></canvas>
  <div id="flash"></div>
</div>

<div id="weapons"></div>
<p class="hint">اضغط على العلبة للطخ • <b>R</b> للتلقيم • <b>1 - 0</b> لتبديل السلاح بسرعة • اضغط على السلاح من تحت لتغييره</p>

<script>
const canvas = document.getElementById('c');
const ctx = canvas.getContext('2d');
const flashEl = document.getElementById('flash');

// 20 سلاح حقيقي - كل سلاح إلو مواصفاته
const weapons = [
  { name:"AK-47", damage:34, fireRate:120, mag:30, reload:2200, type:"rifle", power:1.0, desc:"رشاش روسي - قوي وثابت" },
  { name:"M4A1", damage:30, fireRate:110, mag:30, reload:2000, type:"rifle", power:0.9, desc:"رشاش أمريكي سريع" },
  { name:"M16A4", damage:32, fireRate:140, mag:30, reload:2100, type:"rifle", power:0.95, desc:"بندقية هجومية دقيقة" },
  { name:"SCAR-L", damage:36, fireRate:130, mag:30, reload:2300, type:"rifle", power:1.05, desc:"بلجيكي - ضرر عالي" },
  { name:"G36", damage:29, fireRate:100, mag:30, reload:1900, type:"rifle", power:0.85, desc:"ألماني - سريع جدا" },
  { name:"AUG", damage:31, fireRate:115, mag:30, reload:2000, type:"rifle", power:0.9, desc:"نمساوي - تصميم غريب" },
  { name:"FAMAS", damage:28, fireRate:90, mag:25, reload:1900, type:"rifle", power:0.85, desc:"فرنسي - أسرع طلق" },
  { name:"MP5", damage:22, fireRate:95, mag:32, reload:1800, type:"smg", power:0.7, desc:"رشاش خفيف للمسافات القريبة" },
  { name:"UZI", damage:20, fireRate:85, mag:32, reload:1700, type:"smg", power:0.65, desc:"إسرائيلي - سريع وخفيف" },
  { name:"P90", damage:24, fireRate:90, mag:50, reload:2400, type:"smg", power:0.75, desc:"مخزن كبير 50 طلقة" },
  { name:"MP7", damage:23, fireRate:100, mag:40, reload:1900, type:"smg", power:0.72, desc:"ألماني صغير وقاتل" },
  { name:"Desert Eagle", damage:65, fireRate:450, mag:7, reload:2000, type:"pistol", power:1.6, desc:"مسدس الصحراء - طلقة بتطير العلبة" },
  { name:"Glock 17", damage:25, fireRate:220, mag:17, reload:1500, type:"pistol", power:0.8, desc:"مسدس نمساوي مشهور" },
  { name:"Beretta M9", damage:26, fireRate:240, mag:15, reload:1600, type:"pistol", power:0.82, desc:"مسدس الجيش الأمريكي" },
  { name:".44 Magnum", damage:70, fireRate:500, mag:6, reload:2300, type:"pistol", power:1.7, desc:"ريفيولفر - أقوى مسدس" },
  { name:"Remington 870", damage:90, fireRate:700, mag:6, reload:2600, type:"shotgun", power:2.2, desc:"شوتغن - بيكسر كل شي" },
  { name:"SPAS-12", damage:85, fireRate:650, mag:8, reload:2800, type:"shotgun", power:2.0, desc:"شوتغن إيطالي ثقيل" },
  { name:"AWP Sniper", damage:100, fireRate:1400, mag:5, reload:3000, type:"sniper", power:2.5, desc:"قناص - طلقة وحدة بتكفي" },
  { name:"Barrett M82", damage:120, fireRate:1600, mag:10, reload:3500, type:"sniper", power:2.8, desc:"قناص مضاد للدروع" },
  { name:"Kar98k", damage:95, fireRate:1200, mag:5, reload:2800, type:"sniper", power:2.3, desc:"قناص كلاسيك حرب عالمية" },
];

let current = 0;
let ammo = weapons[0].mag;
let score = 0;
let hits = 0;
let cans = [];
let particles = [];
let shells = [];
let lastShot = 0;
let reloading = false;
let mouse = {x:460, y:260};
let recoil = 0;

const weaponsDiv = document.getElementById('weapons');
weapons.forEach((w,i)=>{
  const b = document.createElement('div');
  b.className = 'wbtn' + (i===0?' active':'');
  b.innerHTML = `${i+1}. ${w.name}<small>${w.desc} | ضرر ${w.damage} | مخزن ${w.mag}</small>`;
  b.onclick = ()=> selectWeapon(i);
  weaponsDiv.appendChild(b);
});

function selectWeapon(i){
  current = i;
  ammo = weapons[i].mag;
  reloading = false;
  document.querySelectorAll('.wbtn').forEach((el,idx)=> el.classList.toggle('active', idx===i));
  updateHUD();
  playClick();
}
function updateHUD(){
  document.getElementById('curName').textContent = weapons[current].name;
  document.getElementById('ammo').textContent = reloading ? 'عم بيعبي...' : `${ammo} / ${weapons[current].mag}`;
  document.getElementById('score').textContent = score;
  document.getElementById('hits').textContent = hits;
}

// ===== الصوت - مولد بالكود بدون ملفات =====
let audioCtx = null;
function getAudio(){
  if(!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();
  if(audioCtx.state === 'suspended') audioCtx.resume();
  return audioCtx;
}
function playClick(){
  try{
    const ac = getAudio();
    const o = ac.createOscillator(); const g = ac.createGain();
    o.type='square'; o.frequency.value=800; g.gain.setValueAtTime(0.05, ac.currentTime);
    g.gain.exponentialRampToValueAtTime(0.001, ac.currentTime+0.05);
    o.connect(g); g.connect(ac.destination); o.start(); o.stop(ac.currentTime+0.06);
  }catch(e){}
}
function playGunshot(w){
  try{
    const ac = getAudio();
    const t = ac.currentTime;
    // ضجة الطلق - Noise
    const dur = w.type==='shotgun' ? 0.35 : w.type==='sniper' ? 0.45 : w.type==='pistol' ? 0.18 : 0.22;
    const bufferSize = ac.sampleRate * dur;
    const buffer = ac.createBuffer(1, bufferSize, ac.sampleRate);
    const data = buffer.getChannelData(0);
    for(let i=0;i<bufferSize;i++){
      data[i] = (Math.random()*2-1) * Math.pow(1 - i/bufferSize, 2.2);
    }
    const noise = ac.createBufferSource(); noise.buffer = buffer;
    const filter = ac.createBiquadFilter();
    filter.type = 'lowpass';
    filter.frequency.value = w.type==='sniper' || w.type==='shotgun' ? 800 : w.type==='pistol' ? 2500 : 1500;
    const gain = ac.createGain();
    gain.gain.setValueAtTime(0.9 * w.power, t);
    gain.gain.exponentialRampToValueAtTime(0.001, t+dur);
    noise.connect(filter); filter.connect(gain); gain.connect(ac.destination); noise.start(t);
    // طقة عميقة للسلاح الثقيل
    const osc = ac.createOscillator(); const og = ac.createGain();
    osc.type='sine';
    osc.frequency.setValueAtTime(w.type==='sniper' || w.type==='shotgun' ? 60 : 120, t);
    osc.frequency.exponentialRampToValueAtTime(30, t+0.15);
    og.gain.setValueAtTime(0.5 * w.power, t);
    og.gain.exponentialRampToValueAtTime(0.001, t+0.18);
    osc.connect(og); og.connect(ac.destination); osc.start(t); osc.stop(t+0.2);
    // صوت المعدن - ظرف الطلقة
    setTimeout(()=>{
      const o2 = ac.createOscillator(); const g2 = ac.createGain();
      o2.type='highpass'; o2.frequency.value=4000; g2.gain.setValueAtTime(0.03, ac.currentTime);
      g2.gain.exponentialRampToValueAtTime(0.001, ac.currentTime+0.08);
      o2.connect(g2); g2.connect(ac.destination); o2.start(); o2.stop(ac.currentTime+0.09);
    }, 120);
  }catch(e){}
}
function playHit(){
  try{
    const ac = getAudio(); const t = ac.currentTime;
    const o = ac.createOscillator(); const g = ac.createGain();
    o.type='triangle'; o.frequency.setValueAtTime(600,t); o.frequency.exponentialRampToValueAtTime(180,t+0.12);
    g.gain.setValueAtTime(0.25,t); g.gain.exponentialRampToValueAtTime(0.001,t+0.13);
    o.connect(g); g.connect(ac.destination); o.start(t); o.stop(t+0.14);
  }catch(e){}
}
function playReload(){
  try{
    const ac = getAudio();
    [0, 350, 750].forEach((d,i)=>{
      setTimeout(()=>{
        const o = ac.createOscillator(); const g = ac.createGain();
        o.type='square'; o.frequency.value = i===2 ? 900 : 400;
        g.gain.setValueAtTime(0.08, ac.currentTime); g.gain.exponentialRampToValueAtTime(0.001, ac.currentTime+0.08);
        o.connect(g); g.connect(ac.destination); o.start(); o.stop(ac.currentTime+0.09);
      }, d);
    });
  }catch(e){}
}

// ===== العلب =====
const canColors = ['#e74c3c','#3498db','#f1c40f','#2ecc71','#9b59b6','#e67e22','#1abc9c','#ff6b81'];
function spawnCan(){
  const w = 45 + Math.random()*25;
  const h = 60 + Math.random()*30;
  cans.push({
    x: 60 + Math.random()*(canvas.width-120),
    y: 300 + Math.random()*60,
    w: w, h: h,
    hp: w > 60 ? 2 : 1,
    maxHp: w > 60 ? 2 : 1,
    color: canColors[Math.floor(Math.random()*canColors.length)],
    vy: 0, vx: 0, falling: false, rot: 0, vr: 0, alpha: 1
  });
}
for(let i=0;i<6;i++) spawnCan();
setInterval(()=>{ if(cans.length < 9) spawnCan(); }, 1200);

function shoot(x,y){
  const now = Date.now();
  const w = weapons[current];
  if(reloading) return;
  if(now - lastShot < w.fireRate) return;
  if(ammo <= 0){ playClick(); reload(); return; }
  lastShot = now;
  ammo--;
  recoil = w.power * 8;
  // وميض الطلق
  flashEl.style.left = x + 'px';
  flashEl.style.top = (y - 10) + 'px';
  flashEl.style.opacity = 1;
  flashEl.style.width = (70 + w.power*30)+'px';
  flashEl.style.height = (70 + w.power*30)+'px';
  setTimeout(()=> flashEl.style.opacity = 0, 60);
  // ظرف طلق طاير
  shells.push({x: x+10, y: y, vx: 2+Math.random()*3, vy: -4-Math.random()*3, rot:0});
  playGunshot(w);
  updateHUD();

  // فحص الإصابة - من فوق لتحت
  for(let i=cans.length-1; i>=0; i--){
    const c = cans[i];
    if(x >= c.x && x <= c.x+c.w && y >= c.y && y <= c.y+c.h){
      c.hp -= 1;
      playHit();
      // شظايا
      for(let p=0;p<12;p++) particles.push({x:x, y:y, vx:(Math.random()-0.5)*8, vy:(Math.random()-0.5)*8, life:1, color:c.color});
      if(c.hp <= 0){
        c.falling = true; c.vy = -6 - Math.random()*3; c.vx = (Math.random()-0.5)*6; c.vr = (Math.random()-0.5)*0.3;
        score += w.damage; hits++;
        // علبة جديدة بعد شوي
        setTimeout(spawnCan, 800);
      } else {
        score += 10;
      }
      updateHUD();
      break;
    }
  }
}

function reload(){
  const w = weapons[current];
  if(reloading || ammo === w.mag) return;
  reloading = true; updateHUD(); playReload();
  setTimeout(()=>{ ammo = w.mag; reloading=false; updateHUD(); }, w.reload);
}

// ===== الرسم =====
function draw(){
  ctx.clearRect(0,0,canvas.width,canvas.height);
  // شمس وغيوم
  ctx.fillStyle='#fff3b0'; ctx.beginPath(); ctx.arc(820,70,35,0,Math.PI*2); ctx.fill();
  ctx.fillStyle='rgba(255,255,255,0.85)';
  ctx.beginPath(); ctx.ellipse(180,80,60,18,0,0,Math.PI*2); ctx.fill();
  ctx.beginPath(); ctx.ellipse(450,60,70,18,0,0,Math.PI*2); ctx.fill();
  // طاولة خشبية
  ctx.fillStyle='#5d3a1a'; ctx.fillRect(0,380,canvas.width,22);
  ctx.fillStyle='#7a4a22'; ctx.fillRect(0,402,canvas.width,118);
  ctx.fillStyle='#3d250f'; ctx.fillRect(0,380,canvas.width,4);
  // العلب
  cans.forEach(c=>{
    ctx.save();
    ctx.globalAlpha = c.alpha;
    ctx.translate(c.x + c.w/2, c.y + c.h/2);
    ctx.rotate(c.rot);
    // جسم العلبة
    ctx.fillStyle = c.color;
    ctx.fillRect(-c.w/2, -c.h/2, c.w, c.h);
    ctx.fillStyle = 'rgba(255,255,255,0.35)'; ctx.fillRect(-c.w/2, -c.h/2, c.w, 10);
    ctx.fillStyle = 'rgba(0,0,0,0.25)'; ctx.fillRect(-c.w/2, c.h/2-10, c.w, 10);
    ctx.fillStyle = '#fff'; ctx.font = 'bold 13px Arial'; ctx.textAlign='center';
    ctx.fillText(c.maxHp>1 ? 'BIG' : 'COLA', 0, 4);
    ctx.fillStyle = '#silver'; ctx.fillRect(-c.w/2, -c.h/2-4, c.w, 5);
    ctx.restore();
  });
  // جزيئات
  particles = particles.filter(p=> p.life>0);
  particles.forEach(p=>{
    p.x+=p.vx; p.y+=p.vy; p.vy+=0.3; p.life-=0.04;
    ctx.globalAlpha = Math.max(p.life,0); ctx.fillStyle=p.color;
    ctx.fillRect(p.x, p.y, 5,5);
  });
  ctx.globalAlpha=1;
  // ظروف الطلق
  shells = shells.filter(s=> s.y < canvas.height);
  shells.forEach(s=>{
    s.x+=s.vx; s.y+=s.vy; s.vy+=0.4; s.rot+=0.2;
    ctx.save(); ctx.translate(s.x,s.y); ctx.rotate(s.rot);
    ctx.fillStyle='#ffcc00'; ctx.fillRect(-3,-6,6,12); ctx.restore();
  });
  // السلاح من تحت - منظور أول
  const gunY = canvas.height - 55 + recoil;
  ctx.fillStyle = '#111'; ctx.fillRect(canvas.width/2 - 90, gunY, 180, 42);
  ctx.fillStyle = '#333'; ctx.fillRect(canvas.width/2 - 90, gunY, 180, 10);
  ctx.fillStyle = '#ffcc00'; ctx.font='bold 14px Arial'; ctx.textAlign='center';
  ctx.fillText(weapons[current].name + '  |  ' + ammo + ' طلقة', canvas.width/2, gunY+28);
  if(reloading){
    ctx.fillStyle='#ff4444'; ctx.font='bold 18px Arial';
    ctx.fillText('... عم بعبي ...', canvas.width/2, gunY-18);
  }
  // تصويب
  ctx.strokeStyle='red'; ctx.lineWidth=2;
  ctx.beginPath(); ctx.arc(mouse.x, mouse.y, 18, 0, Math.PI*2); ctx.stroke();
  ctx.beginPath(); ctx.moveTo(mouse.x-24, mouse.y); ctx.lineTo(mouse.x+24, mouse.y); ctx.moveTo(mouse.x, mouse.y-24); ctx.lineTo(mouse.x, mouse.y+24); ctx.stroke();
  ctx.fillStyle='red'; ctx.beginPath(); ctx.arc(mouse.x, mouse.y, 2.5, 0, Math.PI*2); ctx.fill();
  // تحديث فيزياء العلب الواقعة
  cans.forEach(c=>{
    if(c.falling){
      c.x+=c.vx; c.y+=c.vy; c.vy+=0.6; c.rot+=c.vr;
      if(c.y > 480){ c.alpha-=0.05; }
    }
  });
  cans = cans.filter(c=> c.alpha > 0);
  if(recoil>0) recoil*=0.85;
  requestAnimationFrame(draw);
}
draw();

canvas.addEventListener('mousemove', e=>{
  const r = canvas.getBoundingClientRect();
  mouse.x = (e.clientX - r.left) * (canvas.width / r.width);
  mouse.y = (e.clientY - r.top) * (canvas.height / r.height);
});
canvas.addEventListener('mousedown', e=>{
  getAudio();
  const r = canvas.getBoundingClientRect();
  const x = (e.clientX - r.left) * (canvas.width / r.width);
  const y = (e.clientY - r.top) * (canvas.height / r.height);
  shoot(x,y);
});
document.addEventListener('keydown', e=>{
  if(e.key.toLowerCase()==='r') reload();
  const num = parseInt(e.key);
  if(num>=1 && num<=9) selectWeapon(num-1);
  if(e.key==='0') selectWeapon(9);
  if(e.key==='q' || e.key==='Q') selectWeapon((current+19)%20);
  if(e.key==='e' || e.key==='E') selectWeapon((current+1)%20);
});
</script>
</body>
</html>

Game Source: لعبة طخ العلب - 20 سلاح

Creator: ChromeFlame24

Libraries: none

Complexity: complex (348 lines, 15.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: 20-chromeflame24" to link back to the original. Then publish at arcadelab.ai/publish.