🎮ArcadeLab

LOOM GALAXY ATTACK V2 - PIXEL

by MegaOtter89
220 lines10.3 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>LOOM GALAXY ATTACK V2 - PIXEL</title>
<style>
*{box-sizing:border-box;font-family:Tahoma}
body{margin:0;background:#0a0a1f;color:#fff;text-align:center}
h1{margin:5px 0 0;color:#FFD700;font-size:28px;line-height:1;text-shadow:0 0 12px red}
h1 span{color:#fff}
p{margin:0;color:#ff8c00;letter-spacing:8px;font-weight:bold;font-size:12px}
#hud{display:flex;justify-content:space-around;background:#11113a;padding:8px;font-size:13px}
#hud b{color:#FFD700}
canvas{background:#050514;display:block;margin:5px auto;border:2px solid #FFD700;border-radius:8px;touch-action:none;max-width:95vw;image-rendering:pixelated}
button{background:#FFD700;color:#000;border:none;padding:10px 14px;border-radius:10px;font-weight:bold;margin:4px;cursor:pointer}
button.off{background:#555;color:#fff}
</style>
</head>
<body>
<h1>LOOM<br><span>GALAXY</span></h1><p>PIXEL ATTACK V2</p>
<div id="hud"><div>نقاط: <b id="score">0</b></div><div>كومبو: <b id="combo">x1</b></div><div>موجة: <b id="wave">1</b></div><div>عملات: <b id="coins">0</b></div><div>صحة: <b id="hp">100</b></div></div>
<canvas id="game" width="400" height="520"></canvas>
<div>
<button onclick="startGame()">▶ العب</button>
<button id="soundBtn" onclick="toggleSound()">🔊 صوت: شغال</button>
<button onclick="upgradeWeapon()">⬆️ سلاح 50🪙</button>
<button onclick="useBomb()">💣 قنبلة</button>
</div>

<script>
const canvas=document.getElementById('game'), ctx=canvas.getContext('2d');
let score=0, wave=1, coins=0, combo=1, comboTimer=0, running=false, paused=false, soundOn=true, weaponLv=1, bombs=2, shield=0, shake=0;
let player={x:200,y:450,hp:100,maxHp:100};
let bullets=[], enemies=[], parts=[], drops=[], powers=[];
let timer=0, shootTimer=0, musicTimer=0;

// ========== الصوت - Web Audio بدون ملفات ==========
let audioCtx=null;
function getAudio(){if(!audioCtx)audioCtx=new (window.AudioContext||window.webkitAudioContext)();if(audioCtx.state==='suspended')audioCtx.resume();return audioCtx;}
function beep(freq,dur,type='square',vol=0.08,slide=0){
  if(!soundOn)return; try{
    let a=getAudio(), o=a.createOscillator(), g=a.createGain();
    o.type=type; o.frequency.setValueAtTime(freq,a.currentTime);
    if(slide)o.frequency.exponentialRampToValueAtTime(Math.max(30,freq+slide),a.currentTime+dur);
    g.gain.setValueAtTime(vol,a.currentTime); g.gain.exponentialRampToValueAtTime(0.001,a.currentTime+dur);
    o.connect(g); g.connect(a.destination); o.start(); o.stop(a.currentTime+dur);
  }catch(e){}
}
function playLaser(){beep(880,0.08,'square',0.06,-400);}
function playExplosion(){beep(150,0.3,'sawtooth',0.12,-100);}
function playCoin(){beep(1200,0.08,'square',0.07);setTimeout(()=>beep(1600,0.12,'square',0.07),80);}
function playHit(){beep(220,0.15,'sawtooth',0.1,-80);}
function playBoss(){beep(80,0.5,'sawtooth',0.15,200);}
function playPower(){beep(500,0.1,'square',0.08);setTimeout(()=>beep(800,0.1,'square',0.08),100);setTimeout(()=>beep(1100,0.15,'square',0.08),200);}
function toggleSound(){soundOn=!soundOn;document.getElementById('soundBtn').textContent=soundOn?'🔊 صوت: شغال':'🔇 صوت: طافي';document.getElementById('soundBtn').className=soundOn?'':'off';}
function musicLoop(){
  if(!running||!soundOn)return;
  let notes=[440,520,660,520,440,330,392,440];
  let n=notes[Math.floor(musicTimer/10)%notes.length];
  if(musicTimer%10===0)beep(n,0.15,'triangle',0.03);
  musicTimer++;
}

// ========== بكسل آرت ==========
const COLORS={'.':null,'G':'#7AC74F','D':'#2E7D32','R':'#FF0000','W':'#FFFFFF','B':'#000000','Y':'#FFD700','O':'#FF8C00','C':'#00FFFF','P':'#FF69B4','S':'#C0C0C0','E':'#00E676','N':'#1E90FF'};
const SPRITES={
player:[
"....Y....",
"...YYY...",
"..YNYNY..",
"..YNNNY..",
".NNCCCNN.",
"NNNCCCNNN",
".NNYNNNN.",
"..NNNNN..",
"...NNN...",
"....N...."],
zombie:[
".GGGGGG.",
"GDDDDDDG",
"GDWWWW DG".replace(" ",""),
"GDWRWRDG",
"GDDDDDDG",
"GDWWWW DG".replace(" ",""),
".GDDDDG.",
"..GGGG.."],
zombieFast:[
".DDDDD.",
"DWWWDWD".replace(" ",""),
"DWRWRWD",
"DDDDDDD",
"DWWWWWD",
".DDDDD."],
zombieTank:[
"..DDDDDD..",
".DDDDDDDD.",
"DDWWWWWWDD",
"DDWRWWRWDD",
"DDDDDDDDDD",
"DDWWWWWWDD",
".DDDDDDDD.",
"..DDDDDD.."],
boss:[
"WW.DDDDDD.WW",
"WDDDDDDDDDDW",
"DWWRWWWW RWD".replace(" ",""),
"DDDDDDDDDDDD",
"DDWWWWWWWWDD",
"DDDDDDDDDDDD",
".DDDDDDDDDD.",
"..DDDDDDDD.."]
};
function drawPixel(sprite,x,y,size){
  for(let row=0;row<sprite.length;row++){
    for(let col=0;col<sprite[row].length;col++){
      let ch=sprite[row][col]; if(ch==='.'||!COLORS[ch])continue;
      ctx.fillStyle=COLORS[ch];
      ctx.fillRect(x+col*size - sprite[row].length*size/2, y+row*size - sprite.length*size/2, size, size);
    }
  }
}

function startGame(){score=0;wave=1;coins=100;combo=1;weaponLv=1;bombs=2;shield=0;player.hp=100;player.x=200;bullets=[];enemies=[];parts=[];drops=[];powers=[];running=true;paused=false;playPower();updateHUD();}
function upgradeWeapon(){if(coins<50){alert('بدك 50 عملة!');return;}coins-=50;weaponLv++;playPower();updateHUD();}
function useBomb(){if(bombs<=0){alert('خلصت القنابل!');return;}bombs--;shake=15;playExplosion();enemies.forEach(e=>e.hp-=10);updateHUD();}
function updateHUD(){document.getElementById('score').textContent=score;document.getElementById('combo').textContent='x'+combo;document.getElementById('wave').textContent=wave;document.getElementById('coins').textContent=coins;document.getElementById('hp').textContent=player.hp;}

function spawnEnemy(){
  let isBoss=wave%5===0 && Math.random()<0.25;
  let r=Math.random(); let type=isBoss?'boss':r<0.5?'zombie':r<0.8?'zombieFast':'zombieTank';
  let e={x:40+Math.random()*320,y:-40,type:type,vy:0,r:20};
  if(type==='zombie'){e.vy=1.1;e.hp=3;e.r=20;}
  if(type==='zombieFast'){e.vy=1.9;e.hp=2;e.r=16;}
  if(type==='zombieTank'){e.vy=0.7;e.hp=9;e.r=26;}
  if(type==='boss'){e.vy=0.5;e.hp=35;e.r=40;playBoss();}
  enemies.push(e);
  if(Math.random()<0.08)powers.push({x:40+Math.random()*320,y:-20,kind:Math.random()<0.5?'shield':'double'});
}

canvas.addEventListener('pointermove',e=>{
  let r=canvas.getBoundingClientRect();
  player.x=(e.clientX-r.left)*(canvas.width/r.width);
  player.y=(e.clientY-r.top)*(canvas.height/r.height);
  if(player.y>480)player.y=480; if(player.y<100)player.y=100;
});
canvas.addEventListener('pointerdown',()=>{if(!running)startGame(); getAudio();});

function loop(){
  requestAnimationFrame(loop);
  if(!running||paused){if(!running)drawStart();return;}
  musicLoop();
  comboTimer++; if(comboTimer>180){combo=1;comboTimer=0;}
  shootTimer++; if(shootTimer>16){
    let n=weaponLv>=3?3:weaponLv>=2?2:1;
    for(let i=0;i<n;i++)bullets.push({x:player.x+(i-(n-1)/2)*12,y:player.y-18});
    playLaser(); shootTimer=0;
  }
  timer++; if(timer>50){spawnEnemy();timer=0;if(Math.random()<0.07)wave++;}
  bullets.forEach(b=>b.y-=9); bullets=bullets.filter(b=>b.y>-10);
  enemies.forEach(e=>{e.y+=e.vy; e.x+=Math.sin(e.y/30)*0.7;});
  enemies=enemies.filter(e=>e.y<580);
  parts.forEach(p=>{p.x+=p.vx;p.y+=p.vy;p.life--;}); parts=parts.filter(p=>p.life>0);
  drops.forEach(d=>d.y+=2); drops=drops.filter(d=>d.y<560);
  powers.forEach(p=>p.y+=1.5); powers=powers.filter(p=>p.y<560);
  if(shake>0)shake--;
  bullets.forEach((b,bi)=>{enemies.forEach((e,ei)=>{
    let dx=b.x-e.x, dy=b.y-e.y;
    if(Math.sqrt(dx*dx+dy*dy)<e.r+6){
      e.hp-=1; bullets.splice(bi,1); playHit();
      if(e.hp<=0){
        combo++; comboTimer=0;
        score+=(e.type==='boss'?500:50)*combo; coins+=e.type==='boss'?50:5;
        for(let i=0;i<16;i++)parts.push({x:e.x,y:e.y,vx:(Math.random()-0.5)*6,vy:(Math.random()-0.5)*6,life:25,c:'#7AC74F'});
        drops.push({x:e.x,y:e.y}); enemies.splice(ei,1); playExplosion();
        if(e.type==='boss'){bombs++; coins+=30;}
      }
    }});
  });
  enemies.forEach((e,ei)=>{
    if(Math.abs(e.x-player.x)<e.r*0.7+12 && Math.abs(e.y-player.y)<e.r*0.7+12){
      if(shield>0){shield--;enemies.splice(ei,1);playPower();}
      else{player.hp-=12;shake=8;enemies.splice(ei,1);playHit();if(player.hp<=0){running=false;beep(100,0.6,'sawtooth',0.15,-50);alert('انتهت اللعبة! نقاطك: '+score+' - عملاتك: '+coins+' - أعلى كومبو: x'+combo);}}
    }
  });
  drops.forEach((d,di)=>{if(Math.abs(d.x-player.x)<22&&Math.abs(d.y-player.y)<22){coins+=5;drops.splice(di,1);playCoin();}});
  powers.forEach((p,pi)=>{if(Math.abs(p.x-player.x)<22&&Math.abs(p.y-player.y)<22){if(p.kind==='shield')shield=2; else weaponLv=Math.min(4,weaponLv+1); powers.splice(pi,1); playPower();}});
  updateHUD(); draw();
}
function drawStart(){
  ctx.fillStyle='#050514';ctx.fillRect(0,0,400,520);
  ctx.fillStyle='#FFD700';ctx.font='bold 26px Tahoma';ctx.textAlign='center';
  ctx.fillText('LOOM GALAXY',200,180);ctx.fillStyle='#fff';ctx.fillText('PIXEL ATTACK V2',200,220);
  drawPixel(SPRITES.player,200,300,4);
  drawPixel(SPRITES.zombie,140,380,3); drawPixel(SPRITES.boss,260,380,3);
  ctx.fillStyle='#7AC74F';ctx.font='15px Tahoma';ctx.fillText('الزومبي البكسل جايين! اضربهم',200,440);
  ctx.fillStyle='#FF8C00';ctx.fillText('اكبس العب - صوت شغال',200,465);
}
function draw(){
  ctx.save();
  if(shake>0)ctx.translate((Math.random()-0.5)*shake,(Math.random()-0.5)*shake);
  ctx.fillStyle='#0a0a2a';ctx.fillRect(-20,-20,440,560);
  for(let i=0;i<60;i++){ctx.fillStyle='#fff';ctx.fillRect((i*73)%400,(i*47+Date.now()/25)%520,2,2);}
  bullets.forEach(b=>{ctx.fillStyle='#FFFF00';ctx.fillRect(b.x-2,b.y-6,4,12);ctx.fillStyle='#FF0000';ctx.fillRect(b.x-1,b.y-3,2,6);});
  enemies.forEach(e=>{drawPixel(SPRITES[e.type],e.x,e.y,e.type==='boss'?3:3);});
  powers.forEach(p=>{
    ctx.fillStyle=p.kind==='shield'?'#00FFFF':'#FF00FF';
    ctx.fillRect(p.x-10,p.y-10,20,20);ctx.fillStyle='#fff';ctx.font='bold 12px Tahoma';ctx.textAlign='center';ctx.fillText(p.kind==='shield'?'🛡':'⚡',p.x,p.y+4);
  });
  drops.forEach(d=>{ctx.fillStyle='#FFD700';ctx.fillRect(d.x-7,d.y-7,14,14);ctx.fillStyle='#000';ctx.font='bold 11px Tahoma';ctx.textAlign='center';ctx.fillText('$',d.x,d.y+4);});
  parts.forEach(p=>{ctx.fillStyle=p.c;ctx.fillRect(p.x,p.y,4,4);});
  drawPixel(SPRITES.player,player.x,player.y,3);
  if(shield>0){ctx.strokeStyle='#00FFFF';ctx.lineWidth=3;ctx.beginPath();ctx.arc(player.x,player.y,32,0,Math.PI*2);ctx.stroke();}
  ctx.restore();
}
updateHUD(); drawStart();
requestAnimationFrame(loop);
</script>
</body>
</html>

Game Source: LOOM GALAXY ATTACK V2 - PIXEL

Creator: MegaOtter89

Libraries: none

Complexity: complex (220 lines, 10.3 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: loom-galaxy-attack-v2-pixel-megaotter89" to link back to the original. Then publish at arcadelab.ai/publish.