/** * `item.balloon` 🎈 `{ id }` — globo rojo alienígena con cuerda. `y` = extremo inferior de la cuerda * (el globo queda ~1.3 u más arriba). Solo revienta con golpes de elemento `water` (pistola de agua): * `lagoon.balloons` +1, flag `balloon.` (no reaparece), confeti y POI en el automapa. */ import * as THREE from 'three'; import { Entity } from '../../core/entity'; import type { Hit, Props } from '../../core/types'; import { rand } from '../../core/math'; import { emojiMesh } from '../../render'; const STRING_PTS = 8; const LIFT = 1.35; export class Balloon extends Entity { private readonly balloonId: string; private readonly flag: string; private readonly holder = new THREE.Group(); private readonly line: THREE.Line; private readonly pos: Float32Array; private t = rand(0, 10); private wob = 0; private wobV = 0; private popped = false; constructor(props: Props, x: number, y: number) { super(); this.team = 'neutral'; this.tags.add('item'); this.balloonId = String(props.id ?? `b${Math.round(x * 10)}_${Math.round(y * 10)}`); this.flag = `balloon.${this.balloonId}`; const m = emojiMesh('🎈', 1.25, { gloss: 0.9 }); this.holder.add(m); this.view.add(this.holder); this.pos = new Float32Array(STRING_PTS * 3); const geo = new THREE.BufferGeometry(); geo.setAttribute('position', new THREE.BufferAttribute(this.pos, 3)); this.line = new THREE.Line(geo, new THREE.LineBasicMaterial({ color: 0xf4f1ff, transparent: true, opacity: 0.85 })); this.line.frustumCulled = false; this.view.add(this.line); } onAdded(): void { const g = this.game; if (g.state.has(this.flag)) { this.kill(); return; } if (g.zone) g.events.emit('map:poi', { zone: g.zone.id, x: this.x, y: this.y + LIFT, emoji: '🎈', id: this.flag }); } bounds() { return { x: this.x, y: this.y + LIFT, hw: 0.5, hh: 0.6 }; } takeHit(hit: Hit): boolean { if (this.popped) return false; if (hit.element === 'water') { this.pop(); return true; } // Otros golpes: se bambolea y rebota, pero no revienta. this.wobV += (hit.dirX || 1) * 6; this.game.audio.sfx('bounce', { pitch: 1.5, volume: 0.5, x: this.x }); this.game.vfx.floatText('¡Necesitas agua! 💧', this.x, this.y + LIFT + 0.9, '#9fe8ff'); return false; } private pop(): void { const g = this.game; const st = g.state; this.popped = true; const cx = this.x; const cy = this.y + LIFT; st.set(this.flag, true); const n = st.inc('lagoon.balloons'); if (g.zone) delete st.data.flags[`map.poi.${g.zone.id}.${this.flag}`]; g.audio.sfx('pop', { x: cx }); g.vfx.burst('confetti', cx, cy, { count: 26 }); g.vfx.burst('poof', cx, cy, { count: 8, color: 0xf2452e }); g.vfx.ring(cx, cy, 0xff5040, 1.2); g.vfx.floatText(`🎈 ${Math.min(n, 3)}/3`, cx, cy + 0.8, '#ffe066'); g.gfx.cam.shake(0.15, 0.12); g.hitstop(0.05); g.events.emit('item:collected', { type: this.type, id: this.balloonId, x: cx, y: cy }); st.save(); this.kill(); } render(alpha: number, dt: number): void { super.render(alpha, dt); this.t += dt; // Muelle del bamboleo this.wobV += (-this.wob * 30 - this.wobV * 3) * dt; this.wob += this.wobV * dt; const sway = Math.sin(this.t * 1.3) * 0.12 + this.wob * 0.25; const bob = Math.sin(this.t * 1.9) * 0.1; this.holder.position.set(sway, LIFT + bob, 0); this.holder.rotation.z = -sway * 0.6; const s = 1 + Math.sin(this.t * 2.4) * 0.025; this.holder.scale.set(s, 1 / s, 1); // Cuerda: del nudo (bajo el globo) a la base, curvada. const topX = sway * 0.9; const topY = LIFT + bob - 0.6; const p = this.pos; for (let i = 0; i < STRING_PTS; i++) { const k = i / (STRING_PTS - 1); p[i * 3] = topX * (1 - k) + Math.sin(k * Math.PI + this.t * 2.2) * 0.06; p[i * 3 + 1] = topY * (1 - k); p[i * 3 + 2] = 0; } (this.line.geometry.attributes.position as THREE.BufferAttribute).needsUpdate = true; } }