🎮ArcadeLab

LOOM: هجوم المجرات

by ChromeFlame24
596 lines19.4 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: هجوم المجرات</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            background-color: #05050a;
            color: #fff;
            font-family: 'Courier New', Courier, monospace;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
            overflow: hidden;
            user-select: none;
        }
        #game-container {
            position: relative;
            box-shadow: 0 0 30px rgba(0, 243, 255, 0.4);
            border: 3px solid #00f3ff;
            border-radius: 8px;
            overflow: hidden;
            background: #000;
        }
        canvas {
            display: block;
            image-rendering: pixelated;
            image-rendering: crisp-edges;
        }
        .ui-panel {
            margin-top: 10px;
            display: flex;
            gap: 20px;
            font-size: 16px;
            font-weight: bold;
            letter-spacing: 1px;
        }
        .ui-item {
            background: rgba(0, 243, 255, 0.1);
            padding: 5px 15px;
            border: 1px solid #00f3ff;
            border-radius: 4px;
        }
    </style>
</head>
<body>

    <div id="game-container">
        <canvas id="gameCanvas" width="480" height="640"></canvas>
    </div>
    
    <div class="ui-panel">
        <div class="ui-item">النقاط: <span id="scoreVal">0</span></div>
        <div class="ui-item">الموجة: <span id="waveVal">1</span></div>
        <div class="ui-item">الحياة: <span id="livesVal">3</span></div>
    </div>

<script>
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');

// عناصر الواجهة
const scoreEl = document.getElementById('scoreVal');
const waveEl = document.getElementById('waveVal');
const livesEl = document.getElementById('livesVal');

// حالة اللعبة
let gameState = 'START'; // START, PLAYING, GAMEOVER, VICTORY
let score = 0;
let wave = 1;
let lives = 3;
let frameCount = 0;

// المؤثرات الصوتية البسيطة عبر Web Audio API
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
function playSound(type) {
    if (!audioCtx) return;
    if (audioCtx.state === 'suspended') audioCtx.resume();
    
    const osc = audioCtx.createOscillator();
    const gain = audioCtx.createGain();
    osc.connect(gain);
    gain.connect(audioCtx.destination);
    
    const now = audioCtx.currentTime;
    
    if (type === 'shoot') {
        osc.type = 'square';
        osc.frequency.setValueAtTime(600, now);
        osc.frequency.exponentialRampToValueAtTime(100, now + 0.1);
        gain.gain.setValueAtTime(0.1, now);
        gain.gain.linearRampToValueAtTime(0.01, now + 0.1);
        osc.start(now);
        osc.stop(now + 0.1);
    } else if (type === 'explosion') {
        osc.type = 'sawtooth';
        osc.frequency.setValueAtTime(150, now);
        osc.frequency.linearRampToValueAtTime(30, now + 0.3);
        gain.gain.setValueAtTime(0.2, now);
        gain.gain.linearRampToValueAtTime(0.01, now + 0.3);
        osc.start(now);
        osc.stop(now + 0.3);
    } else if (type === 'powerup') {
        osc.type = 'sine';
        osc.frequency.setValueAtTime(300, now);
        osc.frequency.linearRampToValueAtTime(800, now + 0.2);
        gain.gain.setValueAtTime(0.15, now);
        gain.gain.linearRampToValueAtTime(0.01, now + 0.2);
        osc.start(now);
        osc.stop(now + 0.2);
    }
}

// الكائنات والبيئة
class Star {
    constructor() {
        this.x = Math.random() * canvas.width;
        this.y = Math.random() * canvas.height;
        this.size = Math.random() * 2;
        this.speed = Math.random() * 2 + 0.5;
    }
    update() {
        this.y += this.speed;
        if (this.y > canvas.height) {
            this.y = 0;
            this.x = Math.random() * canvas.width;
        }
    }
    draw() {
        ctx.fillStyle = '#ffffff';
        ctx.fillRect(this.x, this.y, this.size, this.size);
    }
}
let stars = Array.from({ length: 50 }, () => new Star());

