🎮ArcadeLab

族群之争 · 大乱斗

by EpicCoder88
829 lines43.4 KB
▶ Play
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>族群之争 · 大乱斗</title>
<style>
  * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
  body {
    margin: 0; min-height: 100vh; background: #15171a;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    font-family: system-ui, -apple-system, sans-serif; color: #fff; overflow: hidden;
  }
  .game-wrapper { position: relative; width: 100vw; max-width: 368px; aspect-ratio: 1 / 1; box-shadow: 0 12px 48px rgba(0,0,0,.65); background: #2b2119; }
  canvas { display: block; width: 100%; height: 100%; touch-action: none; }
  .overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(21, 23, 26, 0.95); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 10; transition: opacity 0.3s; }
  .overlay.hidden { opacity: 0; pointer-events: none; }
  h1 { font-size: 24px; letter-spacing: 2px; margin-bottom: 5px; color: #e8d39a; }
  .subtitle { font-size: 13px; color: #9fb3c8; margin-bottom: 10px; }
  
  /* 支持 5 人混战的大网格 */
  .char-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 15px; max-height: 350px; overflow-y: auto; padding: 5px; }
  .char-card { 
    width: 95px; height: 110px; background: #232830; border: 2px solid #39414d; border-radius: 10px; 
    display: flex; flex-direction: column; align-items: center; justify-content: center; 
    cursor: pointer; transition: all 0.2s; user-select: none; position: relative;
  }
  .char-card:active { transform: scale(0.95); }
  .char-card.selected { border-color: #e08b3a; background: #3a2e21; box-shadow: 0 0 15px rgba(224, 139, 58, 0.4); }
  
  .char-card.guardian { border-color: #4ade80; }
  .char-card.boss { border-color: #ef4444; }
  .char-card.new-hero { border-color: #a855f7; }

  .char-icon { width: 45px; height: 45px; border-radius: 50%; margin-bottom: 5px; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 16px; color: #111; }
  .char-name { font-size: 13px; font-weight: bold; margin-bottom: 2px; }
  
  .char-tag { font-size: 9px; font-weight: bold; padding: 1px 4px; border-radius: 4px; }
  .tag-guardian { color: #4ade80; background: rgba(74, 222, 128, 0.15); }
  .tag-boss { color: #ef4444; background: rgba(239, 68, 68, 0.15); }
  .tag-new { color: #a855f7; background: rgba(168, 85, 247, 0.15); }

  button { background: #4ade80; color: #000; border: none; border-radius: 8px; padding: 12px 40px; font-size: 16px; font-weight: bold; cursor: pointer; transition: all 0.2s; opacity: 0.5; pointer-events: none; }
  button.enabled { opacity: 1; pointer-events: auto; box-shadow: 0 4px 15px rgba(74, 222, 128, 0.4); }
  
  #game-hud { position: absolute; top: 5px; left: 0; width: 100%; text-align: center; pointer-events: none; font-size: 14px; font-weight: bold; color: #fff; text-shadow: 0 2px 4px #000; opacity: 0; transition: 0.3s; line-height: 1.2; }
  #game-hud.show { opacity: 1; }
  #result-layer { background: rgba(21, 23, 26, 0.85); backdrop-filter: blur(3px); }
  #winner-text { font-size: 26px; color: #fbbf24; margin-bottom: 30px; text-shadow: 0 0 10px rgba(251, 191, 36, 0.5); }
</style>
</head>
<body>
<div class="game-wrapper">
  <canvas id="game"></canvas>
  <div id="game-hud"></div>
  <div id="ui-layer" class="overlay">
    <h1>族群之争</h1>
    <div class="subtitle">选择 2~5 名武士进行大乱斗</div>
    <div class="char-grid">
      <div class="char-card guardian" data-char="火星"><div class="char-icon" style="background:#f97316;">🔥</div><div class="char-name">火星</div><div class="char-tag tag-guardian">守门员</div></div>
      <div class="char-card boss" data-char="长鞭"><div class="char-icon" style="background:#1a1a1a; color:#ff0000;">🩸</div><div class="char-name">长鞭</div><div class="char-tag tag-boss">质检员</div></div>
      <div class="char-card" data-char="根泉"><div class="char-icon" style="background:#4b5563;">🌿</div><div class="char-name">根泉</div><div class="char-tag" style="opacity:0">-</div></div>
      <div class="char-card" data-char="鹰霜"><div class="char-icon" style="background:#e08b3a;">🦅</div><div class="char-name">鹰霜</div><div class="char-tag" style="opacity:0">-</div></div>
      <div class="char-card" data-char="灰翅"><div class="char-icon" style="background:#9ca3af;">🕊️</div><div class="char-name">灰翅</div><div class="char-tag" style="opacity:0">-</div></div>
      <div class="char-card" data-char="黄牙"><div class="char-icon" style="background:#e8d39a;">🌼</div><div class="char-name">黄牙</div><div class="char-tag" style="opacity:0">-</div></div>
      
      <div class="char-card new-hero" data-char="狮焰"><div class="char-icon" style="background:#fbbf24;">🦁</div><div class="char-name">狮焰</div><div class="char-tag tag-new">叹息之墙</div></div>
      <div class="char-card new-hero" data-char="石毛"><div class="char-icon" style="background:#6b7280;">🪨</div><div class="char-name">石毛</div><div class="char-tag tag-new">不屈之魂</div></div>
      <div class="char-card new-hero" data-char="羽尾"><div class="char-icon" style="background:#93c5fd;">🕊️</div><div class="char-name">羽尾</div><div class="char-tag tag-new">天降钟乳</div></div>
      <div class="char-card new-hero" data-char="蜡毛"><div class="char-icon" style="background:#374151; color:#a855f7;">🌫️</div><div class="char-name">蜡毛</div><div class="char-tag tag-new">三阶段Boss</div></div>
    </div>
    <button id="btn-start">开始大乱斗</button>
  </div>
  <div id="result-layer" class="overlay hidden">
    <div id="winner-text">胜者:火星</div>
    <button id="btn-restart" class="enabled">重新选择</button>
  </div>
</div>
<script>
(() => {
  const CELL = 32, COLS = 10, ROWS = 10, WALL = 24;
  const ARENA_W = CELL * COLS, ARENA_H = CELL * ROWS;
  const CANVAS_W = ARENA_W + WALL * 2, CANVAS_H = ARENA_H + WALL * 2;

  const canvas = document.getElementById('game');
  const ctx = canvas.getContext('2d');
  const dpr = Math.min(window.devicePixelRatio || 1, 2);
  canvas.width = CANVAS_W * dpr; canvas.height = CANVAS_H * dpr;
  ctx.setTransform(dpr, 0, 0, dpr, 0, 0);

  let entities = [], traps = [], projectiles = [], groundEffects = [], floatingTexts = [], effects = [];
  let stalactites = []; // 钟乳石
  let paused = true, gameStarted = false, selectedChars = [];
  let activeTeams = 0;

  class Cat {
    constructor(name, team, x, y, color, hp, isRanged, isMinion = false) {
      this.name = name; this.team = team;
      this.x = x; this.y = y; this.color = color;
      this.maxHp = hp; this.hp = hp; this.r = isMinion ? 8 : 14;
      this.isRanged = isRanged; this.isMinion = isMinion; this.alive = true;
      
      this.baseSpeed = 75;
      if (isRanged) this.baseSpeed = 65;
      if (name === '火星') this.baseSpeed = 85;
      if (name === '长鞭') this.baseSpeed = 90;
      if (name === '灰翅') this.baseSpeed = 60;
      if (name === '根泉') this.baseSpeed = 85;
      if (name === '狮焰') this.baseSpeed = 70;
      if (name === '石毛') this.baseSpeed = 70;
      this.speed = this.baseSpeed;
      
      this.atkCd = 0; this.skillCd = 0;
      this.atkRange = isRanged ? 200 : 32;
      if (name === '长鞭') this.atkRange = 16;
      if (name === '灰翅') this.atkRange = 240;
      if (name === '狮焰') this.atkRange = 42; // 1/3格约等于11px,这里放大点免得打不到
      if (name === '石毛') this.atkRange = 32;
      if (name === '羽尾') this.atkRange = 32;
      if (name === '蜡毛') this.atkRange = 32;
      
      this.atkDamage = 30;
      if (name === '火星') this.atkDamage = 28;
      if (name === '长鞭') this.atkDamage = 150;
      if (name === '灰翅') this.atkDamage = 20;
      if (name === '根泉') this.atkDamage = 35;
      if (name === '狮焰') this.atkDamage = 61;
      if (name === '石毛') this.atkDamage = 37;
      if (name === '羽尾') this.atkDamage = 74;
      if (name === '蜡毛') this.atkDamage = 54; // 一阶段
      if (isMinion) this.atkDamage = 45;
      
      this.scoutRange = 140;
      if (name === '火星') this.scoutRange = 180;
      if (name === '长鞭') this.scoutRange = 150;
      if (name === '灰翅') this.scoutRange = 280;
      if (name === '根泉') this.scoutRange = 160;
      if (name === '狮焰') this.scoutRange = 200;
      if (name === '石毛') this.scoutRange = 160;
      if (name === '羽尾') this.scoutRange = 160;
      if (name === '蜡毛') this.scoutRange = 160;
      if (isMinion) this.scoutRange = 120;

      this.wanderAngle = Math.random() * Math.PI * 2;
      this.wanderDistRemaining = 0;
      this.slowPercent = 0; this.slowTimer = 0;
      this.poisonTimer = 0; this.poisonTickTimer = 0;
      this.trapDebuffs = [];
      this.knockbackVx = 0; this.knockbackVy = 0;
      this.hitFlashTimer = 0;
      this.lockOnTimer = 0; this.lockOnTarget = null;

      this.critRate = 0.1; this.critMult = 1.5;
      if (name === '长鞭') { this.critRate = 0.05; this.critMult = 2.0; }
      if (name === '根泉') { this.critRate = 0.2; this.critMult = 1.8; }
      if (name === '灰翅') { this.critRate = 0.15; this.critMult = 2.0; }
      if (name === '火星') { this.critRate = 0.1; this.critMult = 1.5; }
      if (name === '狮焰') { this.critRate = 0.3; this.critMult = 1.5; } // 48/61约等于1.5
      if (name === '蜡毛') { this.critRate = 0; this.critMult = 1.2; } // 阶段二 89/73

      // 专属状态
      if (name === '火星') { this.hasRevived = false; this.invincibleTimer = 0; this.dashTimer = 0; this.damageDealt = 0; this.leaderBuff = 0; }
      if (name === '长鞭') { this.invincibleTimer = 0; this.damageTakenTracker = 0; }
      if (name === '灰翅') { this.asthmaTimer = 10; this.isAsthma = false; }
      if (name === '根泉') { this.damageTakenTracker = 0; this.possessedTimer = 0; this.nextHitGuaranteedCrit = false; this.markedTarget = null; this.markTimer = 0; }
      
      if (name === '狮焰') { this.damageReduction = 0.95; this.hitCount = 0; }
      if (name === '石毛') { this.isBerserk = false; this.unyieldingBuff = false; }
      if (name === '羽尾') { this.meteorTimer = 10; }
      if (name === '蜡毛') { this.stage = 1; this.fireHitTracker = 0; this.isCamouflaged = false; this.disguiseTimer = 0; this.suspicion = 0; }
    }

    takeDamage(amount, isPoison = false, attacker = null) {
      if (!this.alive || this.invincibleTimer > 0) return;

      // 狮焰减伤计算
      if (this.name === '狮焰') {
        amount = amount * this.damageReduction;
        // 减伤递减公式: Y_A = Y_A - 0.01 * n %
        this.hitCount++;
        this.damageReduction = Math.max(0, this.damageReduction - (0.01 * this.hitCount) / 100);
        // 受到伤害分摊给周围40%
        if (attacker && attacker !== this) {
           let nearby = entities.filter(e => e !== this && e.team !== this.team && Math.hypot(e.x - this.x, e.y - this.y) < 60 && e.alive);
           if (nearby.length > 0) {
              nearby[0].takeDamage(amount * 0.4, true); // 分摊伤害
           }
        }
      }

      // 蜡毛二阶段伪装期间免伤(除非被打破怀疑条)
      if (this.name === '蜡毛' && this.isCamouflaged && !isPoison) {
        this.suspicion += 15; // 挨打增加怀疑度
        if (this.suspicion >= 100) {
          this.isCamouflaged = false;
          floatingTexts.push({ x: this.x, y: this.y - 30, text: "伪装识破!", timer: 1.0, maxTimer: 1.0, color: '#a855f7' });
        }
        return; // 伪装期间不掉血
      }

      if (this.name === '长鞭' && !isPoison && Math.random() < 0.3) {
        let angle = attacker ? Math.atan2(this.y - attacker.y, this.x - attacker.x) : Math.random() * Math.PI * 2;
        this.knockbackVx = Math.cos(angle) * 800; this.knockbackVy = Math.sin(angle) * 800;
        this.invincibleTimer = 0.3;
        floatingTexts.push({ x: this.x, y: this.y - 30, text: "闪避!", timer: 0.8, maxTimer: 0.8, color: '#a855f7' });
        return;
      }
      
      // 石毛免控反杀(如果带有控制buff攻击他,如鹰霜陷阱/减速)
      if (this.name === '石毛' && this.slowTimer > 0 && Math.random() < 0.5) {
        this.slowTimer = 0; this.slowPercent = 0;
        this.unyieldingBuff = true;
        floatingTexts.push({ x: this.x, y: this.y - 30, text: "免控!", timer: 0.8, maxTimer: 0.8, color: '#a855f7' });
      }

      // 羽尾替死机制
      if (this.name === '羽尾' && !isPoison && Math.random() < 0.2) {
        let otherCats = entities.filter(e => e.alive && !e.isMinion && e !== this);
        let target = this; // 1v1默认给自己
        if (otherCats.length > 0) target = otherCats[Math.floor(Math.random() * otherCats.length)];
        
        let transferAmount = amount * 0.4;
        let remainAmount = amount * 0.6;
        
        if (target === this) {
          amount = remainAmount; // 自己只吃60%
        } else {
          target.takeDamage(transferAmount, true); // 伤害转移给其他人
        }
        
        this.hp += 2.5; // 回血
        floatingTexts.push({ x: this.x, y: this.y - 30, text: "星族庇佑!", timer: 0.8, maxTimer: 0.8, color: '#93c5fd' });
      }

      this.hp -= amount;
      
      if (!isPoison) {
        this.hitFlashTimer = 0.15;
        if (!this.isRanged && attacker && attacker.isRanged && !this.isMinion) {
          this.lockOnTimer = 3.0; this.lockOnTarget = attacker;
        }
        if (this.isRanged && attacker && Math.random() < 0.3) {
          let angle = Math.atan2(this.y - attacker.y, this.x - attacker.x);
          this.knockbackVx = Math.cos(angle) * 450; this.knockbackVy = Math.sin(angle) * 450;
        } else {
          let angle = Math.random() * Math.PI * 2;
          this.knockbackVx = Math.cos(angle) * 300; this.knockbackVy = Math.sin(angle) * 300;
        }
      }

      if (amount > 0) {
        floatingTexts.push({ x: this.x + (Math.random() * 20 - 10), y: this.y - 20 + (Math.random() * 10 - 5), text: Math.round(amount), timer: 0.8, maxTimer: 0.8, color: isPoison ? '#d946ef' : (amount > 200 ? '#ff0000' : '#ff4d4d'), isBig: amount > 200 });
      }

      // 专属受击触发
      if (this.name === '长鞭') { this.damageTakenTracker += amount; while (this.damageTakenTracker >= 100) { this.damageTakenTracker -= 100; this.summonMinions(); } }
      if (this.name === '根泉') {
        this.damageTakenTracker += amount;
        if (this.damageTakenTracker >= 150 && this.possessedTimer <= 0) {
          this.damageTakenTracker -= 150;
          this.possessedTimer = 2.0; this.nextHitGuaranteedCrit = true;
          effects.push({ type: 'revive', x: this.x, y: this.y, timer: 0.8, maxTimer: 0.8 });
        }
      }
      if (this.name === '石毛' && this.hp > 0 && this.hp <= this.maxHp * 0.3 && !this.isBerserk) {
        this.isBerserk = true; this.atkDamage = 100; this.slowPercent = 0.2; this.slowTimer = 999;
        floatingTexts.push({ x: this.x, y: this.y - 40, text: "不屈之魂!", timer: 1.2, maxTimer: 1.2, color: '#a855f7', isBig: true });
      }
      // 蜡毛阶段转换
      if (this.name === '蜡毛' && this.stage === 1 && this.hp <= 750) {
        this.stage = 2; this.atkDamage = 73; this.critRate = 0.3; this.critMult = 1.2;
        this.isCamouflaged = true; this.disguiseTimer = 15.0; this.suspicion = 0;
        groundEffects = []; // 清除火海
        floatingTexts.push({ x: this.x, y: this.y - 40, text: "伪装·黑莓星", timer: 1.5, maxTimer: 1.5, color: '#a855f7', isBig: true });
      }

      if (this.hp <= 0) {
        if (this.name === '火星' && !this.hasRevived) {
          this.hasRevived = true; this.hp = 1; this.invincibleTimer = 2.0;
          this.slowTimer = 0; this.slowPercent = 0; this.poisonTimer = 0; this.trapDebuffs = [];
          effects.push({ type: 'revive', x: this.x, y: this.y, timer: 1.0, maxTimer: 1.0 });
        } else {
          this.hp = 0; this.alive = false; 
          if (this.name === '蜡毛') {
            // 死亡黑水
            groundEffects.push({ x: this.x, y: this.y, r: 100, timer: 5.0, owner: this, seed: Math.random(), isBlackWater: true });
            floatingTexts.push({ x: this.x, y: this.y - 40, text: "黑水爆发!", timer: 1.5, maxTimer: 1.5, color: '#a855f7', isBig: true });
          }
          checkGameOver();
        }
      }
    }

    summonMinions() {
      let currentMinions = entities.filter(e => e.isMinion && e.team === this.team && e.alive).length;
      if (currentMinions >= 8) return;
      for (let i = 0; i < 2; i++) {
        let angle = Math.random() * Math.PI * 2;
        let dist = 30 + Math.random() * 20;
        let mx = this.x + Math.cos(angle) * dist, my = this.y + Math.sin(angle) * dist;
        mx = Math.max(10, Math.min(ARENA_W - 10, mx)); my = Math.max(10, Math.min(ARENA_H - 10, my));
        entities.push(new Cat('血族', this.team, mx, my, '#1a1a1a', 100, false, true));
        effects.push({ type: 'ring', x: mx, y: my, timer: 0.4, maxTimer: 0.4, color: '#ff0000' });
      }
    }

    update(dt) {
      if (!this.alive) return;

      if (this.hitFlashTimer > 0) this.hitFlashTimer -= dt;
      if (this.invincibleTimer > 0) this.invincibleTimer -= dt;
      if (this.slowTimer > 0 && this.slowTimer < 900) this.slowTimer -= dt; else if (this.slowTimer < 900) this.slowPercent = 0;
      
      if (this.poisonTimer > 0) {
        this.poisonTimer -= dt; this.poisonTickTimer -= dt;
        if (this.poisonTickTimer <= 0) { this.poisonTickTimer = 1.0; this.takeDamage(1, true); }
      }
      for (let i = this.trapDebuffs.length - 1; i >= 0; i--) {
        let debuff = this.trapDebuffs[i]; debuff.timeLeft -= dt;
        if (debuff.timeLeft > 0) {
          debuff.tickTimer -= dt;
          if (debuff.tickTimer <= 0) { debuff.tickTimer = 1.0; debuff.tickCount++; this.takeDamage(Math.pow(2, debuff.tickCount), true); }
        } else { this.trapDebuffs.splice(i, 1); }
      }

      // 羽尾钟乳石生成
      if (this.name === '羽尾') {
        this.meteorTimer -= dt;
        if (this.meteorTimer <= 0) {
          this.meteorTimer = 10.0;
          let count = Math.min(8, 15 - stalactites.length);
          let generated = 0;
          while (generated < count) {
            let sx = 20 + Math.random() * (ARENA_W - 40);
            if (!stalactites.some(s => Math.abs(s.x - sx) < 40)) {
              stalactites.push({ x: sx, y: -50, vy: 150, active: true, r: 16 });
              generated++;
            }
          }
        }
      }

      // 蜡毛火海生成
      if (this.name === '蜡毛' && this.stage === 1 && Math.random() < 0.02 && groundEffects.filter(g => g.isFire).length < 10) {
        groundEffects.push({ x: Math.random() * ARENA_W, y: Math.random() * ARENA_H, r: 25, timer: 8.0, owner: this, seed: Math.random(), isFire: true });
      }

      if (this.name === '根泉' && this.possessedTimer > 0) {
        this.possessedTimer -= dt;
        if (this.possessedTimer <= 0) this.nextHitGuaranteedCrit = false;
      }

      // 位移结算
      if (Math.abs(this.knockbackVx) > 1 || Math.abs(this.knockbackVy) > 1) {
        this.x += this.knockbackVx * dt; this.y += this.knockbackVy * dt;
        this.knockbackVx *= Math.pow(0.001, dt); this.knockbackVy *= Math.pow(0.001, dt);
      } else { this.knockbackVx = 0; this.knockbackVy = 0; }

      // 索敌(大乱斗:找非自己阵营的最近目标)
      let nearestEnemy = null, minDist = Infinity;
      for (let e of entities) { 
        if (e.team !== this.team && e.alive) { 
          let d = Math.hypot(e.x - this.x, e.y - this.y); 
          if (d < minDist) { minDist = d; nearestEnemy = e; } 
        } 
      }

      let inSight = nearestEnemy && minDist < this.scoutRange;
      let currentSpeed = this.speed * (1 - this.slowPercent);
      if (this.invincibleTimer > 0 && this.name === '火星') currentSpeed *= 1.5;
      if (this.dashTimer > 0 && this.name === '火星') currentSpeed *= 3.0;
      if (this.possessedTimer > 0 && this.name === '根泉') currentSpeed *= 2.0;

      let moveTarget = this.lockOnTimer > 0 && this.lockOnTarget ? this.lockOnTarget : (!this.isRanged && inSight && nearestEnemy ? nearestEnemy : null);

      // 伪装逻辑:伪装时原地不动,或者乱跑
      if (this.name === '蜡毛' && this.isCamouflaged) {
        moveTarget = null; // 伪装时停止主动攻击
        this.disguiseTimer -= dt;
        if (this.disguiseTimer <= 0) {
          this.isCamouflaged = false;
          floatingTexts.push({ x: this.x, y: this.y - 30, text: "伪装解除", timer: 1.0, maxTimer: 1.0, color: '#a855f7' });
        }
      }

      if (moveTarget) {
        let dx = moveTarget.x - this.x, dy = moveTarget.y - this.y, dist = Math.hypot(dx, dy);
        if (this.name === '火星' && this.dashTimer <= 0 && this.skillCd <= 0 && dist > this.atkRange) {
          this.dashTimer = 0.4; this.skillCd = 8.0;
        }
        if (this.dashTimer > 0) {
          this.dashTimer -= dt;
          this.x += (dx / dist) * currentSpeed * dt; this.y += (dy / dist) * currentSpeed * dt;
        } else if (dist > this.atkRange * 0.8) {
          this.x += (dx / dist) * currentSpeed * dt; this.y += (dy / dist) * currentSpeed * dt;
        }
      } else {
        if (this.wanderDistRemaining <= 0) { this.wanderAngle = Math.random() * Math.PI * 2; this.wanderDistRemaining = 10 + Math.random() * 40; }
        let step = currentSpeed * 0.6 * dt; if (step > this.wanderDistRemaining) step = this.wanderDistRemaining;
        let nextX = this.x + Math.cos(this.wanderAngle) * step, nextY = this.y + Math.sin(this.wanderAngle) * step;
        if (nextX < this.r || nextX > ARENA_W - this.r || nextY < this.r || nextY > ARENA_H - this.r) this.wanderDistRemaining = 0;
        else { this.x = nextX; this.y = nextY; this.wanderDistRemaining -= step; }
      }

      // 钟乳石物理碰撞(阻挡角色移动)
      for (let s of stalactites) {
        if (s.y > 0) {
          let dx = this.x - s.x, dy = this.y - (s.y + 20);
          let dist = Math.hypot(dx, dy);
          if (dist < this.r + s.r) {
            let angle = Math.atan2(dy, dx);
            this.x = s.x + Math.cos(angle) * (this.r + s.r);
            this.y = (s.y + 20) + Math.sin(angle) * (this.r + s.r);
          }
        }
      }

      if (this.trapDebuffs.length > 0 && this.dashTimer <= 0 && this.invincibleTimer <= 0) {
        for (let iter = 0; iter < 5; iter++) { for (let debuff of this.trapDebuffs) { let tDist = Math.hypot(this.x - debuff.center.x, this.y - debuff.center.y); if (tDist > 128) { let angle = Math.atan2(this.y - debuff.center.y, this.x - debuff.center.x); this.x = debuff.center.x + Math.cos(angle) * 128; this.y = debuff.center.y + Math.sin(angle) * 128; } } }
      }

      this.x = Math.max(this.r, Math.min(ARENA_W - this.r, this.x));
      this.y = Math.max(this.r, Math.min(ARENA_H - this.r, this.y));

      this.atkCd -= dt; this.skillCd -= dt;

      if (nearestEnemy && minDist <= this.atkRange && this.atkCd <= 0 && !(this.name === '蜡毛' && this.isCamouflaged)) {
        let slashAngle = Math.atan2(nearestEnemy.y - this.y, nearestEnemy.x - this.x);
        let slashColor = '#e08b3a';
        if (this.name === '火星') slashColor = '#f97316';
        if (this.name === '长鞭') slashColor = '#ff0000';
        if (this.name === '根泉') slashColor = '#4b5563';
        if (this.name === '狮焰') slashColor = '#fbbf24';
        if (this.name === '石毛') slashColor = '#6b7280';
        if (this.name === '羽尾') slashColor = '#93c5fd';
        if (this.name === '蜡毛') slashColor = this.stage === 1 ? '#ef4444' : '#a855f7';
        if (this.isMinion) slashColor = '#333';

        if (this.name === '灰翅') {
          this.atkCd = 1.5;
          let isCrit = Math.random() < (this.critRate + (nearestEnemy.markedTarget === this ? 0.15 : 0));
          nearestEnemy.takeDamage(this.atkDamage * (isCrit ? this.critMult : 1), false, this);
          nearestEnemy.markedTarget = this; nearestEnemy.markTimer = 3.0;
          effects.push({ type: 'slash', x: nearestEnemy.x, y: nearestEnemy.y, angle: slashAngle, timer: 0.2, maxTimer: 0.2, color: isCrit ? '#fbbf24' : '#9ca3af' });
        }
        else if (this.name === '根泉') {
          this.atkCd = 1.0;
          let isCrit = this.nextHitGuaranteedCrit || Math.random() < this.critRate;
          let finalDmg = isCrit ? this.atkDamage * (this.nextHitGuaranteedCrit ? 3.0 : this.critMult) : this.atkDamage;
          if (this.nextHitGuaranteedCrit) this.nextHitGuaranteedCrit = false;
          nearestEnemy.takeDamage(finalDmg, false, this);
          effects.push({ type: 'slash', x: nearestEnemy.x, y: nearestEnemy.y, angle: slashAngle, timer: 0.25, maxTimer: 0.25, color: isCrit ? '#fbbf24' : '#4b5563' });
          if (isCrit) { nearestEnemy.takeDamage(30, true); }
        }
        else if (this.name === '长鞭') {
          this.atkCd = 1.2;
          let hpRatio = this.hp / this.maxHp;
          let currentCrit = this.critRate + (1 - hpRatio) * 0.45;
          let isCrit = Math.random() < currentCrit;
          let finalDmg = isCrit ? 340 : 150;
          nearestEnemy.takeDamage(finalDmg, false, this);
          effects.push({ type: 'slash', x: nearestEnemy.x, y: nearestEnemy.y, angle: slashAngle, timer: 0.3, maxTimer: 0.3, color: isCrit ? '#ff0000' : slashColor });
        }
        else if (this.name === '火星') {
          this.atkCd = 1.0;
          let isCrit = Math.random() < this.critRate;
          let baseDmg = 28 + 28 * 0.05 * this.leaderBuff;
          let finalDmg = Math.round(baseDmg * (isCrit ? this.critMult : 1));
          nearestEnemy.takeDamage(finalDmg, false, this);
          effects.push({ type: 'slash', x: nearestEnemy.x, y: nearestEnemy.y, angle: slashAngle, timer: 0.2, maxTimer: 0.2, color: isCrit ? '#fbbf24' : slashColor });
          this.damageDealt += finalDmg;
          let newBuff = Math.floor(this.damageDealt / 100);
          if (newBuff > this.leaderBuff) { this.leaderBuff = newBuff; }
        }
        else if (this.name === '石毛') {
          this.atkCd = 1.0;
          let finalDmg = this.atkDamage;
          if (this.unyieldingBuff) { finalDmg = 270; this.unyieldingBuff = false; effects.push({ type: 'ring', x: nearestEnemy.x, y: nearestEnemy.y, timer: 0.4, maxTimer: 0.4, color: '#a855f7' }); }
          if (this.isBerserk && Math.random() < 0.3) { finalDmg = 130; } // 残血暴击
          nearestEnemy.takeDamage(finalDmg, false, this);
          effects.push({ type: 'slash', x: nearestEnemy.x, y: nearestEnemy.y, angle: slashAngle, timer: 0.2, maxTimer: 0.2, color: slashColor });
        }
        else if (this.name === '狮焰') {
          this.atkCd = 1.2;
          let isCrit = Math.random() < this.critRate;
          let finalDmg = isCrit ? 48 : 61;
          nearestEnemy.takeDamage(finalDmg, false, this);
          effects.push({ type: 'slash', x: nearestEnemy.x, y: nearestEnemy.y, angle: slashAngle, timer: 0.2, maxTimer: 0.2, color: slashColor });
        }
        else if (this.name === '羽尾') {
          this.atkCd = 1.2;
          nearestEnemy.takeDamage(this.atkDamage, false, this);
          effects.push({ type: 'slash', x: nearestEnemy.x, y: nearestEnemy.y, angle: slashAngle, timer: 0.2, maxTimer: 0.2, color: slashColor });
        }
        else if (this.name === '蜡毛') {
          this.atkCd = 1.2;
          if (this.isCamouflaged) {
            // 伪装期间攻击别人,别人会增加怀疑度,且不掉血
            nearestEnemy.suspicion = (nearestEnemy.suspicion || 0) + 20;
          } else {
            let isCrit = Math.random() < this.critRate;
            let finalDmg = isCrit ? 89 : 73;
            if (this.stage === 1) finalDmg = 54;
            nearestEnemy.takeDamage(finalDmg, false, this);
            effects.push({ type: 'slash', x: nearestEnemy.x, y: nearestEnemy.y, angle: slashAngle, timer: 0.2, maxTimer: 0.2, color: slashColor });
          }
        }
        else if (this.name === '鹰霜') {
          this.atkCd = 1.0;
          nearestEnemy.takeDamage(this.atkDamage, false, this);
          effects.push({ type: 'slash', x: nearestEnemy.x, y: nearestEnemy.y, angle: slashAngle, timer: 0.2, maxTimer: 0.2, color: slashColor });
        }
        else if (this.isRanged) {
          this.atkCd = 1.5;
          let dx = nearestEnemy.x - this.x, dy = nearestEnemy.y - this.y, dist = Math.hypot(dx, dy);
          let bulletSpeed = this.name === '灰翅' ? 200 : 250;
          projectiles.push({ x: this.x, y: this.y, vx: (dx / dist) * bulletSpeed, vy: (dy / dist) * bulletSpeed, damage: this.atkDamage, type: 'berry', owner: this, life: 3.0 });
        }
        else if (this.isMinion) {
          this.atkCd = 1.0;
          nearestEnemy.takeDamage(45, false, this);
        }
      }

      if (this.name === '鹰霜' && this.skillCd <= 0) {
        this.skillCd = 3.0;
        if (Math.random() < 0.8 && traps.length < 6) traps.push({ x: this.x, y: this.y, r: 25, armed: true, owner: this });
      }
    }

    draw() {
      if (!this.alive) return;
      let sx = WALL + this.x, sy = WALL + this.y;
      if (this.trapDebuffs.length > 0 && this.invincibleTimer <= 0 && this.dashTimer <= 0) { sx += (Math.random() - 0.5) * 4; sy += (Math.random() - 0.5) * 4; }

      if (!this.isMinion) {
        ctx.fillStyle = 'white'; ctx.font = 'bold 11px sans-serif'; ctx.textAlign = 'center';
        ctx.fillText(`${this.name} (${Math.ceil(this.hp)})`, sx, sy - this.r - 15);
        ctx.fillStyle = 'rgba(0,0,0,0.6)'; ctx.fillRect(sx - 18, sy - this.r - 10, 36, 4);
        ctx.fillStyle = this.hp > 300 ? '#4ade80' : '#ef4444'; ctx.fillRect(sx - 18, sy - this.r - 10, 36 * (this.hp / this.maxHp), 4);
        
        // 蜡毛怀疑条
        if (this.name === '蜡毛' && this.isCamouflaged) {
          ctx.fillStyle = '#a855f7'; ctx.font = 'bold 10px sans-serif';
          ctx.fillText(`怀疑: ${Math.min(100, this.suspicion)}%`, sx, sy - this.r - 25);
        }
      } else {
        ctx.fillStyle = 'rgba(0,0,0,0.6)'; ctx.fillRect(sx - 10, sy - this.r - 6, 20, 3);
        ctx.fillStyle = '#ef4444'; ctx.fillRect(sx - 10, sy - this.r - 6, 20 * (this.hp / this.maxHp), 3);
      }

      ctx.beginPath(); ctx.arc(sx, sy, this.r, 0, Math.PI * 2);
      ctx.fillStyle = this.hitFlashTimer > 0 ? '#ffffff' : this.color; ctx.fill();
      ctx.strokeStyle = this.isMinion ? '#ff0000' : '#000'; ctx.lineWidth = this.isMinion ? 1 : 2; ctx.stroke();

      if (this.invincibleTimer > 0) { ctx.beginPath(); ctx.arc(sx, sy, this.r + 4, 0, Math.PI * 2); ctx.strokeStyle = `rgba(255, 255, 255, 0.8)`; ctx.lineWidth = 3; ctx.stroke(); }
      if (this.slowTimer > 0) { ctx.beginPath(); ctx.arc(sx, sy, this.r + 2, 0, Math.PI * 2); ctx.strokeStyle = 'rgba(168, 85, 247, 0.8)'; ctx.lineWidth = 2; ctx.stroke(); }
      if (this.name === '蜡毛' && this.isCamouflaged) { ctx.beginPath(); ctx.arc(sx, sy, this.r + 3, 0, Math.PI * 2); ctx.strokeStyle = 'rgba(168, 85, 247, 0.5)'; ctx.setLineDash([3,3]); ctx.stroke(); ctx.setLineDash([]); }

      for (let debuff of this.trapDebuffs) {
        ctx.beginPath(); ctx.arc(WALL + debuff.center.x, WALL + debuff.center.y, 128, 0, Math.PI * 2);
        let alpha = 0.15 + 0.15 * Math.abs(Math.sin(debuff.timeLeft * 5));
        ctx.strokeStyle = `rgba(255, 50, 50, ${alpha})`; ctx.lineWidth = 1.5; ctx.setLineDash([5, 5]); ctx.stroke(); ctx.setLineDash([]);
      }
    }
  }

  // ================= 游戏控制 =================
  function startBattle() {
    if (selectedChars.length < 2) return;
    gameStarted = true;
    document.getElementById('ui-layer').classList.add('hidden');
    document.getElementById('result-layer').classList.add('hidden');
    document.getElementById('game-hud').classList.add('show');
    document.getElementById('game-hud').innerText = '大乱斗进行中...';
    
    entities = []; activeTeams = selectedChars.length;
    // 圆形排布出生点
    let centerX = ARENA_W / 2, centerY = ARENA_H / 2;
    let radius = 120;
    
    selectedChars.forEach((name, index) => {
      let angle = (index / selectedChars.length) * Math.PI * 2;
      let sx = centerX + Math.cos(angle) * radius;
      let sy = centerY + Math.sin(angle) * radius;
      
      let teamId = 'team_' + index;
      let cat;
      if (name === '鹰霜') cat = new Cat('鹰霜', teamId, sx, sy, '#e08b3a', 1030, false);
      if (name === '黄牙') cat = new Cat('黄牙', teamId, sx, sy, '#e8d39a', 1000, true);
      if (name === '火星') cat = new Cat('火星', teamId, sx, sy, '#f97316', 1050, false);
      if (name === '长鞭') cat = new Cat('长鞭', teamId, sx, sy, '#1a1a1a', 550, false);
      if (name === '灰翅') cat = new Cat('灰翅', teamId, sx, sy, '#9ca3af', 1000, true);
      if (name === '根泉') cat = new Cat('根泉', teamId, sx, sy, '#4b5563', 1000, false);
      if (name === '狮焰') cat = new Cat('狮焰', teamId, sx, sy, '#fbbf24', 2000, false);
      if (name === '石毛') cat = new Cat('石毛', teamId, sx, sy, '#6b7280', 1000, false);
      if (name === '羽尾') cat = new Cat('羽尾', teamId, sx, sy, '#93c5fd', 990, false);
      if (name === '蜡毛') cat = new Cat('蜡毛', teamId, sx, sy, '#374151', 1600, false);
      
      if (cat) entities.push(cat);
    });

    traps = []; projectiles = []; groundEffects = []; floatingTexts = []; effects = []; stalactites = [];
    paused = false;
  }

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

    // 钟乳石更新
    for (let i = stalactites.length - 1; i >= 0; i--) {
      let s = stalactites[i];
      s.y += s.vy * dt;
      
      // 砸中判定
      for (let e of entities) {
        if (e.alive && s.y > -20 && Math.hypot(e.x - s.x, e.y - s.y) < e.r + s.r) {
           if (!s.hit) {
             s.hit = true;
             e.takeDamage(210, false, null); // 砸中不扣血,靠推
             e.knockbackVx = 0; e.knockbackVy = 600; // 往下推
           }
           // 推人
           e.y += 250 * dt;
        }
      }
      
      if (s.y > ARENA_H - 20) {
        s.y = ARENA_H - 20; s.vy = 0; // 砸到底部停下变成障碍物
        if (s.active) { s.active = false; s.timer = 3.0; effects.push({type:'ring', x: s.x, y: s.y, timer: 0.5, maxTimer: 0.5, color: '#93c5fd'}); }
      }
      
      if (!s.active) {
        s.timer -= dt;
        if (s.timer <= 0) stalactites.splice(i, 1);
      }
    }

    for (let entity of entities) { if (entity.alive) entity.update(dt); }

    for (let e of entities) { if (e.markTimer > 0) { e.markTimer -= dt; if (e.markTimer <= 0) e.markedTarget = null; } }

    for (let i = traps.length - 1; i >= 0; i--) {
      let t = traps[i]; if (!t.armed) continue;
      for (let entity of entities) {
        if (!entity.alive || entity.team === t.owner.team || entity.invincibleTimer > 0) continue;
        if (Math.hypot(entity.x - t.x, entity.y - t.y) < entity.r + t.r) {
          t.armed = false; traps.splice(i, 1);
          entity.trapDebuffs.push({ center: { x: t.x, y: t.y }, timeLeft: 5.0, tickTimer: 1.0, tickCount: 0 });
          entity.slowPercent = 0.3; entity.slowTimer = 5.0;
          effects.push({ type: 'ring', x: t.x, y: t.y, timer: 0.3, maxTimer: 0.3, color: '#ef4444' });
        }
      }
    }

    for (let i = projectiles.length - 1; i >= 0; i--) {
      let p = projectiles[i]; p.life -= dt;
      p.x += p.vx * dt; p.y += p.vy * dt;
      
      // 钟乳石挡子弹
      let blocked = false;
      for (let s of stalactites) { if (s.y > 0 && Math.hypot(p.x - s.x, p.y - s.y) < s.r) { blocked = true; break; } }
      if (blocked) { projectiles.splice(i, 1); continue; }

      if (p.x < 0 || p.x > ARENA_W || p.y < 0 || p.y > ARENA_H || p.life <= 0) { projectiles.splice(i, 1); continue; }
      let hit = false;
      for (let entity of entities) {
        if (entity.alive && entity.team !== p.owner.team && Math.hypot(entity.x - p.x, entity.y - p.y) < entity.r + 6) {
          entity.takeDamage(p.damage, false, p.owner);
          entity.poisonTimer = 5.0; entity.poisonTickTimer = 1.0;
          groundEffects.push({ x: entity.x, y: entity.y, r: 30, timer: 20, owner: p.owner, seed: Math.random() });
          effects.push({ type: 'ring', x: entity.x, y: entity.y, timer: 0.3, maxTimer: 0.3, color: '#d946ef' });
          hit = true; break;
        }
      }
      if (hit) projectiles.splice(i, 1);
    }

    for (let i = groundEffects.length - 1; i >= 0; i--) {
      let g = groundEffects[i]; g.timer -= dt;
      if (g.timer <= 0) { groundEffects.splice(i, 1); continue; }
      
      if (g.isFire) {
        // 火海蔓延
        if (Math.random() < 0.05 && groundEffects.filter(ge => ge.isFire).length < 10) {
           groundEffects.push({ x: g.x + (Math.random()-0.5)*40, y: g.y + (Math.random()-0.5)*40, r: 25, timer: 8.0, owner: g.owner, seed: Math.random(), isFire: true });
        }
      }

      if (Math.random() < 0.05 && !g.isBlackWater) {
        effects.push({ type: 'bubble', x: g.x + (Math.random() - 0.5) * g.r * 1.5, y: g.y + (Math.random() - 0.5) * g.r * 1.5, timer: 0.6, maxTimer: 0.6 });
      }
      
      for (let entity of entities) {
        if (!entity.alive || entity.team === g.owner.team || entity.invincibleTimer > 0) continue;
        if (Math.hypot(entity.x - g.x, entity.y - g.y) < entity.r + g.r) {
          if (g.isBlackWater) {
             entity.takeDamage(5000, true); // 黑水真伤
          } else if (g.isFire) {
             entity.takeDamage(5, true); // 火海真伤
          } else {
             if (entity.slowPercent < 0.2) { entity.slowPercent = 0.2; entity.slowTimer = 0.5; }
             if (!entity.juiceTick) entity.juiceTick = 0;
             entity.juiceTick -= dt;
             if (entity.juiceTick <= 0) { entity.juiceTick = 1.0; entity.takeDamage(1, true); }
          }
        }
      }
    }

    // 清理死掉的实体
    for (let i = entities.length - 1; i >= 0; i--) { if (!entities[i].alive) entities.splice(i, 1); }
    
    // 检查胜利
    let aliveNonMinions = entities.filter(e => e.alive && !e.isMinion);
    if (aliveNonMinions.length <= 1 && gameStarted) {
       paused = true; gameStarted = false;
       let winner = aliveNonMinions.length === 1 ? aliveNonMinions[0].name : '平局';
       document.getElementById('game-hud').classList.remove('show');
       document.getElementById('winner-text').innerText = `胜者:${winner}`;
       document.getElementById('result-layer').classList.remove('hidden');
    }

    for (let i = effects.length - 1; i >= 0; i--) { effects[i].timer -= dt; if (effects[i].timer <= 0) effects.splice(i, 1); }
    for (let i = floatingTexts.length - 1; i >= 0; i--) { let ft = floatingTexts[i]; ft.y -= 30 * dt; ft.timer -= dt; if (ft.timer <= 0) floatingTexts.splice(i, 1); }
  }

  function draw() {
    ctx.fillStyle = '#2b2119'; ctx.fillRect(0, 0, CANVAS_W, CANVAS_H);
    ctx.fillStyle = '#55734a'; ctx.fillRect(WALL, WALL, ARENA_W, ARENA_H);
    ctx.strokeStyle = 'rgba(255,255,255,0.075)'; ctx.beginPath();
    for (let i = 1; i < COLS; i++) { ctx.moveTo(WALL + i * CELL, WALL); ctx.lineTo(WALL + i * CELL, WALL + ARENA_H); }
    for (let j = 1; j < ROWS; j++) { ctx.moveTo(WALL, WALL + j * CELL); ctx.lineTo(WALL + ARENA_W, WALL + j * CELL); }
    ctx.stroke();

    // 绘制地形
    for (let g of groundEffects) {
      if (g.isBlackWater) {
         ctx.fillStyle = 'rgba(0, 0, 0, 0.8)'; // 黑水
      } else if (g.isFire) {
         ctx.fillStyle = 'rgba(239, 68, 68, 0.4)'; // 火海
      } else {
         ctx.fillStyle = 'rgba(126, 34, 206, 0.5)'; // 毒液
      }
      ctx.beginPath();
      for (let a = 0; a < Math.PI * 2; a += Math.PI / 4) { let r = g.r * (0.8 + Math.sin(a * 3 + g.seed) * 0.2); let px = WALL + g.x + Math.cos(a) * r, py = WALL + g.y + Math.sin(a) * r; if (a === 0) ctx.moveTo(px, py); else ctx.lineTo(px, py); }
      ctx.closePath(); ctx.fill();
    }

    // 绘制钟乳石
    for (let s of stalactites) {
      ctx.fillStyle = s.active ? '#93c5fd' : '#64748b';
      ctx.beginPath();
      ctx.moveTo(WALL + s.x - s.r, WALL + s.y - 100); // 上方看不见的部分
      ctx.lineTo(WALL + s.x + s.r, WALL + s.y - 100);
      ctx.lineTo(WALL + s.x, WALL + s.y + 20); // 尖底
      ctx.closePath(); ctx.fill();
      ctx.strokeStyle = '#1e3a8a'; ctx.stroke();
    }

    for (let t of traps) {
      ctx.beginPath(); ctx.arc(WALL + t.x, WALL + t.y, t.r, 0, Math.PI * 2); ctx.fillStyle = 'rgba(239, 68, 68, 0.3)'; ctx.fill();
      let pulse = 1 + Math.sin(Date.now() / 150) * 0.1; ctx.beginPath();
      for (let i = 0; i < 6; i++) { let ang = i * Math.PI / 3; let px = WALL + t.x + Math.cos(ang) * t.r * 0.6 * pulse, py = WALL + t.y + Math.sin(ang) * t.r * 0.6 * pulse; if (i === 0) ctx.moveTo(px, py); else ctx.lineTo(px, py); }
      ctx.closePath(); ctx.strokeStyle = '#ef4444'; ctx.lineWidth = 2; ctx.stroke();
    }
    for (let p of projectiles) {
      ctx.beginPath(); ctx.arc(WALL + p.x, WALL + p.y, 6, 0, Math.PI * 2); ctx.fillStyle = '#d946ef'; ctx.fill(); ctx.strokeStyle = '#4a044e'; ctx.lineWidth = 1; ctx.stroke();
    }
    
    if (gameStarted) for (let entity of entities) entity.draw();

    for (let e of effects) {
      let progress = 1 - (e.timer / e.maxTimer);
      if (e.type === 'slash') {
        ctx.save(); ctx.translate(WALL + e.x, WALL + e.y); ctx.rotate(e.angle); ctx.strokeStyle = e.color; ctx.globalAlpha = 1 - progress; ctx.lineWidth = 3; ctx.lineCap = 'round';
        for (let i = -1; i <= 1; i++) { ctx.beginPath(); ctx.moveTo(0, i * 8 - 5); ctx.quadraticCurveTo(15, i * 8 + 5, 30, i * 8 - 5); ctx.stroke(); }
        ctx.restore();
      } else if (e.type === 'revive') { ctx.beginPath(); ctx.arc(WALL + e.x, WALL + e.y, 14 + progress * 60, 0, Math.PI * 2); ctx.strokeStyle = `rgba(255, 215, 0, ${1 - progress})`; ctx.lineWidth = 4; ctx.stroke(); }
      else if (e.type === 'ring') { ctx.beginPath(); ctx.arc(WALL + e.x, WALL + e.y, 10 + progress * 20, 0, Math.PI * 2); ctx.strokeStyle = e.color; ctx.globalAlpha = 1 - progress; ctx.lineWidth = 2; ctx.stroke(); }
    }
    ctx.globalAlpha = 1;

    for (let ft of floatingTexts) {
      let progress = 1 - (ft.timer / ft.maxTimer); let scale = progress < 0.2 ? (progress / 0.2) : (1 - (progress - 0.2) / 0.8 * 0.5); let fontSize = ft.isBig ? 22 : 16;
      ctx.save(); ctx.translate(WALL + ft.x, WALL + ft.y); ctx.scale(scale, scale);
      ctx.font = `bold ${fontSize}px sans-serif`; ctx.textAlign = 'center'; ctx.globalAlpha = Math.min(1, ft.timer * 2);
      ctx.lineWidth = 3; ctx.strokeStyle = '#000'; ctx.strokeText(ft.text, 0, 0);
      ctx.fillStyle = ft.color; ctx.fillText(ft.text, 0, 0); ctx.restore();
    }
  }

  const cards = document.querySelectorAll('.char-card');
  const btnStart = document.getElementById('btn-start');
  const btnRestart = document.getElementById('btn-restart');

  cards.forEach(card => {
    card.addEventListener('click', () => {
      const charName = card.dataset.char;
      if (card.classList.contains('selected')) { 
        card.classList.remove('selected'); 
        selectedChars = selectedChars.filter(c => c !== charName); 
      } else {
        if (selectedChars.length >= 5) return; // 最多选5个
        card.classList.add('selected'); selectedChars.push(charName);
      }
      btnStart.classList.toggle('enabled', selectedChars.length >= 2);
    });
  });

  btnStart.addEventListener('click', startBattle);
  btnRestart.addEventListener('click', () => {
    document.getElementById('result-layer').classList.add('hidden');
    document.getElementById('ui-layer').classList.remove('hidden');
    selectedChars = []; cards.forEach(c => c.classList.remove('selected')); btnStart.classList.remove('enabled');
    gameStarted = false; entities = []; traps = []; projectiles = []; groundEffects = []; floatingTexts = []; effects = []; stalactites = [];
    draw();
  });

  let last = performance.now();
  function loop(now) {
    let dt = Math.min((now - last) / 1000, 0.1); last = now;
    update(dt); draw(); requestAnimationFrame(loop);
  }
  requestAnimationFrame(loop);
})();
</script>
</body>
</html>

Game Source: 族群之争 · 大乱斗

Creator: EpicCoder88

Libraries: none

Complexity: complex (829 lines, 43.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: game-epiccoder88-mx0eojvu" to link back to the original. Then publish at arcadelab.ai/publish.