🎮ArcadeLab

LOOM GALAXY ATTACK

by ChromeFlame24
552 lines16.2 KB
▶ Play

<!DOCTYPE html>
<html lang="ar">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<title>LOOM GALAXY ATTACK</title>
<style>
*{box-sizing:border-box}
body{margin:0;background:#05020d;color:white;font-family:Arial;overflow:hidden;touch-action:none}
canvas{display:block;width:100vw;height:100dvh;touch-action:none}
.hud{position:absolute;top:9px;left:10px;right:10px;display:flex;justify-content:space-between;font-size:13px;font-weight:bold;text-shadow:0 0 10px #ffb52d;pointer-events:none}
#bossHud{position:absolute;top:63px;left:15%;width:70%;display:none;text-align:center;font-size:12px}
#bossBar{height:10px;background:#351b36;border:1px solid #ffc45b;border-radius:10px;overflow:hidden}
#bossFill{height:100%;width:100%;background:linear-gradient(90deg,#ff3030,#ffbd39)}
button{background:#24133c;color:white;border:1px solid #e8a83f;border-radius:12px;padding:10px 15px;font-weight:bold}
#pause{position:absolute;top:40px;right:10px}
#bomb{position:absolute;bottom:25px;right:15px;background:#8b1f44;border-color:#ffb34d}
#menu{position:absolute;inset:0;display:flex;flex-direction:column;justify-content:center;align-items:center;text-align:center;background:radial-gradient(ellipse,#291044,#080313 75%);padding:25px}
#menu h1{font-size:36px;line-height:1.15;color:#ffda80;text-shadow:0 0 12px #ff9d22,0 3px 5px #000}
#menu p{color:#e8d9ff;line-height:1.8}
#menu button{padding:15px 35px;background:linear-gradient(120deg,#8a3a9f,#9a5117);font-size:19px}
#upgrade{position:absolute;top:100px;left:0;right:0;text-align:center;color:#ffda75;font-weight:bold;text-shadow:0 0 12px orange;pointer-events:none}
#hint{position:absolute;bottom:8px;left:12px;color:#c5b4db;font-size:11px;pointer-events:none}
</style>
</head>
<body>
<canvas id="c"></canvas>
<div class="hud">
 <span>⭐ <b id="score">0</b></span>
 <span>⚡ LV <b id="lv">1</b></span>
 <span>❤️ <b id="life">3</b></span>
 <span>💣 <b id="bombs">2</b></span>
</div>
<div id="bossHud">
 <div id="bossName">BOSS</div>
 <div id="bossBar"><div id="bossFill"></div></div>
</div>
<button id="pause">Ⅱ</button>
<button id="bomb">💣 قنبلة</button>
<div id="upgrade"></div>
<div id="hint">اسحب إصبعك لتحريك السفينة</div>
<div id="menu">
 <h1>LOOM<br>GALAXY ATTACK</h1>
 <p>معركة المجرات بدأت!<br>قاتل الأعداء واهزم ملوك الفضاء.</p>
 <p>🚀 أسلحة متطورة • 👾 زعماء • 💥 قنابل</p>
 <button id="start">ابدأ المعركة</button>
 <p>أفضل نتيجة: <b id="best">0</b></p>
</div>

<script>
const c=document.getElementById("c"),ctx=c.getContext("2d");
const $=id=>document.getElementById(id);
let W,H,D;
function resize(){
 D=Math.min(devicePixelRatio||1,2);
 W=innerWidth;H=innerHeight;
 c.width=W*D;c.height=H*D;
 ctx.setTransform(D,0,0,D,0,0);
}
resize();addEventListener("resize",resize);

let score=0,life=3,level=1,weapon=1,bombs=2;
let running=false,paused=false,muted=false;
let enemies=[],shots=[],missiles=[],particles=[],stars=[];
let boss=null,spawn=0,fire=0,last=0,nextBoss=180;
let best=Number(localStorage.getItem("loomBest")||0);
$("best").textContent=best;

const player={x:W/2,y:H-115,tx:W/2,ty:H-115};

const bossTypes=[
 {name:"VOID DRAGON",color:"#b43dff",hp:65,speed:90},
 {name:"IRON TITAN",color:"#ff8533",hp:95,speed:65},
 {name:"GALAXY DESTROYER",color:"#36caff",hp:120,speed:75},
 {name:"KING OF SPACE",color:"#ffcf43",hp:155,speed:100}
];

function rand(a,b){return Math.random()*(b-a)+a}
function clamp(v,a,b){return Math.max(a,Math.min(b,v))}
function initStars(){
 stars=Array.from({length:150},()=>({
 x:rand(0,W),y:rand(0,H),r:rand(.5,2),
 speed:rand(20,100),a:rand(.2,1)
 }));
}
initStars();

function sound(f=500){
 if(muted)return;
 try{
 let ac=window.ac||(window.ac=new AudioContext());
 let o=ac.createOscillator(),g=ac.createGain();
 o.frequency.value=f;
 g.gain.value=.04;
 g.gain.exponentialRampToValueAtTime(.001,ac.currentTime+.15);
 o.connect(g);g.connect(ac.destination);
 o.start();o.stop(ac.currentTime+.15);
 }catch(e){}
}

function glow(color,blur=15){
 ctx.shadowColor=color;ctx.shadowBlur=blur;
}
function noGlow(){ctx.shadowBlur=0}

function background(dt){
 let g=ctx.createLinearGradient(0,0,W,H);
 g.addColorStop(0,"#10071e");
 g.addColorStop(.5,"#07091d");
 g.addColorStop(1,"#180b2b");
 ctx.fillStyle=g;ctx.fillRect(0,0,W,H);

 // السديم الفضائي
 for(let i=0;i<4;i++){
 let x=W*(.18+i*.23),y=H*(.2+(i%2)*.4);
 let neb=ctx.createRadialGradient(x,y,1,x,y,110);
 neb.addColorStop(0,"#49206b55");
 neb.addColorStop(1,"#15082100");
 ctx.fillStyle=neb;ctx.fillRect(x-110,y-110,220,220);
 }

 // شعاع الليزر الأحمر
 let lx=W/2+Math.sin(performance.now()/1300)*W*.22;
 let beam=ctx.createLinearGradient(lx-12,0,lx+12,0);
 beam.addColorStop(0,"#ff140000");
 beam.addColorStop(.5,"#ff302044");
 beam.addColorStop(1,"#ff140000");
 ctx.fillStyle=beam;ctx.fillRect(lx-12,0,24,H);

 stars.forEach(s=>{
 s.y+=s.speed*dt;
 if(s.y>H){s.y=0;s.x=rand(0,W)}
 ctx.globalAlpha=s.a;
 ctx.fillStyle="#e4d8ff";
 ctx.fillRect(s.x,s.y,s.r,s.r);
 });
 ctx.globalAlpha=1;
}

// السفينة الذهبية
function drawShip(x,y){
 ctx.save();ctx.translate(x,y);
 // المحركات
 for(let k of [-1,1]){
 ctx.fillStyle="#b44bff";
 glow("#ff8c24",16);
 ctx.beginPath();ctx.ellipse(k*14,19,5,13,0,0,7);ctx.fill();
 }
 noGlow();
 // الأجنحة
 ctx.fillStyle="#a65a23";
 ctx.strokeStyle="#ffe3a1";ctx.lineWidth=2;
 ctx.beginPath();
 ctx.moveTo(-7,-16);ctx.lineTo(-37,20);ctx.lineTo(-28,31);
 ctx.lineTo(-5,20);ctx.closePath();ctx.fill();ctx.stroke();
 ctx.beginPath();
 ctx.moveTo(7,-16);ctx.lineTo(37,20);ctx.lineTo(28,31);
 ctx.lineTo(5,20);ctx.closePath();ctx.fill();ctx.stroke();
 // جسم
 let g=ctx.createLinearGradient(-18,-35,18,30);
 g.addColorStop(0,"#fff4b0");g.addColorStop(.45,"#dca444");g.addColorStop(1,"#572d72");
 ctx.fillStyle=g;
 ctx.beginPath();ctx.moveTo(0,-42);ctx.lineTo(17,4);
 ctx.lineTo(10,32);ctx.lineTo(0,25);ctx.lineTo(-10,32);
 ctx.lineTo(-17,4);ctx.closePath();ctx.fill();ctx.stroke();
 // الزجاج
 ctx.fillStyle="#6ef4ff";glow("#31dfff",14);
 ctx.beginPath();ctx.ellipse(0,-14,6,14,0,0,7);ctx.fill();
 noGlow();
 ctx.restore();
}

// أنواع الأعداء
function drawEnemy(e){
 ctx.save();ctx.translate(e.x,e.y);
 let color=["#db47c7","#43d5ff","#ff8e3a","#9c70ff","#c8ff56"][e.type];
 glow(color,13);
 if(e.type===0){
 // مقاتل مجنح
 ctx.fillStyle="#922cba";
 ctx.beginPath();ctx.moveTo(0,-20);ctx.lineTo(28,12);
 ctx.lineTo(10,9);ctx.lineTo(0,19);ctx.lineTo(-10,9);
 ctx.lineTo(-28,12);ctx.closePath();ctx.fill();
 }else if(e.type===1){
 // حشرة فضائية
 ctx.fillStyle="#168a9c";
 ctx.beginPath();ctx.ellipse(0,0,18,21,0,0,7);ctx.fill();
 ctx.strokeStyle="#9bffff";ctx.lineWidth=3;
 for(let k of [-1,1]){
 ctx.beginPath();ctx.moveTo(k*12,5);ctx.lineTo(k*30,24);ctx.stroke();
 ctx.beginPath();ctx.moveTo(k*10,-8);ctx.lineTo(k*24,-23);ctx.stroke();
 }
 }else if(e.type===2){
 // مدرعة
 ctx.fillStyle="#ad4c26";
 ctx.beginPath();ctx.moveTo(0,-23);ctx.lineTo(23,-10);
 ctx.lineTo(20,17);ctx.lineTo(0,24);ctx.lineTo(-20,17);
 ctx.lineTo(-23,-10);ctx.closePath();ctx.fill();
 ctx.fillStyle="#ffe16c";ctx.fillRect(-9,-7,18,6);
 }else if(e.type===3){
 // قاذف صواريخ
 ctx.fillStyle="#8e42aa";
 ctx.beginPath();ctx.roundRect(-18,-21,36,42,9);ctx.fill();
 ctx.fillStyle="#ffb63c";
 ctx.fillRect(-14,-18,7,17);ctx.fillRect(7,-18,7,17);
 ctx.fillStyle="#ffffff";ctx.fillRect(-5,1,10,5);
 }else{
 // ثقيل
 ctx.fillStyle="#427a39";
 ctx.beginPath();ctx.ellipse(0,0,27,20,0,0,7);ctx.fill();
 ctx.fillStyle="#caff55";
 ctx.beginPath();ctx.arc(0,-3,9,0,7);ctx.fill();
 }
 noGlow();ctx.restore();
}

// أربعة أنواع زعماء
function drawBoss(b){
 ctx.save();ctx.translate(b.x,b.y);
 let col=b.data.color;
 glow(col,23);

 // شكل الزعيم يختلف حسب النوع
 if(b.type===0){
 // التنين
 ctx.fillStyle="#53206f";
 ctx.beginPath();
 ctx.moveTo(0,-52);ctx.lineTo(30,-20);
 ctx.lineTo(100,-65);ctx.lineTo(75,8);
 ctx.lineTo(30,34);ctx.lineTo(0,50);
 ctx.lineTo(-30,34);ctx.lineTo(-75,8);
 ctx.lineTo(-100,-65);ctx.lineTo(-30,-20);ctx.closePath();ctx.fill();
 ctx.fillStyle="#ff62eb";
 ctx.beginPath();ctx.ellipse(0,-18,30,28,0,0,7);ctx.fill();
 }else if(b.type===1){
 // الروبوت العملاق
 ctx.fillStyle="#9c482e";
 ctx.fillRect(-70,-34,140,75);
 ctx.fillStyle="#f3a34c";
 ctx.fillRect(-48,-55,96,42);
 ctx.fillStyle="#fff16d";
 ctx.fillRect(-31,-42,16,9);ctx.fillRect(15,-42,16,9);
 ctx.fillStyle="#63334a";
 ctx.fillRect(-94,-25,30,42);ctx.fillRect(64,-25,30,42);
 }else if(b.type===2){
 // سفينة حربية
 ctx.fillStyle="#177d9e";
 ctx.beginPath();ctx.moveTo(0,-58);ctx.lineTo(115,5);
 ctx.lineTo(70,43);ctx.lineTo(-70,43);ctx.lineTo(-115,5);ctx.closePath();ctx.fill();
 ctx.fillStyle="#8ef5ff";
 ctx.fillRect(-23,-35,46,38);
 }else{
 // ملك المجرات
 ctx.fillStyle="#9b5821";
 ctx.beginPath();ctx.moveTo(0,-65);ctx.lineTo(30,-25);
 ctx.lineTo(88,-35);ctx.lineTo(70,25);ctx.lineTo(0,55);
 ctx.lineTo(-70,25);ctx.lineTo(-88,-35);ctx.lineTo(-30,-25);ctx.closePath();ctx.fill();
 ctx.fillStyle="#ffdf55";
 ctx.beginPath();ctx.arc(0,-10,24,0,7);ctx.fill();
 ctx.fillStyle="#fff";
 ctx.fillRect(-17,-14,9,6);ctx.fillRect(8,-14,9,6);
 }
 noGlow();
 // المدافع
 ctx.fillStyle=col;
 ctx.beginPath();ctx.arc(-48,15,13,0,7);ctx.fill();
 ctx.beginPath();ctx.arc(48,15,13,0,7);ctx.fill();
 ctx.restore();
}

// الصواريخ والطلقات
function drawProjectiles(){
 shots.forEach(s=>{
 glow(s.power>1?"#ffae34":"#49eaff",15);
 ctx.fillStyle=s.power>1?"#ffdf76":"#d9ffff";
 ctx.beginPath();ctx.ellipse(s.x,s.y,4,s.power>1?12:8,0,0,7);ctx.fill();
 });
 noGlow();
 missiles.forEach(m=>{
 ctx.save();ctx.translate(m.x,m.y);
 ctx.rotate(Math.atan2(m.vy,m.vx)+Math.PI/2);
 glow("#ff3d50",12);
 ctx.fillStyle="#ffb7a8";
 ctx.beginPath();ctx.moveTo(0,-10);ctx.lineTo(6,8);ctx.lineTo(0,5);ctx.lineTo(-6,8);ctx.closePath();ctx.fill();
 ctx.fillStyle="#ff6a18";
 ctx.fillRect(-3,7,6,8);
 noGlow();ctx.restore();
 });
}

// انفجارات
function explode(x,y,color){
 for(let i=0;i<30;i++){
 let a=rand(0,7),v=rand(40,240);
 particles.push({x,y,vx:Math.cos(a)*v,vy:Math.sin(a)*v,
 life:rand(.3,.85),max:.85,color,r:rand(2,7)});
 }
}
function drawParticles(dt){
 particles.forEach(p=>{
 p.x+=p.vx*dt;p.y+=p.vy*dt;p.life-=dt;
 ctx.globalAlpha=clamp(p.life/p.max,0,1);
 ctx.fillStyle=p.color;glow(p.color,10);
 ctx.beginPath();ctx.arc(p.x,p.y,p.r,0,7);ctx.fill();
 });
 noGlow();ctx.globalAlpha=1;
 particles=particles.filter(p=>p.life>0);
}

function makeEnemy(){
 let type=Math.floor(rand(0,Math.min(5,2+Math.floor(level/2))));
 enemies.push({
 x:rand(35,W-35),y:-35,
 speed:rand(65,110)+level*7,
 type,hp:type===2?2:1
 });
}

function makeBoss(){
 let type=Math.floor(rand(0,bossTypes.length));
 let data=bossTypes[type];
 boss={x:W/2,y:-110,tx:W/2,type,data,
 hp:data.hp+level*12,max:data.hp+level*12,
 fire:.7,speed:data.speed,dir:1};
 enemies=[];
 missiles=[];
 $("bossHud").style.display="block";
 $("bossName").textContent=data.name;
 sound(120);
}

function firePlayer(){
 let spread=weapon>=3?[-18,0,18]:weapon===2?[-9,9]:[0];
 spread.forEach(x=>shots.push({
 x:player.x+x,y:player.y-35,
 power:weapon>=4?3:weapon>=2?2:1,
 speed:650
 }));
 sound(650);
}

function useBomb(){
 if(!running||paused||bombs<=0)return;
 bombs--;
 explode(player.x,player.y,"#fff05a");
 enemies.forEach(e=>explode(e.x,e.y,"#ff8c32"));
 enemies=[];missiles=[];
 if(boss){
 boss.hp-=35+weapon*12;
 if(boss.hp<=0)defeatBoss();
 }
 sound(180);
 $("bombs").textContent=bombs;
}

function defeatBoss(){
 if(!boss)return;
 explode(boss.x,boss.y,boss.data.color);
 score+=300;
 boss=null;
 $("bossHud").style.display="none";
 bombs=Math.min(5,bombs+1);
 $("bombs").textContent=bombs;
 sound(100);
 nextBoss=score+250;
}

function upgrade(){
 let newLevel=1+Math.floor(score/100);
 newLevel=Math.min(5,newLevel);
 if(newLevel>weapon){
 weapon=newLevel;
 $("upgrade").textContent="⚡ تطوير السلاح! LEVEL "+weapon;
 sound(950);
 setTimeout(()=>{$("upgrade").textContent=""},1800);
 }
 level=Math.max(1,1+Math.floor(score/180));
}

function update(dt){
 if(!running||paused)return;

 player.x+=(player.tx-player.x)*Math.min(1,dt*14);
 player.y+=(player.ty-player.y)*Math.min(1,dt*14);
 player.x=clamp(player.x,30,W-30);
 player.y=clamp(player.y,H*.45,H-60);

 fire-=dt;
 if(fire<=0){firePlayer();fire=weapon>=3?.16:.25}

 spawn-=dt;
 if(!boss&&spawn<=0){
 makeEnemy();spawn=Math.max(.3,1-level*.06);
 }
 shots.forEach(s=>s.y-=s.speed*dt);
 shots=shots.filter(s=>s.y>-30);

 // حركة الأعداء واصطدامات الأسلحة
 for(let i=enemies.length-1;i>=0;i--){
 let e=enemies[i];e.y+=e.speed*dt;
 if(e.y>H+30){enemies.splice(i,1);life--;continue}
 let hit=false;
 for(let j=shots.length-1;j>=0;j--){
 if(Math.hypot(e.x-shots[j].x,e.y-shots[j].y)<24){
 e.hp-=shots[j].power;shots.splice(j,1);hit=true;
 if(e.hp<=0){
 explode(e.x,e.y,"#ff9a4b");
 enemies.splice(i,1);score+=10;
 }
 break;
 }
 }
 if(enemies[i]&&Math.hypot(e.x-player.x,e.y-player.y)<30){
 explode(e.x,e.y,"#ff4c75");
 enemies.splice(i,1);life--;
 }
 }

 // دخول الزعيم
 if(!boss&&score>=nextBoss)makeBoss();

 if(boss){
 boss.y=Math.min(135,boss.y+boss.speed*dt);
 boss.x+=boss.dir*boss.speed*dt;
 if(boss.x>W-115||boss.x<115)boss.dir*=-1;

 boss.fire-=dt;
 if(boss.fire<=0){
 // نمط إطلاق يتغير حسب الزعيم
 let count=boss.type===2?7:boss.type===3?9:5;
 for(let i=0;i<count;i++){
 let a=(i-(count-1)/2)*.18;
 let vx=Math.sin(a)*150;
 let vy=190+Math.abs(vx)*.3;
 missiles.push({x:boss.x,y:boss.y+40,vx,vy});
 }
 boss.fire= boss.type===3?.55:.85;
 }

 for(let j=shots.length-1;j>=0;j--){
 let s=shots[j];
 if(Math.hypot(boss.x-s.x,boss.y-s.y)<85){
 boss.hp-=s.power*2;
 shots.splice(j,1);
 if(boss.hp<=0){defeatBoss();break}
 }
 }
 $("bossFill").style.width=(boss?Math.max(0,boss.hp/boss.max*100):0)+"%";
 }

 missiles.forEach(m=>{
 let dx=player.x-m.x,dy=player.y-m.y;
 let d=Math.hypot(dx,dy)||1;
 m.vx+=dx/d*45*dt;
 m.vy+=dy/d*45*dt;
 let speed=Math.hypot(m.vx,m.vy);
 m.vx=m.vx/speed*210;m.vy=m.vy/speed*210;
 m.x+=m.vx*dt;m.y+=m.vy*dt;
 });
 for(let i=missiles.length-1;i>=0;i--){
 let m=missiles[i];
 if(m.y>H+30||m.x<0||m.x>W){missiles.splice(i,1);continue}
 if(Math.hypot(m.x-player.x,m.y-player.y)<24){
 missiles.splice(i,1);life--;
 explode(player.x,player.y,"#ff4a72");
 }
 }

 upgrade();
 $("score").textContent=score;
 $("life").textContent=life;
 $("lv").textContent=weapon;
 $("bombs").textContent=bombs;
 if(life<=0)gameOver();
}

function draw(dt){
 background(dt);
 drawProjectiles();
 enemies.forEach(drawEnemy);
 if(boss)drawBoss(boss);
 drawParticles(dt);
 if(life>0)drawShip(player.x,player.y);
}

function loop(t){
 let dt=Math.min((t-last)/1000||0,.04);
 last=t;
 update(dt);draw(dt);
 requestAnimationFrame(loop);
}
requestAnimationFrame(loop);

function start(){
 score=0;life=3;level=1;weapon=1;bombs=2;
 enemies=[];shots=[];missiles=[];particles=[];
 boss=null;spawn=0;fire=0;nextBoss=180;
 player.x=W/2;player.y=H-115;
 player.tx=player.x;player.ty=player.y;
 running=true;paused=false;
 $("menu").style.display="none";
 $("bossHud").style.display="none";
 $("pause").textContent="Ⅱ";
 $("upgrade").textContent="";
}

function gameOver(){
 running=false;
 best=Math.max(best,score);
 localStorage.setItem("loomBest",best);
 $("best").textContent=best;
 $("menu").innerHTML=`
 <h1>GAME OVER</h1>
 <p>نتيجتك: ${score}</p>
 <p>أفضل نتيجة: ${best}</p>
 <button id="again">حاول مرة أخرى 🚀</button>`;
 $("menu").style.display="flex";
 $("again").onclick=start;
}

// تحكم السحب
let dragging=false;
function move(e){
 let r=c.getBoundingClientRect();
 player.tx=e.clientX-r.left;
 player.ty=e.clientY-r.top;
}
c.addEventListener("pointerdown",e=>{
 dragging=true;c.setPointerCapture(e.pointerId);move(e);
});
c.addEventListener("pointermove",e=>{if(dragging)move(e)});
c.addEventListener("pointerup",()=>dragging=false);
c.addEventListener("pointercancel",()=>dragging=false);

$("start").onclick=start;
$("bomb").onclick=useBomb;
$("pause").onclick=()=>{
 if(!running)return;
 paused=!paused;
 $("pause").textContent=paused?"▶":"Ⅱ";
};
$("mute").onclick=()=>{
 muted=!muted;$("mute").textContent=muted?"🔇":"🔊";
};
addEventListener("keydown",e=>{
 if(e.key==="b"||e.key==="B")useBomb();
 if(e.key==="Escape"){$("pause").click()}
});
</script>
</body>
</html>

Game Source: LOOM GALAXY ATTACK

Creator: ChromeFlame24

Libraries: none

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