🎮ArcadeLab

هجوم المجرات

by ChromeFlame24
466 lines12.6 KB
▶ Play

<!DOCTYPE html>
<html lang="ar" 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:#030611;color:white;font-family:Arial;overflow:hidden;touch-action:none}
#game{width:100vw;height:100dvh;display:block;touch-action:none}
.hud{position:absolute;top:12px;left:12px;right:12px;display:flex;justify-content:space-between;font-weight:bold;text-shadow:0 0 10px #00dfff;pointer-events:none}
button{border:1px solid #40dfff;background:#10254c;color:white;padding:10px 16px;border-radius:12px;font-size:16px}
#pause{position:absolute;top:48px;right:12px}
#mute{position:absolute;top:48px;left:12px}
#menu{position:absolute;inset:0;background:#020617eF;display:flex;align-items:center;justify-content:center;flex-direction:column;text-align:center;padding:25px}
#menu h1{font-size:38px;color:#48eaff;text-shadow:0 0 25px #008cff}
#menu p{line-height:1.8;color:#cbd5e1}
#menu button{background:#642ce2;padding:15px 35px;font-weight:bold}
</style>
</head>
<body>
<canvas id="game"></canvas>
<div class="hud">
 <span>⭐ <b id="score">0</b></span>
 <span>❤️ <b id="life">3</b></span>
 <span>LEVEL <b id="level">1</b></span>
</div>
<button id="pause">Ⅱ</button>
<button id="mute">🔊</button>
<div id="menu">
 <h1>🚀 هجوم المجرات</h1>
 <p>قاتل جيوش الفضائيين وواجه الزعماء العملاقة!</p>
 <p>اسحب إصبعك لتحريك السفينة وأطلق النار تلقائياً.</p>
 <button id="start">ابدأ القتال</button>
 <p>أفضل نتيجة: <b id="best">0</b></p>
</div>
<script>
const c=document.getElementById("game");
const 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;
let running=false,paused=false,muted=false;
let bullets=[],enemies=[],particles=[],stars=[],boss=null;
let timer=0,shootTimer=0,last=0;
let best=Number(localStorage.getItem("galaxyBest")||0);
$("best").textContent=best;

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

function random(a,b){return Math.random()*(b-a)+a}

function gradient(x,y,r,color1,color2){
 let g=ctx.createRadialGradient(x-r*.3,y-r*.4,1,x,y,r);
 g.addColorStop(0,color1);g.addColorStop(1,color2);
 return g;
}

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

function background(dt){
 ctx.fillStyle="#030817";
 ctx.fillRect(0,0,W,H);
 let bg=ctx.createRadialGradient(W/2,H*.4,10,W/2,H*.4,H);
 bg.addColorStop(0,"#17254a");
 bg.addColorStop(1,"#030817");
 ctx.fillStyle=bg;ctx.fillRect(0,0,W,H);

 stars.forEach(s=>{
 s.y+=s.v*dt;
 if(s.y>H){s.y=0;s.x=random(0,W)}
 ctx.globalAlpha=s.a;
 ctx.fillStyle="#bceeff";
 ctx.beginPath();ctx.arc(s.x,s.y,s.r,0,Math.PI*2);ctx.fill();
 });
 ctx.globalAlpha=1;
}

function initStars(){
 stars=Array.from({length:130},()=>({
 x:random(0,W),y:random(0,H),
 r:random(.5,2),v:random(20,100),a:random(.2,.9)
 }));
}
initStars();

// سفينة اللاعب بتفاصيل معدنية
function drawShip(x,y,scale=1){
 ctx.save();ctx.translate(x,y);ctx.scale(scale,scale);

 // محركات
 for(let side of [-1,1]){
 ctx.fillStyle="#243c71";
 ctx.beginPath();ctx.ellipse(side*15,15,8,17,0,0,7);ctx.fill();
 ctx.fillStyle="#00dfff";
 ctx.shadowColor="#00dfff";ctx.shadowBlur=20;
 ctx.beginPath();ctx.ellipse(side*15,28,4,random(12,22),0,0,7);ctx.fill();
 }
 ctx.shadowBlur=0;

 // الأجنحة
 ctx.fillStyle="#b92c67";
 ctx.beginPath();
 ctx.moveTo(-7,-8);ctx.lineTo(-39,24);ctx.lineTo(-29,34);
 ctx.lineTo(-5,20);ctx.fill();
 ctx.beginPath();
 ctx.moveTo(7,-8);ctx.lineTo(39,24);ctx.lineTo(29,34);
 ctx.lineTo(5,20);ctx.fill();

 // الجسم
 ctx.fillStyle=gradient(0,0,43,"#ffffff","#142c68");
 ctx.beginPath();
 ctx.moveTo(0,-42);ctx.bezierCurveTo(23,-20,22,12,9,32);
 ctx.lineTo(0,39);ctx.lineTo(-9,32);
 ctx.bezierCurveTo(-22,12,-23,-20,0,-42);
 ctx.fill();

 // درع معدني
 ctx.strokeStyle="#70edff";ctx.lineWidth=2;
 ctx.beginPath();ctx.moveTo(0,-35);ctx.lineTo(0,28);ctx.stroke();

 // قمرة القيادة
 ctx.fillStyle=gradient(0,-14,15,"#d9ffff","#0574b8");
 ctx.beginPath();ctx.ellipse(0,-12,8,16,0,0,7);ctx.fill();

 // تفاصيل الأجنحة
 ctx.fillStyle="#ffcf59";
 ctx.fillRect(-29,21,8,3);ctx.fillRect(21,21,8,3);

 ctx.restore();
}

// عدو فضائي مرسوم
function drawAlien(e){
 ctx.save();ctx.translate(e.x,e.y);
 let s=e.scale||1;ctx.scale(s,s);

 // أجنحة
 ctx.fillStyle="#6220a9";
 ctx.beginPath();
 ctx.moveTo(-10,-3);ctx.lineTo(-39,-27);
 ctx.lineTo(-31,5);ctx.lineTo(-12,14);ctx.fill();
 ctx.beginPath();
 ctx.moveTo(10,-3);ctx.lineTo(39,-27);
 ctx.lineTo(31,5);ctx.lineTo(12,14);ctx.fill();

 // الجسم
 ctx.fillStyle=gradient(0,0,30,"#ff8ce9","#5c1b91");
 ctx.beginPath();ctx.ellipse(0,0,22,17,0,0,7);ctx.fill();

 // الرأس
 ctx.fillStyle=gradient(0,-10,20,"#f5d6ff","#8526ae");
 ctx.beginPath();ctx.ellipse(0,-8,16,13,0,0,7);ctx.fill();

 // العيون
 ctx.fillStyle="#ffed55";
 ctx.shadowColor="#ff3cda";ctx.shadowBlur=12;
 ctx.beginPath();ctx.ellipse(-7,-9,4,6,0,0,7);ctx.fill();
 ctx.beginPath();ctx.ellipse(7,-9,4,6,0,0,7);ctx.fill();
 ctx.shadowBlur=0;

 // قرون
 ctx.strokeStyle="#e4a7ff";ctx.lineWidth=3;
 ctx.beginPath();ctx.moveTo(-9,-17);ctx.lineTo(-16,-29);
 ctx.moveTo(9,-17);ctx.lineTo(16,-29);ctx.stroke();

 // محركات
 ctx.fillStyle="#00eaff";
 ctx.beginPath();ctx.arc(-12,15,4,0,7);ctx.fill();
 ctx.beginPath();ctx.arc(12,15,4,0,7);ctx.fill();

 ctx.restore();
}

// زعيم عملاق
function drawBoss(b){
 ctx.save();ctx.translate(b.x,b.y);
 let pulse=Math.sin(performance.now()/180)*3;

 // أجنحة ضخمة
 ctx.fillStyle="#35134f";
 ctx.beginPath();
 ctx.moveTo(-35,-20);ctx.lineTo(-105,-55);
 ctx.lineTo(-88,30);ctx.lineTo(-43,42);ctx.fill();
 ctx.beginPath();
 ctx.moveTo(35,-20);ctx.lineTo(105,-55);
 ctx.lineTo(88,30);ctx.lineTo(43,42);ctx.fill();

 // كتفين
 for(let s of [-1,1]){
 ctx.fillStyle=gradient(s*55,0,45,"#ffd76b","#672a34");
 ctx.beginPath();ctx.ellipse(s*55,-5,32,38,s*.3,0,7);ctx.fill();
 ctx.fillStyle="#ff9a30";
 ctx.beginPath();ctx.arc(s*55,-5,11,0,7);ctx.fill();
 ctx.shadowColor="#ff5b00";ctx.shadowBlur=20;
 ctx.beginPath();ctx.arc(s*55,-5,6,0,7);ctx.fill();
 ctx.shadowBlur=0;
 }

 // جسم الزعيم
 ctx.fillStyle=gradient(0,0,70,"#ffb84b","#38123d");
 ctx.beginPath();
 ctx.moveTo(0,-65);ctx.lineTo(43,-30);
 ctx.lineTo(37,36);ctx.lineTo(0,57);
 ctx.lineTo(-37,36);ctx.lineTo(-43,-30);
 ctx.closePath();ctx.fill();

 // الرأس
 ctx.fillStyle=gradient(0,-35,40,"#ffdf83","#8d263c");
 ctx.beginPath();ctx.moveTo(0,-65);ctx.lineTo(30,-35);
 ctx.lineTo(20,-5);ctx.lineTo(0,7);
 ctx.lineTo(-20,-5);ctx.lineTo(-30,-35);ctx.closePath();ctx.fill();

 // عيون
 ctx.shadowColor="#a9ffff";ctx.shadowBlur=18;
 ctx.fillStyle="#48faff";
 ctx.beginPath();ctx.ellipse(-12,-32,7,4,0,0,7);ctx.fill();
 ctx.beginPath();ctx.ellipse(12,-32,7,4,0,0,7);ctx.fill();
 ctx.shadowBlur=0;

 // قلب الطاقة
 ctx.fillStyle="#ffed4b";
 ctx.shadowColor="#ff8c00";ctx.shadowBlur=22;
 ctx.beginPath();ctx.arc(0,20,12+pulse*.3,0,7);ctx.fill();
 ctx.shadowBlur=0;
 ctx.restore();
}

// انفجارات
function explode(x,y,color="#ffae38"){
 for(let i=0;i<24;i++){
 let a=random(0,Math.PI*2),v=random(40,230);
 particles.push({
 x,y,vx:Math.cos(a)*v,vy:Math.sin(a)*v,
 life:random(.3,.8),max:.8,color,r:random(2,6)
 });
 }
}

function drawParticles(dt){
 particles.forEach(p=>{
 p.x+=p.vx*dt;p.y+=p.vy*dt;p.life-=dt;
 ctx.globalAlpha=Math.max(0,p.life/p.max);
 ctx.fillStyle=p.color;
 ctx.shadowColor=p.color;ctx.shadowBlur=12;
 ctx.beginPath();ctx.arc(p.x,p.y,p.r,0,7);ctx.fill();
 });
 ctx.globalAlpha=1;ctx.shadowBlur=0;
 particles=particles.filter(p=>p.life>0);
}

function spawnEnemy(){
 enemies.push({
 x:random(40,W-40),y:-45,
 speed:random(65,105)+level*9,
 scale:random(.8,1.15),hp:1
 });
}

function shoot(){
 bullets.push({x:ship.x-10,y:ship.y-35,v:600});
 bullets.push({x:ship.x+10,y:ship.y-35,v:600});
 sound(750);
}

function spawnBoss(){
 boss={x:W/2,y:-100,hp:35+level*10,max:35+level*10,
 speed:65,dir:1,fire:0};
 enemies=[];
}

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

 // سحب سلس للسفينة
 ship.x+=(ship.tx-ship.x)*Math.min(1,dt*13);
 ship.y+=(ship.ty-ship.y)*Math.min(1,dt*13);
 ship.x=Math.max(35,Math.min(W-35,ship.x));
 ship.y=Math.max(H*.48,Math.min(H-65,ship.y));

 shootTimer-=dt;
 if(shootTimer<=0){shoot();shootTimer=.24}

 bullets.forEach(b=>b.y-=b.v*dt);
 bullets=bullets.filter(b=>b.y>-30);

 timer-=dt;
 if(!boss&&timer<=0){
 spawnEnemy();timer=Math.max(.32,1-level*.055);
 }

 enemies.forEach(e=>e.y+=e.speed*dt);

 for(let i=enemies.length-1;i>=0;i--){
 let e=enemies[i];
 if(e.y>H+40){enemies.splice(i,1);life--;continue}
 for(let j=bullets.length-1;j>=0;j--){
 if(Math.hypot(e.x-bullets[j].x,e.y-bullets[j].y)<25){
 explode(e.x,e.y);
 enemies.splice(i,1);bullets.splice(j,1);
 score+=10;break;
 }
 }
 if(enemies[i]&&Math.hypot(e.x-ship.x,e.y-ship.y)<36){
 explode(e.x,e.y);
 enemies.splice(i,1);life--;
 }
 }

 if(!boss&&score>0&&score%250===0){
 spawnBoss();
 }

 if(boss){
 boss.y+=(boss.y<130?boss.speed:-boss.speed*.15)*dt;
 if(boss.y>145)boss.y=145;
 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){
 // طلقات الزعيم تتجه نحو الأسفل
 for(let k=-1;k<=1;k++){
 enemyShots.push({x:boss.x+k*25,y:boss.y+55,v:190});
 }
 boss.fire=1.1;
 }

 for(let i=bullets.length-1;i>=0;i--){
 if(Math.hypot(boss.x-bullets[i].x,boss.y-bullets[i].y)<85){
 boss.hp--;bullets.splice(i,1);
 if(boss.hp<=0){
 explode(boss.x,boss.y,"#ffb52e");
 score+=200;boss=null;level++;
 sound(180);
 break;
 }
 }
 }
 }

 enemyShots.forEach(b=>b.y+=b.v*dt);
 for(let i=enemyShots.length-1;i>=0;i--){
 let b=enemyShots[i];
 if(b.y>H){enemyShots.splice(i,1);continue}
 if(Math.hypot(b.x-ship.x,b.y-ship.y)<24){
 enemyShots.splice(i,1);life--;
 explode(ship.x,ship.y,"#40dfff");
 }
 }

 if(life<=0)gameOver();

 level=Math.max(1,1+Math.floor(score/250));
 $("score").textContent=score;
 $("life").textContent=life;
 $("level").textContent=level;
}

