Gege.ts 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { Button, isDown } from '../input';
  2. import { Anim, Character, type CharacterContext } from './Character';
  3. import { aimDir } from './Mamie';
  4. /**
  5. * Gégé le Ver.
  6. * - Attack: headbutt.
  7. * - Special (held): swims through the cake toward the aim in a narrow tunnel. Breaking out of
  8. * the terrain (or letting go while underground), he bursts up and sends flying whoever stands
  9. * right above.
  10. * - Flaw: slow, and fragile in the open (takes extra knockback unless underground).
  11. */
  12. export class Gege extends Character {
  13. private headTimer = 0;
  14. private digTimer = 0;
  15. /** Seconds of swimming thrust left: renewed while there is cake around him. */
  16. private swimTime = 0;
  17. private underground = false;
  18. private swimming = false;
  19. /** Pixels eaten by the last dig, to notice he broke out into the open. */
  20. private lastDug = 0;
  21. onAttack(ctx: CharacterContext): void {
  22. const p = this.stats.params;
  23. const [dx, dy] = aimDir(ctx);
  24. const reach = this.size + p.headReach;
  25. const hx = ctx.x + dx * reach;
  26. const hy = ctx.y + dy * reach;
  27. ctx.hit(hx, hy, p.headRadius, p.headKnockback, p.headStun);
  28. ctx.emitOp({ kind: 'carve', x: Math.round(hx), y: Math.round(hy), r: Math.round(p.headCarve), power: Math.round(p.headPower) });
  29. this.headTimer = p.headAnim;
  30. }
  31. onSpecial(_ctx: CharacterContext): void {}
  32. override onTick(ctx: CharacterContext, dt: number): void {
  33. const p = this.stats.params;
  34. this.headTimer = Math.max(0, this.headTimer - dt);
  35. this.swimTime = Math.max(0, this.swimTime - dt);
  36. this.swimming = isDown(ctx.input, Button.Special);
  37. if (!this.swimming) {
  38. if (this.underground) this.emerge(ctx);
  39. this.digTimer = 0;
  40. return;
  41. }
  42. const [dx, dy] = aimDir(ctx);
  43. if (this.swimTime > 0) ctx.setVelocity(dx * p.swimSpeed, dy * p.swimSpeed);
  44. this.digTimer -= dt;
  45. if (this.digTimer > 0) return;
  46. this.digTimer = p.digInterval;
  47. const front = this.size * 0.5;
  48. // Nothing left to eat ahead: either he broke out into the open (burst up), or he is
  49. // blocked by something too hard for him (he just stops).
  50. if (this.underground && this.lastDug < p.swimMinPixels) {
  51. const ahead = this.size + 4;
  52. if (!ctx.isSolid(ctx.x + dx * ahead, ctx.y + dy * ahead)) {
  53. this.emerge(ctx);
  54. return;
  55. }
  56. }
  57. ctx.emitOp(
  58. { 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) },
  59. (n) => {
  60. this.lastDug = n;
  61. if (n >= p.swimMinPixels) {
  62. this.swimTime = p.swimGrace;
  63. this.underground = true;
  64. }
  65. },
  66. );
  67. }
  68. /** Bursts out of the cake: whoever stands above him goes flying. */
  69. private emerge(ctx: CharacterContext): void {
  70. const p = this.stats.params;
  71. this.underground = false;
  72. this.lastDug = 0;
  73. this.swimTime = 0;
  74. ctx.hit(ctx.x, ctx.y - this.size, this.size * p.emergeRadiusFactor, p.emergeKnockback, p.emergeStun);
  75. ctx.setVelocity(ctx.vx * 0.5, -p.emergeHop);
  76. ctx.cue('emerge');
  77. }
  78. override anim(): number {
  79. return (this.headTimer > 0 ? Anim.Attack : 0) | (this.swimming ? Anim.Special : 0) | (this.underground ? Anim.Underground : 0);
  80. }
  81. override knockbackTaken(): number {
  82. return this.underground ? this.stats.params.buriedKnockback : this.stats.params.exposedKnockback;
  83. }
  84. }