// اللاعب (LOOM)
class Player {
    constructor() {
        this.width = 36;
        this.height = 36;
        this.x = canvas.width / 2 - this.width / 2;
        this.y = canvas.height - 70;
        this.speed = 5;
        this.dx = 0;
        this.weaponLevel = 1;
        this.shootCooldown = 0;
    }
    update() {
        this.x += this.dx;
        if (this.x < 0) this.x = 0;
        if (this.x > canvas.width - this.width) this.x = canvas.width - this.width;

        if (this.shootCooldown > 0) this.shootCooldown--;
    }
    draw() {
        ctx.fillStyle = '#00f3ff';
        // تصميم بكسل آرت للمركبة
        ctx.fillRect(this.x + 14, this.y, 8, 12);
        ctx.fillRect(this.x + 6, this.y + 12, 24, 12);
        ctx.fillRect(this.x, this.y + 24, 36, 8);
        ctx.fillStyle = '#ff0055';
        ctx.fillRect(this.x + 4, this.y + 28, 6, 6);
        ctx.fillRect(this.x + 26, this.y + 28, 6, 6);
    }
    shoot() {
        if (this.shootCooldown > 0) return;
        playSound('shoot');
        if (this.weaponLevel === 1) {
            bullets.push(new Bullet(this.x + this.width / 2 - 2, this.y, 0, -8, '#00f3ff'));
        } else if (this.weaponLevel === 2) {
            bullets.push(new Bullet(this.x + 6, this.y, 0, -8, '#00f3ff'));
            bullets.push(new Bullet(this.x + this.width - 10, this.y, 0, -8, '#00f3ff'));
        } else {
            bullets.push(new Bullet(this.x + this.width / 2 - 2, this.y, 0, -9, '#ff00ff'));
            bullets.push(new Bullet(this.x + 4, this.y + 5, -1.5, -8, '#00f3ff'));
            bullets.push(new Bullet(this.x + this.width - 8, this.y + 5, 1.5, -8, '#00f3ff'));
        }
        this.shootCooldown = 12;
    }
}

// الطلقات
class Bullet {
    constructor(x, y, dx, dy, color) {
        this.x = x;
        this.y = y;
        this.dx = dx;
        this.dy = dy;
        this.width = 4;
        this.height = 10;
        this.color = color;
    }
    update() {
        this.x += this.dx;
        this.y += this.dy;
    }
    draw() {
        ctx.fillStyle = this.color;
        ctx.fillRect(this.x, this.y, this.width, this.height);
    }
}

// العدو (مصطف ومنتظم مع نظام تصاعد في القوة)
class Enemy {
    constructor(x, y, type, waveMultiplier) {
        this.x = x;
        this.y = y;
        this.type = type; // 1: عاصفة, 2: مدرع, 3: قناص
        this.width = 30;
        this.height = 26;
        
        // تصاعد القوة تدريجيًا بناءً على رقم الموجة
        let healthMultiplier = 1 + (waveMultiplier - 1) * 0.4;
        
        if (type === 1) {
            this.maxHealth = Math.floor(1 * healthMultiplier);
            this.color = '#ffcc00';
            this.points = 10;
        } else if (type === 2) {
            this.maxHealth = Math.floor(2 * healthMultiplier);
            this.color = '#ff3333';
            this.points = 25;
        } else {
            this.maxHealth = Math.floor(3 * healthMultiplier);
            this.color = '#cc00ff';
            this.points = 40;
        }
        this.health = this.maxHealth;
    }
    draw() {
        ctx.fillStyle = this.color;
        if (this.type === 1) {
            ctx.fillRect(this.x + 5, this.y, 20, 8);
            ctx.fillRect(this.x, this.y + 8, 30, 12);
            ctx.fillRect(this.x + 8, this.y + 20, 14, 6);
        } else if (this.type === 2) {
            ctx.fillRect(this.x, this.y, 30, 26);
            ctx.fillStyle = '#ffffff';
            ctx.fillRect(this.x + 6, this.y + 8, 18, 6);
        } else {
            ctx.fillRect(this.x + 10, this.y, 10, 26);
            ctx.fillRect(this.x, this.y + 6, 30, 10);
        }
    }
}