let enemyShots=[];

function draw(){
 background((performance.now()-last)/1000||0);
 bullets.forEach(b=>{
 ctx.shadowColor="#35faff";ctx.shadowBlur=18;
 ctx.fillStyle="#d8ffff";
 ctx.fillRect(b.x-3,b.y-12,6,23);
 });
 ctx.shadowBlur=0;

 enemies.forEach(drawAlien);
 if(boss){
 drawBoss(boss);
 ctx.fillStyle="#29213a";ctx.fillRect(W/2-95,30,190,10);
 ctx.fillStyle="#ff365b";
 ctx.fillRect(W/2-95,30,190*boss.hp/boss.max,10);
 ctx.strokeStyle="white";ctx.strokeRect(W/2-95,30,190,10);
 }
 enemyShots.forEach(b=>{
 ctx.fillStyle="#ff4b92";ctx.shadowColor="#ff0088";ctx.shadowBlur=15;
 ctx.beginPath();ctx.arc(b.x,b.y,6,0,7);ctx.fill();
 });
 ctx.shadowBlur=0;
 drawParticles(.016);
 if(life>0)drawShip(ship.x,ship.y);
}

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

function start(){
 score=0;life=3;level=1;
 bullets=[];enemies=[];enemyShots=[];particles=[];
 boss=null;timer=0;shootTimer=0;
 ship.x=W/2;ship.y=H-120;ship.tx=ship.x;ship.ty=ship.y;
 paused=false;running=true;
 $("menu").style.display="none";
 $("pause").textContent="Ⅱ";
}

function gameOver(){
 running=false;
 best=Math.max(best,score);
 localStorage.setItem("galaxyBest",best);
 $("menu").innerHTML=`
 <h1>انتهت المعركة!</h1>
 <p>نتيجتك: ${score}</p>
 <p>أفضل نتيجة: ${best}</p>
 <button id="again">إعادة اللعب 🚀</button>`;
 $("menu").style.display="flex";
 $("again").onclick=start;
}

// التحكم بالسحب بالإصبع أو الماوس
let dragging=false;
function move(e){
 const r=c.getBoundingClientRect();
 ship.tx=e.clientX-r.left;
 ship.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;
$("pause").onclick=()=>{
 if(!running)return;
 paused=!paused;
 $("pause").textContent=paused?"▶":"Ⅱ";
};
$("mute").onclick=()=>{
 muted=!muted;$("mute").textContent=muted?"🔇":"🔊";
};
</script>
</body>
</html>

Game Source: هجوم المجرات

Creator: ChromeFlame24

Libraries: none

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