import { Button, isDown } from '../input'; import { Anim, Character, type CharacterContext } from './Character'; import { aimDir } from './Mamie'; /** * Gégé le Ver. * - Attack: headbutt. * - Special (held): swims through the cake toward the aim in a narrow tunnel. Breaking out of * the terrain (or letting go while underground), he bursts up and sends flying whoever stands * right above. * - Flaw: slow, and fragile in the open (takes extra knockback unless underground). */ export class Gege extends Character { private headTimer = 0; private digTimer = 0; /** Seconds of swimming thrust left: renewed while there is cake around him. */ private swimTime = 0; private underground = false; private swimming = false; /** Pixels eaten by the last dig, to notice he broke out into the open. */ private lastDug = 0; onAttack(ctx: CharacterContext): void { const p = this.stats.params; const [dx, dy] = aimDir(ctx); const reach = this.size + p.headReach; const hx = ctx.x + dx * reach; const hy = ctx.y + dy * reach; ctx.hit(hx, hy, p.headRadius, p.headKnockback, p.headStun); ctx.emitOp({ kind: 'carve', x: Math.round(hx), y: Math.round(hy), r: Math.round(p.headCarve), power: Math.round(p.headPower) }); this.headTimer = p.headAnim; } onSpecial(_ctx: CharacterContext): void {} override onTick(ctx: CharacterContext, dt: number): void { const p = this.stats.params; this.headTimer = Math.max(0, this.headTimer - dt); this.swimTime = Math.max(0, this.swimTime - dt); this.swimming = isDown(ctx.input, Button.Special); if (!this.swimming) { if (this.underground) this.emerge(ctx); this.digTimer = 0; return; } const [dx, dy] = aimDir(ctx); if (this.swimTime > 0) ctx.setVelocity(dx * p.swimSpeed, dy * p.swimSpeed); this.digTimer -= dt; if (this.digTimer > 0) return; this.digTimer = p.digInterval; const front = this.size * 0.5; // Nothing left to eat ahead: either he broke out into the open (burst up), or he is // blocked by something too hard for him (he just stops). if (this.underground && this.lastDug < p.swimMinPixels) { const ahead = this.size + 4; if (!ctx.isSolid(ctx.x + dx * ahead, ctx.y + dy * ahead)) { this.emerge(ctx); return; } } ctx.emitOp( { kind: 'carve', x: Math.round(ctx.x + dx * front), y: Math.round(ctx.y + dy * front), r: Math.round(this.size * p.tunnelFactor), power: Math.round(p.swimPower) }, (n) => { this.lastDug = n; if (n >= p.swimMinPixels) { this.swimTime = p.swimGrace; this.underground = true; } }, ); } /** Bursts out of the cake: whoever stands above him goes flying. */ private emerge(ctx: CharacterContext): void { const p = this.stats.params; this.underground = false; this.lastDug = 0; this.swimTime = 0; ctx.hit(ctx.x, ctx.y - this.size, this.size * p.emergeRadiusFactor, p.emergeKnockback, p.emergeStun); ctx.setVelocity(ctx.vx * 0.5, -p.emergeHop); ctx.cue('emerge'); } override anim(): number { return (this.headTimer > 0 ? Anim.Attack : 0) | (this.swimming ? Anim.Special : 0) | (this.underground ? Anim.Underground : 0); } override knockbackTaken(): number { return this.underground ? this.stats.params.buriedKnockback : this.stats.params.exposedKnockback; } }