GALAXY INVADERS
by ChromeFlame24478 lines9.6 KB
<!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>GALAXY INVADERS</title>
<style>
*{box-sizing:border-box}
body{
margin:0;background:#050510;color:white;
font-family:Arial;text-align:center;overflow:hidden;
}
h1{
color:#55eeff;letter-spacing:3px;
text-shadow:0 0 15px #00d9ff;
font-size:25px;margin:10px;
}
#hud{
display:flex;justify-content:space-around;
font-size:14px;padding:8px;color:#fff;
}
canvas{
width:96vw;height:auto;max-height:70vh;
aspect-ratio:3/2;
background:#080b22;border:2px solid #25dfff;
border-radius:10px;
box-shadow:0 0 25px #006eff55;
image-rendering:pixelated;
touch-action:none;
}
.controls{
display:flex;justify-content:center;gap:20px;
margin:8px;
}
button{
background:#101b3d;color:#4df5ff;
border:2px solid #25dfff;border-radius:12px;
padding:13px 25px;font-size:20px;
}
#message{color:#ffdf65;font-size:14px}
</style>
</head>
<body>
<h1>🚀 GALAXY INVADERS</h1>
<div id="hud">
<span>❤️ <b id="hp">3</b></span>
<span>⭐ <b id="score">0</b></span>
<span>LEVEL <b id="level">1</b></span>
</div>
<canvas id="game" width="900" height="600"></canvas>
<div class="controls">
<button id="left">◀</button>
<button id="fire">🔥 FIRE</button>
<button id="right">▶</button>
</div>
<p id="message">دافع عن المجرة! اقضِ على جيش الفضائيين!</p>
<script>
const canvas=document.getElementById("game");
const ctx=canvas.getContext("2d");
ctx.imageSmoothingEnabled=false;
const W=900,H=600;
let player,enemies,bullets,enemyBullets;
let particles,stars,score,level,hp;
let boss,bossBullets;
let keys={};
let gameOver=false;
let started=false;
let frame=0;
let moveTouch=0;
let firing=false;
const $=id=>document.getElementById(id);
function reset(){
player={x:435,y:510,w:36,h:36,speed:6};
enemies=[];
bullets=[];
enemyBullets=[];
bossBullets=[];
particles=[];
score=0;level=1;hp=3;
boss=null;gameOver=false;started=true;
makeEnemies();
updateHUD();
}
function makeEnemies(){
enemies=[];
// صفّان من الأعداء
for(let row=0;row<2;row++){
for(let col=0;col<12;col++){
enemies.push({
x:90+col*62,
y:75+row*65,
baseX:90+col*62,
row,
w:34,h:30,
alive:true,
phase:Math.random()*6
});
}
}
}
stars=Array.from({length:100},()=>({
x:Math.random()*W,
y:Math.random()*H,
s:Math.random()*2+1,
v:Math.random()*2+.5
}));
function updateHUD(){
$("hp").textContent=hp;
$("score").textContent=score;
$("level").textContent=level;
}
function rect(x,y,w,h,color){
ctx.fillStyle=color;
ctx.fillRect(Math.round(x),Math.round(y),w,h);
}
// رسم سفينة Pixel Art
function drawPlayer(){
ctx.shadowBlur=18;
ctx.shadowColor="#00eeff";
const p=player;
rect(p.x+12,p.y,12,8,"#ffffff");
rect(p.x+7,p.y+8,22,8,"#00eaff");
rect(p.x,p.y+16,36,12,"#0879ff");
rect(p.x+7,p.y+28,8,8,"#00eaff");
rect(p.x+21,p.y+28,8,8,"#00eaff");
rect(p.x+14,p.y+16,8,8,"#ffffff");
ctx.shadowBlur=0;
if(frame%8<4){
rect(p.x+8,p.y+37,6,9,"#ffae00");
rect(p.x+22,p.y+37,6,9,"#ffae00");
}
}
// رسم عدو بكسل
function drawEnemy(e){
const x=e.x,y=e.y;
let color=e.row===0?"#ff3c83":"#a65cff";
ctx.shadowBlur=12;
ctx.shadowColor=color;
rect(x+8,y,18,6,color);
rect(x+3,y+6,28,8,color);
rect(x,y+14,34,8,color);
rect(x+5,y+22,8,7,color);
rect(x+21,y+22,8,7,color);
rect(x+8,y+9,5,5,"#ffffff");
rect(x+22,y+9,5,5,"#ffffff");
rect(x+9,y+10,3,3,"#080b22");
rect(x+23,y+10,3,3,"#080b22");
ctx.shadowBlur=0;
}
// رسم البوس
function drawBoss(){
if(!boss)return;
let x=boss.x,y=boss.y;
ctx.shadowBlur=30;
ctx.shadowColor="#ff003c";
rect(x+45,y,90,20,"#ff174f");
rect(x+20,y+20,140,25,"#bd1248");
rect(x,y+45,180,35,"#e52255");
rect(x+20,y+80,35,20,"#ff174f");
rect(x+125,y+80,35,20,"#ff174f");
rect(x+35,y+35,25,18,"#fff000");
rect(x+120,y+35,25,18,"#fff000");
rect(x+65,y+65,50,8,"#ffb000");
ctx.shadowBlur=0;
// شريط صحة البوس
ctx.fillStyle="#333";
ctx.fillRect(300,20,300,12);
ctx.fillStyle="#ff174f";
ctx.fillRect(300,20,300*(boss.hp/boss.maxHp),12);
ctx.strokeStyle="white";
ctx.strokeRect(300,20,300,12);
}
function shoot(){
bullets.push({
x:player.x+16,y:player.y-10,
w:5,h:17,v:10
});
}
function enemyShoot(){
let alive=enemies.filter(e=>e.alive);
if(alive.length===0)return;
let e=alive[Math.floor(Math.random()*alive.length)];
enemyBullets.push({
x:e.x+15,y:e.y+25,w:6,h:13,v:4+level*.3
});
}
function createBoss(){
boss={
x:350,y:65,w:180,h:100,
hp:40+level*10,
maxHp:40+level*10,
dir:1
};
$("message").textContent="⚠️ تحذير! ظهر زعيم المجرة!";
}
function explode(x,y,color){
for(let i=0;i<12;i++){
particles.push({
x,y,
vx:(Math.random()-.5)*8,
vy:(Math.random()-.5)*8,
life:30,
color
});
}
}
function hitPlayer(){
hp--;
updateHUD();
explode(player.x+18,player.y+15,"#00eeff");
if(hp<=0){
gameOver=true;
$("message").textContent="انتهت المعركة! اضغط FIRE لإعادة اللعب";
}
}
function update(){
if(!started||gameOver)return;
frame++;
// حركة اللاعب
if(keys.ArrowLeft||keys.a||moveTouch===-1)
player.x-=player.speed;
if(keys.ArrowRight||keys.d||moveTouch===1)
player.x+=player.speed;
player.x=Math.max(0,Math.min(W-player.w,player.x));
// إطلاق تلقائي عند الضغط
if(firing&&frame%10===0)shoot();
// تحديث النجوم
stars.forEach(s=>{
s.y+=s.v;
if(s.y>H){s.y=0;s.x=Math.random()*W}
});
// رصاص اللاعب
bullets.forEach(b=>b.y-=b.v);
bullets=bullets.filter(b=>b.y>-20);
// رصاص الأعداء
enemyBullets.forEach(b=>{
b.y+=b.v;
if(b.x<player.x+player.w&&b.x+b.w>player.x&&
b.y<player.y+player.h&&b.y+b.h>player.y){
b.dead=true;
hitPlayer();
}
});
enemyBullets=enemyBullets.filter(b=>b.y<H&&!b.dead);
// حركة الأعداء
enemies.forEach(e=>{
if(!e.alive)return;
e.x=e.baseX+Math.sin(frame*.025+e.phase)*22;
e.y+=Math.sin(frame*.04+e.phase)*.3;
bullets.forEach(b=>{
if(b.x<e.x+e.w&&b.x+b.w>e.x&&
b.y<e.y+e.h&&b.y+b.h>e.y){
e.alive=false;b.dead=true;
score+=10;
explode(e.x+15,e.y+15,"#ff36ad");
updateHUD();
}
});
});
bullets=bullets.filter(b=>!b.dead);
// إطلاق الأعداء
if(frame%65===0&&enemies.some(e=>e.alive))
enemyShoot();
// التحقق من نهاية موجة الأعداء
if(enemies.every(e=>!e.alive)&&!boss){
createBoss();
}
// حركة البوس
if(boss){
boss.x+=boss.dir*3;
if(boss.x<0||boss.x>W-180)boss.dir*=-1;
if(frame%35===0){
bossBullets.push({
x:boss.x+80,y:boss.y+90,
w:12,h:18,v:5
});
}
bullets.forEach(b=>{
if(b.x<boss.x+180&&b.x+ b.w>boss.x&&
b.y<boss.y+100&&b.y+b.h>boss.y){
b.dead=true;
boss.hp--;
explode(b.x,b.y,"#ffcc00");
if(boss.hp<=0){
explode(boss.x+90,boss.y+50,"#ff174f");
score+=500;
boss=null;
level++;
hp=Math.min(5,hp+1);
makeEnemies();
updateHUD();
$("message").textContent="🏆 انتصرت! بدأت موجة جديدة!";
}
}
});
bullets=bullets.filter(b=>!b.dead);
}
bossBullets.forEach(b=>{
b.y+=b.v;
if(b.x<player.x+player.w&&b.x+b.w>player.x&&
b.y<player.y+player.h&&b.y+b.h>player.y){
b.dead=true;hitPlayer();
}
});
bossBullets=bossBullets.filter(b=>b.y<H&&!b.dead);
// الجسيمات
particles.forEach(p=>{
p.x+=p.vx;p.y+=p.vy;p.life--;
});
particles=particles.filter(p=>p.life>0);
}
function draw(){
ctx.clearRect(0,0,W,H);
// خلفية فضائية
ctx.fillStyle="#080b22";
ctx.fillRect(0,0,W,H);
stars.forEach(s=>{
rect(s.x,s.y,s.s,s.s,"#9bbaff");
});
// شبكة مستقبلية
ctx.strokeStyle="#151b46";
ctx.lineWidth=1;
for(let x=0;x<W;x+=60){
ctx.beginPath();ctx.moveTo(x,0);ctx.lineTo(x,H);
ctx.stroke();
}
drawPlayer();
enemies.forEach(e=>{
if(e.alive)drawEnemy(e);
});
// رصاص اللاعب
bullets.forEach(b=>{
ctx.shadowBlur=15;
ctx.shadowColor="#00ffff";
rect(b.x,b.y,b.w,b.h,"#00ffff");
});
ctx.shadowBlur=0;
enemyBullets.forEach(b=>{
rect(b.x,b.y,b.w,b.h,"#ff3990");
});
bossBullets.forEach(b=>{
rect(b.x,b.y,b.w,b.h,"#ff2222");
});
drawBoss();
particles.forEach(p=>{
ctx.globalAlpha=p.life/30;
rect(p.x,p.y,5,5,p.color);
});
ctx.globalAlpha=1;
if(!started){
ctx.fillStyle="white";
ctx.font="bold 40px Arial";
ctx.textAlign="center";
ctx.fillText("GALAXY INVADERS",450,260);
ctx.font="22px Arial";
ctx.fillText("اضغط FIRE للبدء",450,320);
}
if(gameOver){
ctx.fillStyle="#000000bb";
ctx.fillRect(0,0,W,H);
ctx.fillStyle="#ff3355";
ctx.font="bold 55px Arial";
ctx.textAlign="center";
ctx.fillText("GAME OVER",450,270);
ctx.fillStyle="white";
ctx.font="25px Arial";
ctx.fillText("SCORE: "+score,450,320);
ctx.fillText("اضغط FIRE للعب مجدداً",450,370);
}
}
function loop(){
update();
draw();
requestAnimationFrame(loop);
}
// لوحة المفاتيح
document.addEventListener("keydown",e=>{
keys[e.key]=true;
if(e.code==="Space"){
e.preventDefault();
if(!started||gameOver)reset();
else shoot();
}
});
document.addEventListener("keyup",e=>keys[e.key]=false);
// أزرار الهاتف
function holdButton(id,callback){
const el=$(id);
el.addEventListener("pointerdown",e=>{
e.preventDefault();callback(true);
});
["pointerup","pointercancel","pointerleave"].forEach(ev=>{
el.addEventListener(ev,()=>callback(false));
});
}
holdButton("left",v=>moveTouch=v?-1:0);
holdButton("right",v=>moveTouch=v?1:0);
holdButton("fire",v=>{
firing=v;
if(v){
if(!started||gameOver)reset();
else shoot();
}
});
loop();
</script>
</body>
</html>Game Source: GALAXY INVADERS
Creator: ChromeFlame24
Libraries: none
Complexity: complex (478 lines, 9.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: galaxy-invaders-chromeflame24" to link back to the original. Then publish at arcadelab.ai/publish.