/** * 🐝 enemy.bee — abeja guardiana del Bosque Susurro. Vuela en zigzag, persigue al hĂ©roe a media * altura y se congela con HIELO (cae al suelo como un carĂĄmbano). No es burnable: el FUEGO no la * resuelve, asĂ­ que el jugador debe usar HIELO o golpearla. * Props: { facing?, range?, patrol?: [x0, x1] } */ import * as THREE from 'three'; import { createChibi } from '../../characters/chibi'; import type { Props } from '../../core/types'; import { toonMaterial } from '../../render'; import { Enemy, approach, clampPatrol } from './base'; const BEE = { hp: 2, hw: 0.3, hh: 0.28, size: 0.66, range: 7, color: 0xffc928, chase: 3.4, }; const clamp = (v: number, lo: number, hi: number): number => Math.max(lo, Math.min(hi, v)); let wingGeo: THREE.BufferGeometry | null = null; let wingMat: THREE.Material | null = null; let stripeMat: THREE.Material | null = null; function sharedWing(): { geo: THREE.BufferGeometry; mat: THREE.Material } { if (!wingGeo) { wingGeo = new THREE.SphereGeometry(1, 14, 10); wingGeo.userData.shared = true; wingMat = toonMaterial({ color: 0xeaf6ff, emissive: 0x9fd8ff, emissiveIntensity: 0.18, transparent: true, opacity: 0.58, depthWrite: false, gloss: 1, rim: 0.8, }); wingMat.userData.shared = true; stripeMat = toonMaterial({ color: 0x2b2430, gloss: 0.4, rim: 0.2 }); stripeMat.userData.shared = true; } return { geo: wingGeo!, mat: wingMat! }; } export class Bee extends Enemy { private ax = 0; private ay = 0; private seed = 0; private readonly wings: THREE.Object3D[] = []; constructor(props: Props) { super(props); this.hw = BEE.hw; this.hh = BEE.hh; this.maxHp = BEE.hp; this.flying = true; this.freezable = true; this.burnable = false; this.contactDamage = 1; this.shadowRadius = 0.3; this.dizzyHeight = 0.12; this.state = 'fly'; } protected build(): void { this.rig = createChibi({ color: BEE.color, size: BEE.size, expression: 'angry', hands: false, emissive: 0xffa800, emissiveIntensity: 0.1, }); // franjas negras sobre el cuerpo const s = sharedWing(); const bodyR = BEE.size * 0.5; for (const y of [-0.09, 0.09]) { const stripe = new THREE.Mesh(s.geo, stripeMat!); stripe.scale.set(bodyR * 1.02, 0.045, bodyR * 1.02); stripe.position.y = y * BEE.size; this.rig.root.add(stripe); } // alas translĂșcidas for (const side of [-1, 1]) { const pivot = new THREE.Group(); pivot.position.set(side * 0.18, 0.16, -0.06); const w = new THREE.Mesh(s.geo, s.mat); w.scale.set(0.24, 0.06, 0.14); w.position.x = side * 0.16; w.rotation.z = side * 0.2; pivot.add(w); this.visual.add(pivot); this.wings.push(pivot); } } protected afterAdded(): void { this.ax = this.x; this.ay = this.y; this.seed = Math.random() * Math.PI * 2; } protected stunFalls(): boolean { return false; } protected think(dt: number): void { const b = this.body; const p = this.props; const hero = this.hero; const d = this.heroDelta(); let tx = this.ax + Math.sin(this.t * 1.1 + this.seed) * 1.6; let ty = this.ay; if (hero && d && Math.abs(d.dx) < (p.range ?? BEE.range) && Math.abs(d.dy) < 5) { this.facing = d.dx > 0 ? 1 : -1; tx = hero.x - this.facing * 0.7; ty = hero.y + 1.15; // si estĂĄ encima, retrocede un poco para no acosar sin pausa if (Math.abs(d.dx) < 0.9) tx = this.x - this.facing * 2.2; } else if (Math.random() < 0.002) { this.facing = -this.facing as 1 | -1; } if (clampPatrol(this, p.patrol, this.facing)) tx = clamp(tx, p.patrol![0], p.patrol![1]); const vx = clamp((tx - b.x) * 2.6, -BEE.chase, BEE.chase); const vy = clamp((ty + Math.sin(this.t * 2.7 + this.seed) * 0.38 - b.y) * 3.2, -4.2, 4.2); b.vx = approach(b.vx, vx, 16 * dt); b.vy = approach(b.vy, vy, 18 * dt); } protected animate(dt: number): void { const b = this.body; this.rig?.update(dt, { vx: b.vx, vy: b.vy, onGround: true, facing: this.facing }); const flap = 1 + Math.sin(this.t * 34 + this.seed) * 0.55; for (let i = 0; i < this.wings.length; i++) { const s = i === 0 ? -1 : 1; this.wings[i].rotation.z = s * (0.18 + 0.34 * flap); this.wings[i].scale.y = 0.85 + 0.2 * flap; } this.visual.position.y = Math.sin(this.t * 3 + this.seed) * 0.03; } }