Add a kick
Goal
The brawl kit's fighters get a fourth move: I kicks. A kick reaches farther than a punch and knocks harder, but has a longer cooldown. Like every ability, the page only asks; the authority checks the cooldown, the reach and the facing, and confirms a hit to the attacker and the victim.
Files you will edit
src/systems/abilities.tssrc/systems/controls.ts
Steps
Declare the message and its cooldown in
src/systems/abilities.ts, below the imports. AdddefineMessageto the file'sgameableimport. The cooldown is one lane per seat, made once.ts/** I: kick whoever is in front of me. */ export const Kick = defineMessage('kick', (p): p is null => p === null, { maxBytes: 8 }); /** The kick's number in `hit` and `refused`: after punch 0, dash 1, slam 2. */ const KICK = 3; /** Seconds until each seat may kick again. */ const kickReady = new Float32Array(MAX_PLAYERS);Check it and land it at the end of
abilities(ctx), after the slams.allowedrefuses a kick inside its cooldown, from a knocked-out fighter or between rounds, and starts the cooldown otherwise;strikefinds the nearest fighter in reach and in front, and lands the hit or refuses withrangeorfacing.tsfor (let seat = 0; seat < MAX_PLAYERS; seat += 1) { kickReady[seat] = Math.max(0, kickReady[seat] - ctx.dt); } const kicks = ctx.net.messages(Kick); for (let i = 0; i < kicks.length; i += 1) { const player = ctx.players.get(kicks[i].player); if (allowed(ctx, player, KICK, kickReady, 1.2)) { strike(ctx, player, KICK, 2.2, 90, 16, 11); } }The numbers are the cooldown (1.2 s), then the reach (2.2 m), the arc in front (90 degrees), the damage and the knockback (m/s). Move them into
rulesinsrc/game.tswhen you want them beside the others.Send it from the page in
src/systems/controls.ts: importKickfrom./abilities, and add one line beside the other keys incontrols(ctx).tsif (ctx.input.pressed('I')) ctx.net.send(Kick, null);Rebuild the guest, because Play Solo's authority runs it:
shnpm run build:guest
Verify
sh
npm testpasses as before. Then npm run dev, open http://localhost:5199, open Play with friends in a second tab, and walk the two fighters to two metres apart, facing each other. I lands (the other fighter flashes red and slides back); J from the same spot is refused, out of the punch's reach.
See also
- Send a message: the round trip every ability uses.
- Play with friends: two tabs in one room.
- Multiplayer: prediction, and why a knockback reaches your own page as a correction.