LOOM GALAXY ATTACK
by ChromeFlame24449 lines12.6 KB
<!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>LOOM GALAXY ATTACK</title>
<style>
*{box-sizing:border-box}
body{margin:0;background:#050617;color:white;font-family:Arial;overflow:hidden;touch-action:none}
canvas{display:block;width:100vw;height:100vh;background:#050617}
#hud{position:fixed;top:12px;left:12px;right:12px;display:flex;justify-content:space-between;pointer-events:none;font-weight:bold;text-shadow:0 0 8px cyan}
#controls{position:fixed;bottom:15px;left:12px;right:12px;display:flex;justify-content:space-between;align-items:end}
button{border:1px solid #42dfff;background:#101b3b;color:white;padding:12px 17px;border-radius:14px;font-weight:bold;font-size:15px}
button:active{background:#354b87}
#overlay{position:fixed;inset:0;background:#030516dd;display:flex;align-items:center;justify-content:center;text-align:center;padding:20px}
.panel{max-width:380px;width:100%;background:#11152f;border:1px solid #3edfff;border-radius:22px;padding:25px;box-shadow:0 0 35px #512bff}
h1{color:#50eaff;text-shadow:0 0 15px #713cff}
.small{color:#c7d2fe;font-size:14px;line-height:1.8}
#bossName{color:#ff648d}
.hidden{display:none!important}
</style>
</head>
<body>
<canvas id="game"></canvas>
<div id="hud">
<span>⭐ <span id="score">0</span></span>
<span>❤️ <span id="lives">3</span></span>
<span>⚡ Level <span id="level">1</span></span>
</div>
<div id="controls">
<button id="bomb">💣 قنبلة</button>
<button id="mute">🔊 الصوت</button>
<button id="pause">⏸ إيقاف</button>
</div>
<div id="overlay">
<div class="panel">
<h1>LOOM GALAXY ATTACK</h1>
<p id="message">استعد لمعركة المجرة!</p>
<p class="small">اسحب إصبعك لتحريك سفينتك.<br>أطلق النار تلقائياً، وواجه الزعماء الأقوياء!</p>
<button id="start">🚀 ابدأ اللعبة</button>
</div>
</div>
<script>
const canvas=document.getElementById("game");
const ctx=canvas.getContext("2d");
const $=id=>document.getElementById(id);
let W,H,playing=false,paused=false,muted=false;
let score=0,lives=3,level=1,weapon=1;
let player,bullets=[],enemyBullets=[],enemies=[],boss=null;
let particles=[],stars=[],lastShot=0,lastEnemy=0,lastBossLine=0;
let bossIndex=0,gameTime=0;
let audioCtx=null;
function resize(){
W=canvas.width=innerWidth*devicePixelRatio;
H=canvas.height=innerHeight*devicePixelRatio;
ctx.setTransform(devicePixelRatio,0,0,devicePixelRatio,0,0);
W=innerWidth;H=innerHeight;
}
addEventListener("resize",resize);resize();
function sound(freq=300,duration=.15,type="sawtooth",volume=.08){
if(muted)return;
try{
audioCtx ||= new (window.AudioContext||window.webkitAudioContext)();
if(audioCtx.state==="suspended")audioCtx.resume();
const o=audioCtx.createOscillator(),g=audioCtx.createGain();
o.type=type;o.frequency.setValueAtTime(freq,audioCtx.currentTime);
o.frequency.exponentialRampToValueAtTime(Math.max(40,freq*.45),audioCtx.currentTime+duration);
g.gain.setValueAtTime(volume,audioCtx.currentTime);
g.gain.exponentialRampToValueAtTime(.001,audioCtx.currentTime+duration);
o.connect(g);g.connect(audioCtx.destination);
o.start();o.stop(audioCtx.currentTime+duration);
}catch(e){}
}
// صوت كلام الزعيم
function bossSpeak(message){
if(muted || !("speechSynthesis" in window))return;
speechSynthesis.cancel();
const voice=new SpeechSynthesisUtterance(message);
voice.lang="ar";
voice.rate=.82;
voice.pitch=.55;
voice.volume=1;
speechSynthesis.speak(voice);
}
const bossLines=[
"لن تستطيعوا هزيمتي!",
"أنا سيد هذه المجرة!",
"استعدوا للنهاية!",
"قوتي لا حدود لها!",
"لن تهربوا مني!",
"سأدمر سفينتكم!",
"هذه المجرة ملكي!"
];
function bossTaunt(){
if(!boss || muted)return;
bossSpeak(bossLines[Math.floor(Math.random()*bossLines.length)]);
}
function init(){
score=0;lives=3;level=1;weapon=1;
bullets=[];enemyBullets=[];enemies=[];particles=[];
boss=null;bossIndex=0;gameTime=0;
player={x:W/2,y:H*.82,r:17};
stars=Array.from({length:100},()=>({
x:Math.random()*W,y:Math.random()*H,
s:Math.random()*2+0.5,v:Math.random()*2+0.5
}));
updateHUD();
}
function updateHUD(){
$("score").textContent=score;
$("lives").textContent=lives;
$("level").textContent=level;
}
function drawShip(x,y){
ctx.save();ctx.translate(x,y);
ctx.shadowBlur=20;ctx.shadowColor="#00eaff";
ctx.fillStyle="#20dfff";
ctx.beginPath();ctx.moveTo(0,-25);ctx.lineTo(18,18);
ctx.lineTo(0,11);ctx.lineTo(-18,18);ctx.closePath();ctx.fill();
ctx.fillStyle="#fff";
ctx.beginPath();ctx.ellipse(0,-5,5,10,0,0,Math.PI*2);ctx.fill();
ctx.fillStyle="#ff9c35";
ctx.beginPath();ctx.moveTo(-7,16);ctx.lineTo(0,30+Math.random()*7);
ctx.lineTo(7,16);ctx.fill();
ctx.restore();
}
function drawEnemy(e){
ctx.save();ctx.translate(e.x,e.y);
ctx.shadowBlur=14;ctx.shadowColor=e.color;
ctx.fillStyle=e.color;
ctx.beginPath();
if(e.type===0){
ctx.moveTo(0,16);ctx.lineTo(19,-9);ctx.lineTo(0,-16);ctx.lineTo(-19,-9);
}else if(e.type===1){
ctx.arc(0,0,15,0,Math.PI*2);
}else if(e.type===2){
ctx.moveTo(-18,-12);ctx.lineTo(18,-12);ctx.lineTo(12,15);ctx.lineTo(-12,15);
}else{
ctx.moveTo(0,-18);ctx.lineTo(18,0);ctx.lineTo(0,18);ctx.lineTo(-18,0);
}
ctx.closePath();ctx.fill();
ctx.fillStyle="white";
ctx.fillRect(-7,-3,5,4);ctx.fillRect(3,-3,5,4);
ctx.restore();
}
function drawBoss(){
if(!boss)return;
ctx.save();ctx.translate(boss.x,boss.y);
ctx.shadowBlur=30;ctx.shadowColor="#ff174f";
ctx.fillStyle=boss.color;
ctx.beginPath();
ctx.moveTo(0,40);ctx.lineTo(-65,5);ctx.lineTo(-52,-35);
ctx.lineTo(-20,-22);ctx.lineTo(0,-55);ctx.lineTo(20,-22);
ctx.lineTo(52,-35);ctx.lineTo(65,5);ctx.closePath();ctx.fill();
ctx.fillStyle="#fff";
ctx.fillRect(-22,-13,12,8);ctx.fillRect(10,-13,12,8);
ctx.fillStyle="#ffcf45";
ctx.fillRect(-boss.width/2,-65,boss.width,7);
ctx.fillStyle="#36f5ff";
ctx.fillRect(-boss.width/2,-65,boss.width*(boss.hp/boss.maxHp),7);
ctx.restore();
ctx.fillStyle="white";ctx.font="bold 14px Arial";
ctx.textAlign="center";
ctx.fillText(boss.name,boss.x,boss.y-76);
}
function shoot(){
if(!player)return;
const now=Date.now();
if(now-lastShot<Math.max(100,320-weapon*35))return;
lastShot=now;
sound(600,.08,"square",.025);
if(weapon===1){
bullets.push({x:player.x,y:player.y-25,v:9,damage:1});
}else{
bullets.push({x:player.x-9,y:player.y-20,v:9,damage:1});
bullets.push({x:player.x+9,y:player.y-20,v:9,damage:1});
if(weapon>=3){
bullets.push({x:player.x,y:player.y-28,v:11,damage:2});
}
if(weapon>=4){
bullets.push({x:player.x-18,y:player.y,v:8,damage:1});
bullets.push({x:player.x+18,y:player.y,v:8,damage:1});
}
}
}
function spawnEnemy(){
const type=Math.floor(Math.random()*4);
enemies.push({
x:Math.random()*(W-50)+25,y:-30,
type,color:["#ff5577","#b66cff","#ffb347","#48e6bd"][type],
hp:1+Math.floor(level/3),v:1.5+Math.random()*1.5+level*.12
});
}
function spawnBoss(){
bossIndex++;
boss={
x:W/2,y:100,hp:35+bossIndex*15,
maxHp:35+bossIndex*15,
width:130,
color:["#a52cff","#ff315f","#267cff","#ff8b28"][bossIndex%4],
name:["ملك الظلام","مدمر الكواكب","وحش المجرة","القائد الأخير"][bossIndex%4],
dir:1
};
bossSpeak("أنا "+boss.name+"! لن تستطيعوا هزيمتي!");
lastBossLine=Date.now();
sound(90,.8,"sawtooth",.15);
}
function enemyShoot(){
if(!boss)return;
const dx=player.x-boss.x,dy=player.y-boss.y;
const len=Math.hypot(dx,dy)||1;
enemyBullets.push({
x:boss.x,y:boss.y+30,
vx:dx/len*3,vy:dy/len*3,
r:7,color:"#ff315f"
});
if(Math.random()<.3){
for(let i=-1;i<=1;i++){
enemyBullets.push({
x:boss.x,y:boss.y+20,
vx:i*2,vy:4,r:6,color:"#ff9a42"
});
}
}
}
function explode(x,y,color="#ff8b35"){
for(let i=0;i<18;i++){
const a=Math.random()*Math.PI*2,s=Math.random()*5+1;
particles.push({x,y,vx:Math.cos(a)*s,vy:Math.sin(a)*s,life:35,color});
}
sound(110,.25,"sawtooth",.08);
}
function bomb(){
if(!playing||paused)return;
if(score<50){
bossSpeak("تحتاج إلى خمسين نقطة لاستخدام القنبلة");
return;
}
score-=50;
enemies.forEach(e=>explode(e.x,e.y));
enemies=[];
enemyBullets=[];
if(boss)boss.hp-=15;
sound(65,.7,"sawtooth",.2);
updateHUD();
}
function update(){
if(!playing||paused)return;
gameTime++;
for(const s of stars){
s.y+=s.v;
if(s.y>H){s.y=0;s.x=Math.random()*W;}
}
shoot();
if(Date.now()-lastEnemy>850-level*35 && !boss){
lastEnemy=Date.now();spawnEnemy();
}
if(gameTime>1000+bossIndex*500 && !boss)spawnBoss();
bullets.forEach(b=>b.y-=b.v);
bullets=bullets.filter(b=>b.y>-20);
enemies.forEach(e=>e.y+=e.v);
enemies=enemies.filter(e=>{
if(e.y>H+30){lives--;updateHUD();return false;}
return true;
});
if(boss){
boss.x+=boss.dir*1.7;
if(boss.x>W-75||boss.x<75)boss.dir*=-1;
if(Math.random()<.025)enemyShoot();
if(Date.now()-lastBossLine>12000){
lastBossLine=Date.now();bossTaunt();
}
}
for(const b of bullets){
for(const e of enemies){
if(Math.hypot(b.x-e.x,b.y-e.y)<22 && !b.hit){
e.hp-=b.damage;b.hit=true;
explode(b.x,b.y,"#50eaff");
if(e.hp<=0){score+=10;explode(e.x,e.y,e.color);}
}
}
if(boss && Math.hypot(b.x-boss.x,b.y-boss.y)<65 && !b.hit){
boss.hp-=b.damage;b.hit=true;
if(boss.hp<=0){
score+=100+bossIndex*50;
explode(boss.x,boss.y,"#ff315f");
bossSpeak("لااا! لقد هزمتني!");
boss=null;
level++;
weapon=Math.min(5,weapon+1);
setTimeout(()=>{if(playing)bossSpeak("لقد تطورت أسلحتك! استعد للعدو القادم!");},900);
}
}
}
bullets=bullets.filter(b=>!b.hit);
enemies=enemies.filter(e=>e.hp>0);
enemyBullets.forEach(b=>{b.x+=b.vx;b.y+=b.vy;});
enemyBullets=enemyBullets.filter(b=>b.x>-30&&b.x<W+30&&b.y>-30&&b.y<H+30);
for(const b of enemyBullets){
if(Math.hypot(b.x-player.x,b.y-player.y)<22){
b.hit=true;lives--;explode(player.x,player.y);
updateHUD();
}
}
enemyBullets=enemyBullets.filter(b=>!b.hit);
for(const e of enemies){
if(Math.hypot(e.x-player.x,e.y-player.y)<27){
e.hp=0;lives--;explode(e.x,e.y);updateHUD();
}
}
particles.forEach(p=>{
p.x+=p.vx;p.y+=p.vy;p.life--;
});
particles=particles.filter(p=>p.life>0);
updateHUD();
if(lives<=0)endGame();
}
function draw(){
ctx.clearRect(0,0,W,H);
const gradient=ctx.createLinearGradient(0,0,0,H);
gradient.addColorStop(0,"#05051b");
gradient.addColorStop(1,"#10133b");
ctx.fillStyle=gradient;ctx.fillRect(0,0,W,H);
ctx.fillStyle="white";
for(const s of stars){
ctx.globalAlpha=.4+s.s/4;
ctx.fillRect(s.x,s.y,s.s,s.s);
}
ctx.globalAlpha=1;
bullets.forEach(b=>{
ctx.fillStyle="#48f4ff";ctx.shadowBlur=12;ctx.shadowColor="#48f4ff";
ctx.fillRect(b.x-3,b.y-10,6,16);
});
ctx.shadowBlur=0;
enemies.forEach(drawEnemy);
if(boss)drawBoss();
enemyBullets.forEach(b=>{
ctx.fillStyle=b.color;ctx.shadowBlur=12;ctx.shadowColor=b.color;
ctx.beginPath();ctx.arc(b.x,b.y,b.r,0,Math.PI*2);ctx.fill();
});
ctx.shadowBlur=0;
particles.forEach(p=>{
ctx.globalAlpha=p.life/35;
ctx.fillStyle=p.color;
ctx.fillRect(p.x,p.y,4,4);
});
ctx.globalAlpha=1;
if(player)drawShip(player.x,player.y);
if(paused&&playing){
ctx.fillStyle="#ffffff";ctx.font="bold 38px Arial";
ctx.textAlign="center";ctx.fillText("متوقف مؤقتاً",W/2,H/2);
}
}
function loop(){
update();draw();requestAnimationFrame(loop);
}
function endGame(){
playing=false;
if("speechSynthesis" in window)speechSynthesis.cancel();
$("overlay").classList.remove("hidden");
$("message").textContent="انتهت اللعبة! نتيجتك: "+score;
$("start").textContent="🔄 العب مرة أخرى";
}
function startGame(){
if("speechSynthesis" in window)speechSynthesis.cancel();
init();
playing=true;paused=false;
$("overlay").classList.add("hidden");
bossSpeak("أهلاً بك في معركة المجرة");
}
$("start").onclick=startGame;
$("bomb").onclick=bomb;
$("pause").onclick=()=>{
if(!playing)return;
paused=!paused;
$("pause").textContent=paused?"▶ متابعة":"⏸ إيقاف";
};
$("mute").onclick=()=>{
muted=!muted;
$("mute").textContent=muted?"🔇 مكتوم":"🔊 الصوت";
if(muted&&"speechSynthesis" in window)speechSynthesis.cancel();
};
let dragging=false;
function movePlayer(x,y){
if(!player)return;
player.x=Math.max(22,Math.min(W-22,x));
player.y=Math.max(H*.45,Math.min(H-35,y));
}
canvas.addEventListener("pointerdown",e=>{
dragging=true;movePlayer(e.clientX,e.clientY);
});
canvas.addEventListener("pointermove",e=>{
if(dragging)movePlayer(e.clientX,e.clientY);
});
addEventListener("pointerup",()=>dragging=false);
init();
loop();
</script>
</body>
</html>Game Source: LOOM GALAXY ATTACK
Creator: ChromeFlame24
Libraries: none
Complexity: complex (449 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: loom-galaxy-attack-chromeflame24-mwn7kh9n" to link back to the original. Then publish at arcadelab.ai/publish.