// الزعيم (Boss)
class Boss {
    constructor(waveNum) {
        this.width = 100;
        this.height = 50;
        this.x = canvas.width / 2 - this.width / 2;
        this.y = -60;
        this.targetY = 60;
        this.maxHealth = 50 + (waveNum * 25);
        this.health = this.maxHealth;
        this.dx = 2;
        this.shootTimer = 0;
    }
    update() {
        if (this.y < this.targetY) {
            this.y += 1;
        } else {
            this.x += this.dx;
            if (this.x <= 20 || this.x >= canvas.width - this.width - 20) {
                this.dx *= -1;
            }
            
            // إطلاق النار المكثف من الزعيم
            this.shootTimer++;
            if (this.shootTimer % 45 === 0) {
                enemyBullets.push(new Bullet(this.x + 20, this.y + this.height, 0, 4, '#ff0055'));
                enemyBullets.push(new Bullet(this.x + this.width - 20, this.y + this.height, 0, 4, '#ff0055'));
                enemyBullets.push(new Bullet(this.x + this.width / 2, this.y + this.height, 0, 5, '#ffff00'));
            }
        }
    }
    draw() {
        ctx.fillStyle = '#ff2222';
        ctx.fillRect(this.x, this.y, this.width, this.height);
        ctx.fillStyle = '#00ffff';
        ctx.fillRect(this.x + 30, this.y + 15, 40, 20);
        
        // شريط حياة الزعيم
        ctx.fillStyle = '#444';
        ctx.fillRect(canvas.width / 2 - 100, 20, 200, 10);
        ctx.fillStyle = '#ff0055';
        ctx.fillRect(canvas.width / 2 - 100, 20, (this.health / this.maxHealth) * 200, 10);
    }
}

// المؤثرات البصرية (الانفجارات)
class Particle {
    constructor(x, y, color) {
        this.x = x;
        this.y = y;
        this.color = color;
        this.size = Math.random() * 4 + 2;
        this.dx = (Math.random() - 0.5) * 6;
        this.dy = (Math.random() - 0.5) * 6;
        this.life = 30;
    }
    update() {
        this.x += this.dx;
        this.y += this.dy;
        this.life--;
    }
    draw() {
        ctx.fillStyle = this.color;
        ctx.fillRect(this.x, this.y, this.size, this.size);
    }
}

// عناصر الدعم (PowerUp)
class PowerUp {
    constructor(x, y) {
        this.x = x;
        this.y = y;
        this.width = 20;
        this.height = 20;
        this.dy = 2;
    }
    update() {
        this.y += this.dy;
    }
    draw() {
        ctx.fillStyle = '#00ff66';
        ctx.fillRect(this.x, this.y, this.width, this.height);
        ctx.fillStyle = '#000';
        ctx.font = 'bold 14px Courier New';
        ctx.fillText('P', this.x + 5, this.y + 15);
    }
}

let player = new Player();
let bullets = [];
let enemyBullets = [];
let enemies = [];
let boss = null;
let particles = [];
let powerUps = [];

// إنشاء صفوف الأعداء بشكل هندسي منتظم
let enemyDirection = 1;
let enemyMoveTimer = 0;

function spawnWave() {
    enemies = [];
    boss = null;
    let rows = 4;
    let cols = 8;
    let startX = 50;
    let startY = 80;
    let spacingX = 48;
    let spacingY = 40;

    for (let r = 0; r < rows; r++) {
        let type = r === 0 ? 3 : (r < 2 ? 2 : 1);
        for (let c = 0; c < cols; c++) {
            enemies.append ? null : null; // Safe check
            enemies.push(new Enemy(startX + c * spacingX, startY + r * spacingY, type, wave));
        }
    }
}

spawnWave();

