LOOM: FORTRESS DEFENSE
by ChromeFlame24388 lines20.0 KB
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>LOOM: FORTRESS DEFENSE</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; user-select: none; -webkit-user-select: none; touch-action: none; }
body { background: #020205; overflow: hidden; font-family: 'Courier New', monospace; color: #fff; }
canvas { display: block; width: 100vw; height: 100vh; image-rendering: pixelated; }
#ui-layer { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.hud-top { display: flex; justify-content: space-between; padding: 15px; }
.stat-box { background: rgba(0,0,0,0.8); border: 1px solid #00f3ff; border-radius: 6px; padding: 8px 12px; text-align: center; backdrop-filter: blur(4px); box-shadow: 0 0 10px rgba(0,243,255,0.2); min-width: 90px; }
.stat-label { font-size: 10px; color: #00f3ff; letter-spacing: 1px; }
.stat-value { font-size: 18px; font-weight: bold; color: #fff; text-shadow: 0 0 5px #00f3ff; }
.stat-value.loom { color: #ffd700; text-shadow: 0 0 5px #ffd700; }
.stat-value.hp { color: #ff0055; text-shadow: 0 0 5px #ff0055; }
#joystick-zone { position: fixed; bottom: 30px; left: 30px; width: 120px; height: 120px; pointer-events: auto; z-index: 20; }
#joy-base { position: absolute; inset: 0; border-radius: 50%; background: rgba(0,243,255,0.05); border: 2px solid rgba(0,243,255,0.3); }
#joy-thumb { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 45px; height: 45px; border-radius: 50%; background: radial-gradient(circle, #00f3ff, #0066aa); border: 2px solid #fff; box-shadow: 0 0 15px #00f3ff; }
#shop-btn { position: fixed; bottom: 30px; right: 30px; width: 70px; height: 70px; background: linear-gradient(135deg, #ff0055, #990033); border: 2px solid #fff; border-radius: 50%; color: #fff; font-size: 28px; cursor: pointer; pointer-events: auto; z-index: 20; box-shadow: 0 0 20px #ff0055; display: flex; align-items: center; justify-content: center; }
#shop-btn:active { transform: scale(0.9); }
#shop-modal { position: fixed; inset: 0; background: rgba(2,2,5,0.95); z-index: 100; display: none; pointer-events: auto; backdrop-filter: blur(10px); }
.shop-container { width: 95%; max-width: 900px; height: 90vh; margin: 5vh auto; background: #0a0a12; border: 2px solid #00f3ff; border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; }
.shop-header { padding: 15px; background: #111; border-bottom: 1px solid #333; display: flex; justify-content: space-between; align-items: center; }
.shop-tabs { display: flex; background: #05050a; overflow-x: auto; }
.tab-btn { flex: 1; min-width: 80px; padding: 12px; background: transparent; border: none; color: #666; font-weight: bold; cursor: pointer; border-bottom: 3px solid transparent; transition: all 0.2s; font-size: 13px; white-space: nowrap; }
.tab-btn.active { color: #00f3ff; border-bottom-color: #00f3ff; background: rgba(0,243,255,0.05); }
.shop-content { flex: 1; overflow-y: auto; padding: 15px; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.shop-item { background: #151520; border: 1px solid #333; border-radius: 8px; padding: 12px; cursor: pointer; transition: all 0.2s; position: relative; }
.shop-item:hover { border-color: #00f3ff; transform: translateY(-2px); box-shadow: 0 5px 15px rgba(0,243,255,0.1); }
.shop-item.locked { opacity: 0.4; cursor: not-allowed; }
.shop-item.owned { border-color: #0f0; background: rgba(0,255,0,0.05); }
.item-name { font-weight: bold; color: #fff; margin-bottom: 4px; font-size: 14px; display: flex; justify-content: space-between; }
.item-desc { font-size: 11px; color: #889; margin-bottom: 8px; line-height: 1.3; height: 30px; overflow: hidden; }
.item-cost { font-size: 13px; color: #ffd700; font-weight: bold; display: flex; align-items: center; gap: 5px; }
.close-shop { background: #ff0055; border: none; color: #fff; width: 35px; height: 35px; border-radius: 50%; font-size: 18px; cursor: pointer; }
.screen { position: fixed; inset: 0; background: rgba(2,2,5,0.98); z-index: 200; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: auto; }
.screen h1 { font-size: 52px; color: #00f3ff; text-shadow: 0 0 20px #00f3ff, 0 0 40px #00f3ff; margin-bottom: 10px; letter-spacing: 5px; text-align: center; }
.screen p { color: #889; margin: 5px 0; font-size: 15px; text-align: center; max-width: 400px; }
.btn-primary { margin-top: 30px; padding: 15px 50px; font-size: 20px; font-weight: bold; background: linear-gradient(135deg, #00f3ff, #0066ff); border: none; border-radius: 50px; color: #000; cursor: pointer; box-shadow: 0 0 30px rgba(0,243,255,0.4); transition: transform 0.2s; }
.btn-primary:hover { transform: scale(1.05); }
#notification { position: fixed; top: 20%; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,0.9); border: 1px solid #00f3ff; color: #00f3ff; padding: 10px 25px; border-radius: 20px; font-weight: bold; opacity: 0; transition: opacity 0.3s; pointer-events: none; z-index: 50; }
</style>
</head>
<body>
<canvas id="game"></canvas>
<div id="ui-layer">
<div class="hud-top">
<div class="stat-box"><div class="stat-label">النقاط</div><div class="stat-value" id="score">0</div></div>
<div class="stat-box"><div class="stat-label">الموجة</div><div class="stat-value" id="wave">1</div></div>
<div class="stat-box"><div class="stat-label">LOOM</div><div class="stat-value loom" id="loom">1</div></div>
<div class="stat-box"><div class="stat-label">القاعدة</div><div class="stat-value hp" id="baseHp">1000</div></div>
</div>
</div>
<div id="joystick-zone"><div id="joy-base"></div><div id="joy-thumb"></div></div>
<div id="shop-btn" onclick="openShop()">🛒</div>
<div id="shop-modal">
<div class="shop-container">
<div class="shop-header">
<h2 style="color:#00f3ff; font-size:20px; letter-spacing:2px">متجر LOOM</h2>
<button class="close-shop" onclick="closeShop()">✕</button>
</div>
<div class="shop-tabs">
<button class="tab-btn active" onclick="switchTab('base')">🏰 القاعدة</button>
<button class="tab-btn" onclick="switchTab('army')">👥 الجيش</button>
<button class="tab-btn" onclick="switchTab('planes')">✈️ الطائرات</button>
<button class="tab-btn" onclick="switchTab('upgrades')">⬆️ ترقيات</button>
</div>
<div class="shop-content" id="shop-grid"></div>
</div>
</div>
<div id="start-screen" class="screen">
<h1>LOOM FORTRESS</h1>
<p>🏰 دافع عن قاعدتك ضد الزومبي</p>
<p>🕹️ حرّك شخصيتك بحرية</p>
<p>🔫 القاعدة تطلق النار تلقائياً</p>
<p>✈️ اشترِ طائرات وجيش للحماية</p>
<button class="btn-primary" onclick="startGame()">ابدأ الدفاع</button>
</div>
<div id="game-over-screen" class="screen" style="display:none">
<h1 style="color:#ff0055; text-shadow: 0 0 20px #ff0055;">سقطت القاعدة</h1>
<p>النقاط: <span id="final-score" style="color:#fff; font-weight:bold">0</span></p>
<p>الموجة: <span id="final-wave" style="color:#fff; font-weight:bold">1</span></p>
<button class="btn-primary" onclick="location.reload()">إعادة المحاولة</button>
</div>
<div id="notification"></div>
<script>
const Audio = {
ctx: null,
init() { if (!this.ctx) this.ctx = new (window.AudioContext || window.webkitAudioContext)(); },
play(type) {
if (!this.ctx) return;
const osc = this.ctx.createOscillator();
const gain = this.ctx.createGain();
osc.connect(gain); gain.connect(this.ctx.destination);
const now = this.ctx.currentTime;
if (type === 'shoot') {
osc.type = 'square'; osc.frequency.setValueAtTime(300, now); osc.frequency.exponentialRampToValueAtTime(50, now + 0.1);
gain.gain.setValueAtTime(0.08, now); gain.gain.exponentialRampToValueAtTime(0.01, now + 0.1);
osc.start(now); osc.stop(now + 0.1);
} else if (type === 'hit') {
osc.type = 'triangle'; osc.frequency.setValueAtTime(600, now);
gain.gain.setValueAtTime(0.08, now); gain.gain.exponentialRampToValueAtTime(0.01, now + 0.05);
osc.start(now); osc.stop(now + 0.05);
} else if (type === 'buy') {
osc.type = 'sine'; osc.frequency.setValueAtTime(800, now); osc.frequency.setValueAtTime(1200, now + 0.1);
gain.gain.setValueAtTime(0.1, now); gain.gain.linearRampToValueAtTime(0, now + 0.2);
osc.start(now); osc.stop(now + 0.2);
} else if (type === 'explosion') {
osc.type = 'sawtooth'; osc.frequency.setValueAtTime(100, now); osc.frequency.exponentialRampToValueAtTime(10, now + 0.3);
gain.gain.setValueAtTime(0.15, now); gain.gain.exponentialRampToValueAtTime(0.01, now + 0.3);
osc.start(now); osc.stop(now + 0.3);
}
}
};
function formatNumber(num) {
if (num >= 1e16) return (num / 1e16).toFixed(2) + ' Quadrillion';
if (num >= 1e15) return (num / 1e15).toFixed(2) + ' Quadrillion';
if (num >= 1e12) return (num / 1e12).toFixed(2) + ' Trillion';
if (num >= 1e9) return (num / 1e9).toFixed(2) + ' Billion';
if (num >= 1e6) return (num / 1e6).toFixed(2) + ' Million';
if (num >= 1e3) return (num / 1e3).toFixed(1) + ' K';
return Math.floor(num).toString();
}
const canvas = document.getElementById('game');
const ctx = canvas.getContext('2d');
let W, H, SCALE = 2;
function resize() {
W = canvas.width = Math.floor(innerWidth / SCALE);
H = canvas.height = Math.floor(innerHeight / SCALE);
canvas.style.width = innerWidth + 'px'; canvas.style.height = innerHeight + 'px';
}
window.addEventListener('resize', resize); resize();
let gameActive = false, loom = 1, score = 0, wave = 1, shake = 0;
let player = { x: 0, y: 0, hp: 100, maxHp: 100, speed: 2.5, lastShot: 0, facing: 0 };
let base = { x: 0, y: 60, hp: 1000, maxHp: 1000, damage: 20, range: 150, fireRate: 500, lastShot: 0, level: 1 };
let enemies = [], bullets = [], particles = [], army = [], planes = [], texts = [];
// 100 Zombie Types
const ZOMBIE_TYPES = [];
const zombiePrefixes = ["متعفن", "سريع", "مسلح", "مدرع", "سام", "مشع", "ظلي", "دموي", "مطفر", "سيبراني", "وحشي", "كاسر", "شبحي", "متفجر", "عملاق", "ملكي", "أسطوري", "كوني", "إلهي", "مدمر"];
for (let i = 1; i <= 100; i++) {
const prefix = zombiePrefixes[(i - 1) % zombiePrefixes.length];
const tier = Math.floor((i - 1) / zombiePrefixes.length) + 1;
const hp = Math.floor(50 * Math.pow(1.25, i));
const speed = 0.6 + (Math.random() * 1.2) - (i * 0.005);
const loomDrop = Math.floor(1 * Math.pow(1.35, i));
const hue = (i * 13) % 360;
ZOMBIE_TYPES.push({
id: i, name: `زومبي ${prefix} Mk.${tier}`, hp, speed: Math.max(0.3, speed), radius: 6 + (i * 0.1),
color: `hsl(${hue}, 70%, 40%)`, eyeColor: `hsl(${hue}, 100%, 70%)`,
loom: loomDrop, score: i * 10
});
}
const ARMY_TYPES = [
{ id: 'soldier', name: 'جندي مشاة', desc: 'يحمي القاعدة', cost: 500, hp: 100, damage: 15, rate: 600, range: 100, color: '#00ff00' },
{ id: 'heavy', name: 'جندي مدرع', desc: 'صحي جداً', cost: 2000, hp: 300, damage: 25, rate: 800, range: 80, color: '#ff8800' },
{ id: 'sniper', name: 'قناص', desc: 'مدى بعيد', cost: 5000, hp: 80, damage: 50, rate: 1500, range: 200, color: '#00ffff' }
];
const PLANE_TYPES = [
{ id: 'fighter', name: 'مقاتلة', desc: 'سريعة، تطلق النار', cost: 10000, hp: 200, damage: 30, rate: 400, range: 180, color: '#ff00ff', speed: 3 },
{ id: 'bomber', name: 'قاذفة', desc: 'انفجارية قوية', cost: 50000, hp: 400, damage: 80, rate: 1000, range: 150, color: '#ff6600', speed: 2, explosive: true },
{ id: 'stealth', name: 'شبحية', desc: 'سريعة جداً', cost: 200000, hp: 150, damage: 50, rate: 300, range: 200, color: '#888888', speed: 5 }
];
const BASE_UPGRADES = [
{ id: 'base_dmg', name: 'ضرر القاعدة', desc: '+25% ضرر', max: 50, baseCost: 1000, mult: 1.4, current: 0 },
{ id: 'base_range', name: 'مدى القاعدة', desc: '+20% مدى', max: 30, baseCost: 1500, mult: 1.5, current: 0 },
{ id: 'base_rate', name: 'سرعة إطلاق', desc: '-15% وقت', max: 30, baseCost: 2000, mult: 1.6, current: 0 },
{ id: 'base_hp', name: 'صحة القاعدة', desc: '+200 صحة', max: 50, baseCost: 800, mult: 1.3, current: 0 }
];
const UPGRADES = [
{ id: 'dmg', name: 'قوة هجومية', desc: '+20% ضرر اللاعب', max: 50, baseCost: 100, mult: 1.3, current: 0 },
{ id: 'rate', name: 'سرعة إطلاق', desc: '-10% وقت', max: 30, baseCost: 200, mult: 1.4, current: 0 },
{ id: 'hp', name: 'تعزيز الصحة', desc: '+25 صحة', max: 50, baseCost: 150, mult: 1.3, current: 0 },
{ id: 'speed', name: 'حذاء سريع', desc: '+10% سرعة', max: 20, baseCost: 300, mult: 1.5, current: 0 },
{ id: 'loom_mult', name: 'جشع LOOM', desc: '+25% LOOM', max: 50, baseCost: 500, mult: 1.4, current: 0 }
];
let joy = { active: false, dx: 0, dy: 0, originX: 0, originY: 0 };
const joyZone = document.getElementById('joystick-zone');
const joyThumb = document.getElementById('joy-thumb');
joyZone.addEventListener('pointerdown', e => {
e.preventDefault(); Audio.init();
joy.active = true;
const rect = joyZone.getBoundingClientRect();
joy.originX = rect.left + rect.width / 2;
joy.originY = rect.top + rect.height / 2;
updateJoy(e);
});
window.addEventListener('pointermove', e => { if (joy.active) { e.preventDefault(); updateJoy(e); } });
window.addEventListener('pointerup', () => { joy.active = false; joy.dx = 0; joy.dy = 0; joyThumb.style.transform = `translate(-50%, -50%)`; });
function updateJoy(e) {
let dx = e.clientX - joy.originX, dy = e.clientY - joy.originY;
const dist = Math.hypot(dx, dy), maxDist = 40;
if (dist > maxDist) { dx = (dx / dist) * maxDist; dy = (dy / dist) * maxDist; }
joy.dx = dx / maxDist; joy.dy = dy / maxDist;
joyThumb.style.transform = `translate(calc(-50% + ${dx}px), calc(-50% + ${dy}px))`;
}
function startGame() {
Audio.init();
document.getElementById('start-screen').style.display = 'none';
gameActive = true; loom = 1; score = 0; wave = 1;
player.hp = 100; player.maxHp = 100; player.x = W / 2; player.y = H / 2;
base.x = W / 2; base.y = 60; base.hp = 1000; base.maxHp = 1000;
enemies = []; bullets = []; particles = []; army = []; planes = []; texts = [];
updateHUD(); showNotification('الموجة 1 بدأت!');
gameLoop();
}
function spawnEnemy() {
if (enemies.length > 15 + wave * 2) return;
const maxTier = Math.min(100, Math.floor(wave * 1.5));
const minTier = Math.max(1, maxTier - 5);
const tierId = Math.floor(Math.random() * (maxTier - minTier + 1)) + minTier;
const type = ZOMBIE_TYPES[tierId - 1];
const side = Math.floor(Math.random() * 4);
let x = side === 0 ? Math.random() * W : (side === 1 ? W + 30 : (side === 2 ? Math.random() * W : -30));
let y = side === 0 ? -30 : (side === 1 ? Math.random() * H : (side === 2 ? H + 30 : Math.random() * H));
// الأعداء يقوون مع كل موجة
const waveMult = 1 + (wave * 0.1);
enemies.push({
...type, x, y,
hp: type.hp * waveMult,
maxHp: type.hp * waveMult,
speed: type.speed * (1 + wave * 0.05)
});
}
function baseShoot() {
if (!gameActive) return;
const rateMult = Math.pow(0.85, BASE_UPGRADES.find(u => u.id === 'base_rate').current);
const now = Date.now();
if (now - base.lastShot < base.fireRate * rateMult) return;
let target = null, minDist = base.range * (1 + BASE_UPGRADES.find(u => u.id === 'base_range').current * 0.2);
enemies.forEach(e => {
const d = Math.hypot(e.x - base.x, e.y - base.y);
if (d < minDist) { minDist = d; target = e; }
});
if (target) {
base.lastShot = now;
const dmgMult = 1 + (BASE_UPGRADES.find(u => u.id === 'base_dmg').current * 0.25);
const angle = Math.atan2(target.y - base.y, target.x - base.x);
bullets.push({
x: base.x, y: base.y + 20,
vx: Math.cos(angle) * 12, vy: Math.sin(angle) * 12,
damage: base.damage * dmgMult, color: '#00f3ff', size: 4,
life: 80, owner: 'base'
});
Audio.play('shoot');
}
}
function armyShoot(unit) {
const now = Date.now();
if (!unit.lastShot) unit.lastShot = 0;
if (now - unit.lastShot < unit.rate) return;
let target = null, minDist = unit.range;
enemies.forEach(e => {
const d = Math.hypot(e.x - unit.x, e.y - unit.y);
if (d < minDist) { minDist = d; target = e; }
});
if (target) {
unit.lastShot = now;
const angle = Math.atan2(target.y - unit.y, target.x - unit.x);
bullets.push({
x: unit.x, y: unit.y,
vx: Math.cos(angle) * 9, vy: Math.sin(angle) * 9,
damage: unit.damage, color: unit.color, size: 3, life: 60, owner: 'army'
});
}
}
function planeShoot(plane) {
const now = Date.now();
if (!plane.lastShot) plane.lastShot = 0;
if (now - plane.lastShot < plane.rate) return;
let target = null, minDist = plane.range;
enemies.forEach(e => {
const d = Math.hypot(e.x - plane.x, e.y - plane.y);
if (d < minDist) { minDist = d; target = e; }
});
if (target) {
plane.lastShot = now;
const angle = Math.atan2(target.y - plane.y, target.x - plane.x);
bullets.push({
x: plane.x, y: plane.y,
vx: Math.cos(angle) * 11, vy: Math.sin(angle) * 11,
damage: plane.damage, color: plane.color, size: 4,
explosive: plane.explosive || false, life: 70, owner: 'plane'
});
}
}
function update() {
if (!gameActive) return;
// Player Movement
const speedMult = 1 + (UPGRADES.find(u => u.id === 'speed').current * 0.1);
player.x += joy.dx * player.speed * speedMult;
player.y += joy.dy * player.speed * speedMult;
player.x = Math.max(15, Math.min(W - 15, player.x));
player.y = Math.max(15, Math.min(H - 15, player.y));
// Base & Army & Planes shoot
baseShoot();
army.forEach(u => armyShoot(u));
planes.forEach(p => {
planeShoot(p);
// Planes patrol around base
p.x += Math.sin(Date.now() * 0.001 + p.offset) * p.speed;
p.y = base.y - 40 + Math.cos(Date.now() * 0.0008 + p.offset) * 20;
});
// Bullets
for (let i = bullets.length - 1; i >= 0; i--) {
const b = bullets[i];
b.x += b.vx; b.y += b.vy; b.life--;
if (b.life <= 0 || b.x < 0 || b.x > W || b.y < 0 || b.y > H) { bullets.splice(i, 1); continue; }
for (let j = enemies.length - 1; j >= 0; j--) {
const e = enemies[j];
if (Math.hypot(b.x - e.x, b.y - e.y) < e.radius + b.size) {
e.hp -= b.damage;
addText(b.x, b.y, Math.floor(b.damage), '#fff');
Audio.play('hit');
createParticles(b.x, b.y, b.color, 4);
if (b.explosive) {
enemies.forEach(other => {
if (Math.hypot(b.x - other.x, b.y - other.y) < 60) other.hp -= b.damage * 0.5;
});
createParticles(b.x, b.y, '#ffaa00', 15); shake = 8;
}
bullets.splice(i, 1);
if (e.hp <= 0) killEnemy(e, j);
break;
}
}
}
// Enemies
for (let i = enemies.length - 1; i >= 0; i--) {
const e = enemies[i];
// Enemies target base first, then player
const targetX = base.x;
const targetY = base.y;
const angle = Math.atan2(targetY - e.y, targetX - e.x);
e.x += Math.cos(angle) * e.speed;
e.y += Math.sin(angle) * e.speed;
// Hit base
if (Math.hypot(e.x - base.x, e.y - base.y) < e.radius + 30) {
base.hp -= (e.id * 0.5) + 5;
Game Source: LOOM: FORTRESS DEFENSE
Creator: ChromeFlame24
Libraries: none
Complexity: complex (388 lines, 20.0 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-fortress-defense-chromeflame24" to link back to the original. Then publish at arcadelab.ai/publish.