// تحكم لوحة المفاتيح
const keys = {};
window.addEventListener('keydown', e => {
    keys[e.code] = true;
    if (e.code === 'Space') {
        if (gameState === 'PLAYING') player.shoot();
        else if (gameState === 'START' || gameState === 'GAMEOVER' || gameState === 'VICTORY') resetGame();
    }
});
window.addEventListener('keyup', e => { keys[e.code] = false; });

function resetGame() {
    score = 0;
    wave = 1;
    lives = 3;
    player = new Player();
    bullets = [];
    enemyBullets = [];
    particles = [];
    powerUps = [];
    spawnWave();
    gameState = 'PLAYING';
}

// حلقة اللعبة الرئيسية
function gameLoop() {
    ctx.clearRect(0, 0, canvas.width, canvas.height);

    // تحديث ورسم الخلفية
    stars.forEach(s => { s.update(); s.draw(); });

    if (gameState === 'START') {
        ctx.fillStyle = '#00f3ff';
        ctx.font = 'bold 30px Courier New';
        ctx.textAlign = 'center';
        ctx.fillText('LOOM: هجوم المجرات', canvas.width / 2, canvas.height / 2 - 40);
        ctx.fillStyle = '#fff';
        ctx.font = '16px Courier New';
        ctx.fillText('اضغط مسافة (Space) للبدء', canvas.width / 2, canvas.height / 2 + 10);
        ctx.fillText('تحرك بالسهمين الأيمن والأيسر وإطلاق النار بالمسافة', canvas.width / 2, canvas.height / 2 + 50);
    } else if (gameState === 'PLAYING') {
        frameCount++;

        // تحكم اللاعب
        if (keys['ArrowRight'] || keys['KeyD']) player.dx = player.speed;
        else if (keys['ArrowLeft'] || keys['KeyA']) player.dx = -player.speed;
        else player.dx = 0;

        if (keys['Space']) player.shoot();

        player.update();
        player.draw();

        // حركة الأعداء المنتظمة (كتلة واحدة تتحرك يميناً ويساراً وتنزل للأسفل)
        if (!boss) {
            enemyMoveTimer++;
            if (enemyMoveTimer > 30) {
                let hitEdge = false;
                enemies.forEach(e => {
                    e.x += enemyDirection * 12;
                    if (e.x <= 10 || e.x >= canvas.width - 40) hitEdge = true;
                });
                if (hitEdge) {
                    enemyDirection *= -1;
                    enemies.forEach(e => { e.y += 15; });
                }
                enemyMoveTimer = 0;
            }

            // إطلاق نار عشوائي من الأعداء
            if (Math.random() < 0.02 + (wave * 0.005) && enemies.length > 0) {
                let shooter = enemies[Math.floor(Math.random() * enemies.length)];
                enemyBullets.push(new Bullet(shooter.x + shooter.width / 2, shooter.y + shooter.height, 0, 3 + wave * 0.2, '#ff3333'));
            }
        }

        // تحديث الزعيم إن وجدت
        if (boss) {
            boss.update();
            boss.draw();
            
            // اصطدام طلقات اللاعب بالزعيم
            bullets.forEach((b, bIdx) => {
                if (b.x > boss.x && b.x < boss.x + boss.width && b.y > boss.y && b.y < boss.y + boss.height) {
                    boss.health--;
                    bullets.splice(bIdx, 1);
                    if (boss.health <= 0) {
                        playSound('explosion');
                        for(let i=0; i<30; i++) particles.push(new Particle(boss.x + boss.width/2, boss.y + boss.height/2, '#ff0055'));
                        score += 500;
                        boss = null;
                        wave++;
                        if (wave > 5) {
                            gameState = 'VICTORY';
                        } else {
                            spawnWave();
                        }
                    }
                }
            });
        }

        // تحديث الأعداء العاديين
        enemies.forEach((e, eIdx) => {
            e.draw();
            
            // اصطدام الأعداء باللاعب
            if (player.x < e.x + e.width && player.x + player.width > e.x && player.y < e.y + e.height && player.y + player.height > e.y) {
                lives--;
                enemies.splice(eIdx, 1);
                playSound('explosion');
                if (lives <= 0) gameState = 'GAMEOVER';
            }

            // وصول العدو لأسفل الشاشة
            if (e.y > canvas.height - 50) {
                gameState = 'GAMEOVER';
            }
        });

        // إذا انتهى الأعداء، يظهر الزعيم أو تنتقل للموجة التالية
        if (enemies.length === 0 && !boss) {
            if (wave % 2 === 0) {
                boss = new Boss(wave);
            } else {
                wave++;
                spawnWave();
            }
        }

        // تحديث الطلقات
        bullets.forEach((b, idx) => {
            b.update();
            b.draw();
            if (b.y < 0) bullets.splice(idx, 1);
        });

        enemyBullets.forEach((b, idx) => {
            b.update();
            b.draw();
            // اصطدام طلقة العدو باللاعب
            if (b.x > player.x && b.x < player.x + player.width && b.y > player.y && b.y < player.y + player.height) {
                lives--;
                enemyBullets.splice(idx, 1);
                playSound('explosion');
                if (lives <= 0) gameState = 'GAMEOVER';
            }
            if (b.y > canvas.height) enemyBullets.splice(idx, 1);
        });

        // اصطدام طلقة اللاعب بالأعداء
        bullets.forEach((b, bIdx) => {
            enemies.forEach((e, eIdx) => {
                if (b.x > e.x && b.x < e.x + e.width && b.y > e.y && b.y < e.y + e.height) {
                    e.health--;
                    bullets.splice(bIdx, 1);
                    if (e.health <= 0) {
                        playSound('explosion');
                        score += e.points;
                        for(let i=0; i<8; i++) particles.push(new Particle(e.x + e.width/2, e.y + e.height/2, e.color));
                        
                        // احتمال سقوط عنصر تطوير
                        if (Math.random() < 0.15) {
                            powerUps.push(new PowerUp(e.x, e.y));
                        }
                        
                        enemies.splice(eIdx, 1);
                    }
                }
            });
        });

        // تحديث عناصر الدعم PowerUps
        powerUps.forEach((p, idx) => {
            p.update();
            p.draw();
            if (p.x < player.x + player.width && p.x + p.width > player.x && p.y < player.y + player.height && p.y + p.height > player.y) {
                playSound('powerup');
                if (player.weaponLevel < 3) player.weaponLevel++;
                score += 50;
                powerUps.splice(idx, 1);
            }
            if (p.y > canvas.height) powerUps.splice(idx, 1);
        });

        // تحديث الجسيمات والانفجارات
        particles.forEach((p, idx) => {
            p.update();
            p.draw();
            if (p.life <= 0) particles.splice(idx, 1);
        });

    } else if (gameState === 'GAMEOVER') {
        ctx.fillStyle = '#ff0055';
        ctx.font = 'bold 32px Courier New';
        ctx.textAlign = 'center';
        ctx.fillText('انتهت اللعبة', canvas.width / 2, canvas.height / 2 - 20);
        ctx.fillStyle = '#fff';
        ctx.font = '16px Courier New';
        ctx.fillText('اضغط مسافة للإعادة', canvas.width / 2, canvas.height / 2 + 30);
    } else if (gameState === 'VICTORY') {
        ctx.fillStyle = '#00ff66';
        ctx.font = 'bold 32px Courier New';
        ctx.textAlign = 'center';
        ctx.fillText('لقد فزت بإنقاذ المجرة!', canvas.width / 2, canvas.height / 2 - 20);
        ctx.fillStyle = '#fff';
        ctx.font = '16px Courier New';
        ctx.fillText('اضغط مسافة للعب مجدداً', canvas.width / 2, canvas.height / 2 + 30);
    }

    // تحديث لوحة المعلومات الخارجية
    scoreEl.innerText = score;
    waveEl.innerText = wave;
    livesEl.innerText = lives;

    requestAnimationFrame(gameLoop);
}

// بدء حلقة التشغيل
requestAnimationFrame(gameLoop);
</script>

</body>
</html>

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

Creator: ChromeFlame24

Libraries: none

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