Split The code is public; the app answers only to the crew.

Pick the rifle up off the body: a weapon stays in the world when its owner dies #24

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

vesper/cs:vesper/19-pick-the-rifle-up-off-the-body-a-weapon → main 1 commit fork

  • Merged. vesper/19-pick-the-rifle-up-off-the-body-a-weapon was merged into main as 3b044c4.

Review

Sign in to review this change.
11 files changed +393 −70
README.md +10 −2
@@ -40,7 +40,14 @@ The bundle in `static/` is committed, so a fresh clone plays without building;
4040 movement (ground friction, air acceleration, an 18-unit step, strafe jumping),
4141 CS damage with range falloff, armour and hitgroups, deterministic spray patterns,
4242 a 1:55 round with a 40-second bomb, plant and defuse timers, kill rewards and
43 loss bonuses. Hit feedback runs both ways: a hit marker and a beep when you hit
43 loss bonuses. The economy has CS's loop: weapons drop. A player killed leaves
44 the gun they were holding on the floor with whatever was left in the magazine
45 — a knife never drops, and someone killed holding one leaves their primary —
46 and it can be picked up. With no primary you take it by walking over it; with
47 one already, <kbd>E</kbd> swaps, and the gun you were holding lands at your
48 feet. There is no team rule: a CT who finds an AK-47 keeps it. The floor is
49 swept at the start of the next round, and whatever you are carrying then comes
50 back with a full magazine. Hit feedback runs both ways: a hit marker and a beep when you hit
4451 someone, and when you are hit a view punch away from the shot, a wedge around
4552 the crosshair pointing at whoever fired, a vignette that reddens as your health
4653 falls and a pain sound. Every world sound is panned around the listener's
@@ -69,7 +76,8 @@ The bundle in `static/` is committed, so a fresh clone plays without building;
6976
7077 <kbd>WASD</kbd> move, <kbd>Space</kbd> jump, <kbd>Ctrl</kbd> crouch,
7178 <kbd>Shift</kbd> walk, mouse aims and fires, <kbd>R</kbd> reload,
72 <kbd>E</kbd> plants or defuses, <kbd>B</kbd> opens the buy menu in the freeze
79 <kbd>E</kbd> plants, defuses or takes the gun you are standing on (the HUD says
80 which gun when it is one you have to ask for), <kbd>B</kbd> opens the buy menu in the freeze
7381 time, <kbd>1</kbd>/<kbd>2</kbd>/<kbd>3</kbd> switch guns, <kbd>Tab</kbd> shows
7482 the scoreboard, <kbd>Esc</kbd> pauses. On a touch screen the left of the view
7583 is a thumb stick, the right looks around, and the buttons along the bottom do
src/client/hud.test.ts +26
@@ -163,6 +163,32 @@ test("a spectator does not inherit the dead player's hit markers", () => {
163163 expect(own.calls.filter((c) => c.name === "moveTo").length).toBeGreaterThan(4);
164164 });
165165
166 test("a gun under your feet that you would have to ask for says so", () => {
167 const world = createWorld(SHORT, "me", "ct", 5, 89);
168 world.me.primary = "m4a4";
169 world.pickups.push({
170 weapon: "ak47",
171 pos: [world.me.pos[0], world.me.pos[1], world.me.pos[2] + 4],
172 ammo: { mag: 12, reserve: 90 },
173 });
174 const carrying = recorder();
175 draw(carrying, world);
176 expect(carrying.calls.some((c) => c.text === "E — take AK-47")).toBe(true);
177
178 // With no primary it is taken by walking over it, so there is nothing to ask.
179 world.me.primary = null;
180 const empty = recorder();
181 draw(empty, world);
182 expect(empty.calls.some((c) => c.text.includes("take AK-47"))).toBe(false);
183
184 // And a gun across the map is not under anyone's feet.
185 world.me.primary = "m4a4";
186 world.pickups[0].pos = [world.me.pos[0] + 400, world.me.pos[1], world.me.pos[2]];
187 const far = recorder();
188 draw(far, world);
189 expect(far.calls.some((c) => c.text.includes("take AK-47"))).toBe(false);
190 });
191
166192 test("the round result stays up through the end delay and the freeze that follows", () => {
167193 const world = createWorld(SHORT, "me", "ct", 5, 83);
168194 world.match.phase = "over";
src/client/hud.ts +12 −1
@@ -12,7 +12,7 @@ import { angleDelta, clamp } from "./math.ts";
1212 import { MOVE } from "./physics.ts";
1313 import { deathNotice } from "./spectate.ts";
1414 import { inaccuracy, WEAPONS } from "./weapons.ts";
15 import { currentWeapon, eyePos, useProgress, type Player, type World } from "./world.ts";
15 import { currentWeapon, eyePos, offeredPickup, useProgress, type Player, type World } from "./world.ts";
1616
1717 const T_COLOR = "#e2b04a";
1818 const CT_COLOR = "#6fa8e8";
@@ -264,6 +264,17 @@ export function drawHud(
264264 ctx.fillText(message.text, width / 2, height * 0.22);
265265 }
266266
267 // --- a gun under your feet that you would have to ask for. A gun you have
268 // no slot for is taken by walking over it and says nothing, because by the
269 // time it could be read it is already in your hands.
270 const offered = !spectating && view.alive ? offeredPickup(world, view) : null;
271 if (offered !== null) {
272 ctx.textAlign = "center";
273 ctx.font = mid;
274 ctx.fillStyle = "rgba(255,255,255,0.92)";
275 ctx.fillText(`E — take ${WEAPONS[offered.weapon].name}`, width / 2, height * 0.58);
276 }
277
267278 // --- planting or defusing
268279 const progress = useProgress(world, view);
269280 if (progress !== null) {
src/client/models.ts +14
@@ -101,6 +101,20 @@ export function bombMesh(): Mesh {
101101 return finish(b);
102102 }
103103
104 /**
105 * A gun lying on the floor, built around the origin at its own feet: a barrel,
106 * a receiver and a magazine, small enough to read as "something to walk over"
107 * and big enough to see from across a site.
108 */
109 export function pickupMesh(): Mesh {
110 const b = builder();
111 const GUN = 7, GRIP = 6;
112 cube(b, 6, 0, 3, 26, 3, 3, GUN); // barrel and receiver
113 cube(b, -4, 0, 3, 10, 4, 6, GUN); // body
114 cube(b, -2, 0, -1, 5, 3, 6, GRIP); // magazine, hanging under it
115 return finish(b);
116 }
117
104118 /**
105119 * A first-person weapon, in view space: X right, Y up, Z back, so the barrel
106120 * runs down -Z and the model needs no rotation at all.
src/client/renderer.ts +13 −1
@@ -6,7 +6,7 @@
66 */
77
88 import { multiply, perspective, viewMatrix, modelMatrix, type Vec3 } from "./math.ts";
9 import { bombMesh, levelMesh, playerMesh, viewModelMesh, type Mesh } from "./models.ts";
9 import { bombMesh, levelMesh, pickupMesh, playerMesh, viewModelMesh, type Mesh } from "./models.ts";
1010 import { MAX_SCALE, MIN_SCALE } from "./quality.ts";
1111 import { LAYERS, TEX_SIZE, materialTextures } from "./textures.ts";
1212 import type { World } from "./world.ts";
@@ -175,6 +175,7 @@ export function createRenderer(canvas: HTMLCanvasElement): Renderer | null {
175175 let levelBuffers: Buffers | null = null;
176176 const player = upload(gl, playerMesh());
177177 const bomb = upload(gl, bombMesh());
178 const pickup = upload(gl, pickupMesh());
178179 const viewModels = new Map<string, Buffers>();
179180
180181 // One buffer for every line drawn this frame: tracers, sparks, the bomb beam.
@@ -254,6 +255,17 @@ export function createRenderer(canvas: HTMLCanvasElement): Renderer | null {
254255 gl.drawElements(gl.TRIANGLES, player.count, gl.UNSIGNED_INT, 0);
255256 }
256257
258 // Guns their owners are not carrying any more, turning slowly on the spot
259 // so a rifle in a doorway reads as something to take and not as rubble.
260 if (world.pickups.length > 0) {
261 gl.uniform3f(u.tint, 1.1, 1.05, 0.85);
262 gl.bindVertexArray(pickup.vao);
263 for (const item of world.pickups) {
264 gl.uniformMatrix4fv(u.model, false, modelMatrix(item.pos, world.time * 45));
265 gl.drawElements(gl.TRIANGLES, pickup.count, gl.UNSIGNED_INT, 0);
266 }
267 }
268
257269 if (world.bomb.state === "planted" || world.bomb.state === "dropped") {
258270 gl.uniformMatrix4fv(u.model, false, modelMatrix(world.bomb.pos, 0));
259271 gl.uniform3f(u.tint, 1, 1, 1);
src/client/world.test.ts +139 −2
@@ -3,8 +3,8 @@ import { siteAt, sites } from "./map.ts";
33 import { SHORT } from "./match.ts";
44 import { WEAPONS } from "./weapons.ts";
55 import {
6 aimAt, applyInput, bodyCentre, buy, createWorld, currentWeapon, eyePos, flinch, NO_INPUT, shoot,
7 startRound, update, type Input, type Player, type World,
6 aimAt, applyInput, bodyCentre, buy, createWorld, currentWeapon, eyePos, flinch, NO_INPUT,
7 offeredPickup, shoot, startRound, update, type Input, type Player, type World,
88 } from "./world.ts";
99
1010 const TICK = 1 / 64;
@@ -127,6 +127,143 @@ test("a new round puts everyone back with full health and a full magazine", () =
127127 expect(world.players.filter((p) => p.hasBomb).length).toBe(1);
128128 });
129129
130 /**
131 * Guns on the floor. The pickup is made the way the game makes one — a kill —
132 * so the drop and the take are tested together and not against a fixture.
133 */
134
135 /** Kill the person, holding an M4 with seven left in it, and leave it there. */
136 function dropRifle(world: World): Player {
137 const shooter = world.players.find((p) => p.team === "t") as Player;
138 faceOff(world, shooter);
139 world.me.primary = "m4a4";
140 world.me.weapon = "m4a4";
141 world.me.ammo.m4a4 = { mag: 7, reserve: 30 };
142 world.me.health = 1;
143 world.me.armor = 0;
144 expect(shoot(world, shooter)).toBe(true);
145 expect(world.me.alive).toBe(false);
146 return shooter;
147 }
148
149 /** A live player standing where the person fell, with whatever they carry. */
150 function standOnIt(world: World, primary: "ak47" | null): Player {
151 // One of the bots faceOff stood down, put back on its feet on top of the gun.
152 const taker = world.players.find((p) => p.team === "t" && !p.alive) as Player;
153 taker.alive = true;
154 taker.health = 100;
155 taker.pos = [world.me.pos[0], world.me.pos[1], world.me.pos[2]];
156 taker.primary = primary;
157 taker.weapon = primary ?? taker.secondary;
158 if (primary !== null) taker.ammo[primary] = { mag: 30, reserve: 90 };
159 world.time += 1; // past the swap cooldown, which starts at zero anyway
160 return taker;
161 }
162
163 test("a kill leaves exactly one gun where its owner fell, with the ammo it had", () => {
164 const world = createWorld(SHORT, "me", "ct", 5, 101);
165 dropRifle(world);
166 expect(world.pickups.length).toBe(1);
167 const gun = world.pickups[0];
168 expect(gun.weapon).toBe("m4a4");
169 expect(gun.ammo).toEqual({ mag: 7, reserve: 30 });
170 expect(Math.hypot(gun.pos[0] - world.me.pos[0], gun.pos[1] - world.me.pos[1])).toBeLessThan(1);
171 });
172
173 test("a knife kill leaves nothing: a knife is never a pickup", () => {
174 const world = createWorld(SHORT, "me", "ct", 5, 103);
175 const shooter = world.players.find((p) => p.team === "t") as Player;
176 faceOff(world, shooter);
177 world.me.primary = null;
178 world.me.weapon = "knife";
179 world.me.health = 1;
180 world.me.armor = 0;
181 expect(shoot(world, shooter)).toBe(true);
182 expect(world.me.alive).toBe(false);
183 expect(world.pickups.length).toBe(0);
184 });
185
186 test("a pistol-only player walks over the gun and comes away holding it", () => {
187 const world = createWorld(SHORT, "me", "ct", 5, 107);
188 dropRifle(world);
189 const taker = standOnIt(world, null);
190 applyInput(world, taker, NO_INPUT, TICK);
191 expect(taker.primary).toBe("m4a4");
192 expect(taker.weapon).toBe("m4a4");
193 expect(taker.ammo.m4a4).toEqual({ mag: 7, reserve: 30 });
194 expect(world.pickups.length).toBe(0);
195 });
196
197 test("a pistol is never swept up — the pistol slot is never free — but a rifle is", () => {
198 const world = createWorld(SHORT, "me", "ct", 5, 131);
199 dropRifle(world);
200 const taker = standOnIt(world, null);
201 world.pickups[0].pos = [taker.pos[0] + 30, taker.pos[1], taker.pos[2] + 4];
202 world.pickups.push({
203 weapon: "deagle",
204 pos: [taker.pos[0], taker.pos[1], taker.pos[2] + 4],
205 ammo: { mag: 7, reserve: 35 },
206 });
207 applyInput(world, taker, NO_INPUT, TICK);
208 expect(taker.primary).toBe("m4a4"); // the rifle a step away, not the one underfoot
209 expect(taker.secondary).toBe("glock");
210 expect(world.pickups.map((g) => g.weapon)).toEqual(["deagle"]);
211 });
212
213 test("a player who already has a primary does not sweep one up, and E swaps", () => {
214 const world = createWorld(SHORT, "me", "ct", 5, 109);
215 dropRifle(world);
216 const taker = standOnIt(world, "ak47");
217 applyInput(world, taker, NO_INPUT, TICK);
218 expect(taker.primary).toBe("ak47");
219 expect(world.pickups.length).toBe(1);
220 expect(offeredPickup(world, taker)?.weapon).toBe("m4a4");
221
222 applyInput(world, taker, { ...NO_INPUT, use: true }, TICK);
223 expect(taker.primary).toBe("m4a4");
224 expect(taker.ammo.m4a4).toEqual({ mag: 7, reserve: 30 });
225 expect(taker.ammo.ak47).toBeUndefined(); // it is on the floor, not in the bag
226 expect(world.pickups.map((g) => g.weapon)).toEqual(["ak47"]);
227 expect(world.pickups[0].ammo).toEqual({ mag: 30, reserve: 90 });
228 // Holding E does not flip the two guns back and forth at 64 Hz.
229 for (let i = 0; i < 8; i++) applyInput(world, taker, { ...NO_INPUT, use: true }, TICK);
230 expect(taker.primary).toBe("m4a4");
231 });
232
233 test("the next round clears the floor and hands the picked-up gun back loaded", () => {
234 const world = createWorld(SHORT, "me", "ct", 5, 113);
235 dropRifle(world);
236 const taker = standOnIt(world, "ak47");
237 applyInput(world, taker, { ...NO_INPUT, use: true }, TICK);
238 expect(taker.primary).toBe("m4a4");
239
240 startRound(world);
241 expect(world.pickups.length).toBe(0);
242 expect(taker.primary).toBe("m4a4");
243 expect(taker.weapon).toBe("m4a4");
244 expect(taker.ammo.m4a4).toEqual({ mag: WEAPONS.m4a4.magazine, reserve: WEAPONS.m4a4.reserve });
245 expect(taker.ammo.ak47).toBeUndefined();
246 expect(taker.ammo[taker.secondary].mag).toBe(WEAPONS[taker.secondary].magazine);
247 });
248
249 test("a long round cannot grow the floor without bound", () => {
250 const world = createWorld(SHORT, "me", "ct", 5, 127);
251 const shooter = world.players.find((p) => p.team === "t") as Player;
252 faceOff(world, shooter);
253 for (let i = 0; i < 60; i++) {
254 world.me.alive = true;
255 world.me.health = 1;
256 world.me.armor = 0;
257 world.me.primary = "m4a4";
258 world.me.weapon = "m4a4";
259 world.me.ammo.m4a4 = { mag: 7, reserve: 30 };
260 shooter.nextShotAt = 0;
261 world.time += 1;
262 shoot(world, shooter);
263 }
264 expect(world.pickups.length).toBeLessThanOrEqual(24);
265 });
266
130267 /** The damage the person took, narrowed out of the effects list. */
131268 const hurtsIn = (world: World): { at: number; victim: number; from: number[]; amount: number }[] =>
132269 world.effects.flatMap((e) => (e.kind === "hurt" ? [e] : []));
src/client/world.ts +117 −5
@@ -42,6 +42,7 @@ export type Player = Actor & Body & {
4242 scoped: boolean;
4343 firedThisPress: boolean;
4444 punch: [number, number]; // view kick, decaying
45 nextPickupAt: number; // no swapping guns again until this, so E cannot flip-flop
4546 kills: number;
4647 deaths: number;
4748 headshots: number;
@@ -59,6 +60,13 @@ export type Bomb = {
5960 defuser: Player | null;
6061 };
6162
63 /** A gun lying on the floor: what it is, where it fell, and what was left in it. */
64 export type Pickup = {
65 weapon: WeaponId;
66 pos: Vec3;
67 ammo: Ammo;
68 };
69
6270 export type Effect =
6371 | { kind: "tracer"; from: Vec3; to: Vec3; at: number }
6472 | { kind: "impact"; at: number; pos: Vec3; normal: Vec3 }
@@ -107,6 +115,7 @@ export type World = {
107115 me: Player;
108116 time: number;
109117 bomb: Bomb;
118 pickups: Pickup[];
110119 effects: Effect[];
111120 feed: FeedEntry[];
112121 messages: { at: number; text: string }[];
@@ -135,7 +144,7 @@ function makePlayer(id: number, team: Team, name: string, bot: boolean): Player
135144 ammo: { knife: { mag: 0, reserve: 0 }, [secondary]: emptyAmmo(secondary) },
136145 defuseKit: false, hasBomb: false,
137146 nextShotAt: 0, reloadUntil: 0, shotIndex: 0, lastShotAt: -99, scoped: false, firedThisPress: false,
138 punch: [0, 0],
147 punch: [0, 0], nextPickupAt: 0,
139148 kills: 0, deaths: 0, headshots: 0, damage: 0, spawnAt: 0, stepDistance: 0,
140149 };
141150 }
@@ -165,6 +174,7 @@ export function createWorld(
165174 const world: World = {
166175 match, players, me, time: 0,
167176 bomb: { state: "carried", pos: [0, 0, 0], site: null, plantProgress: 0, defuseProgress: 0, defuser: null },
177 pickups: [],
168178 effects: [], feed: [], messages: [],
169179 random, boxes: map.boxes, bombPlanted: false, pendingBuy: false,
170180 };
@@ -201,12 +211,14 @@ export function startRound(world: World): void {
201211 p.scoped = false;
202212 p.stepDistance = 0;
203213 p.spawnAt = world.time;
214 p.nextPickupAt = 0;
204215 p.yaw = p.team === "t" ? 90 : -90;
205216 p.pitch = 0;
206 for (const id of Object.keys(p.ammo)) {
207 const w = WEAPONS[id as WeaponId];
208 if (w !== undefined) p.ammo[id] = emptyAmmo(w.id);
209 }
217 // The magazines are rebuilt from the two slots rather than topped up in
218 // place: a gun taken off a body is in `p.primary`/`p.secondary` and nowhere
219 // else, and a gun swapped away is gone from the list the same way.
220 p.ammo = { knife: { mag: 0, reserve: 0 }, [p.secondary]: emptyAmmo(p.secondary) };
221 if (p.primary !== null) p.ammo[p.primary] = emptyAmmo(p.primary);
210222 p.weapon = p.primary ?? p.secondary;
211223 if (p.brain !== undefined) p.brain.reset = true;
212224 }
@@ -217,6 +229,7 @@ export function startRound(world: World): void {
217229 world.bomb = { state: "carried", pos: [...carrier.pos] as Vec3, site: null, plantProgress: 0, defuseProgress: 0, defuser: null };
218230 }
219231 world.bombPlanted = false;
232 world.pickups.length = 0;
220233 world.feed = [];
221234 for (const p of world.players) if (p.bot) botBuy(world, p);
222235 }
@@ -426,9 +439,107 @@ function onKill(world: World, killer: Player, victim: Player, weapon: WeaponId,
426439 world.bomb.state = "dropped";
427440 world.bomb.pos = [victim.pos[0], victim.pos[1], victim.pos[2] + 4];
428441 }
442 // The gun they were holding stays where they fell. A knife is never a pickup,
443 // so someone killed holding one leaves their primary instead — or nothing.
444 dropWeapon(world, victim, victim.weapon === "knife" ? victim.primary : victim.weapon);
429445 checkRoundEnd(world);
430446 }
431447
448 // --- guns on the floor ----------------------------------------------------
449
450 /**
451 * The rule, once: a gun you have no slot for is taken by walking over it, and a
452 * gun that would replace one you are carrying takes an explicit `use`, which
453 * leaves the one you were holding where you stand. Bots get no new code — the
454 * automatic half is enough, and their paths already take them past bodies.
455 *
456 * There is no team rule. This match has no friendly fire and a CT who picks up
457 * an AK-47 keeps it; inventing a restriction CS does not have would only make
458 * the floor confusing.
459 */
460 const PICKUP_RANGE = 48;
461 /** A long round cannot grow the floor without bound; the oldest gun goes. */
462 const MAX_PICKUPS = 24;
463 /** How long after a swap before another one: without it, holding E flip-flops. */
464 const PICKUP_COOLDOWN = 0.75;
465
466 /** Which slot a gun lives in. A pistol is a secondary; everything else primary. */
467 export const pickupSlot = (id: WeaponId): "primary" | "secondary" =>
468 WEAPONS[id]?.kind === "pistol" ? "secondary" : "primary";
469
470 /** Leave `id` on the floor under `p`, with the ammunition `p` had left in it. */
471 function dropWeapon(world: World, p: Player, id: WeaponId | null): void {
472 if (id === null || WEAPONS[id] === undefined || WEAPONS[id].kind === "knife") return;
473 const ammo = p.ammo[id] ?? emptyAmmo(id);
474 world.pickups.push({
475 weapon: id,
476 pos: [p.pos[0], p.pos[1], p.pos[2] + 4],
477 ammo: { mag: ammo.mag, reserve: ammo.reserve },
478 });
479 if (world.pickups.length > MAX_PICKUPS) world.pickups.shift();
480 }
481
482 /**
483 * The closest gun within arm's reach of `p`, if there is one. `freeSlotOnly`
484 * asks for the closest one they have a hand free for — a rifle two steps away
485 * beats the pistol they are standing on, which they could not take anyway.
486 */
487 function nearestPickup(world: World, p: Player, freeSlotOnly = false): Pickup | null {
488 let best: Pickup | null = null;
489 let bestDistance = PICKUP_RANGE;
490 for (const pickup of world.pickups) {
491 if (freeSlotOnly && p[pickupSlot(pickup.weapon)] !== null) continue;
492 const d = dist(p.pos, pickup.pos);
493 if (d < bestDistance) {
494 bestDistance = d;
495 best = pickup;
496 }
497 }
498 return best;
499 }
500
501 /**
502 * The gun under your feet that you would have to ask for, if any: the HUD's
503 * `E — take AK-47` prompt, and nothing else reads it.
504 */
505 export function offeredPickup(world: World, p: Player): Pickup | null {
506 if (world.pickups.length === 0 || !p.alive) return null;
507 const pickup = nearestPickup(world, p);
508 if (pickup === null) return null;
509 return p[pickupSlot(pickup.weapon)] === null ? null : pickup;
510 }
511
512 function takePickup(world: World, p: Player, pickup: Pickup): void {
513 const slot = pickupSlot(pickup.weapon);
514 const held = p[slot];
515 const index = world.pickups.indexOf(pickup);
516 if (index >= 0) world.pickups.splice(index, 1);
517 if (held !== null && held !== pickup.weapon) dropWeapon(world, p, held);
518 if (held !== null) delete p.ammo[held];
519 p[slot] = pickup.weapon;
520 p.ammo[pickup.weapon] = { mag: pickup.ammo.mag, reserve: pickup.ammo.reserve };
521 p.weapon = pickup.weapon;
522 p.shotIndex = 0;
523 p.reloadUntil = 0;
524 p.scoped = false;
525 p.nextPickupAt = world.time + PICKUP_COOLDOWN;
526 }
527
528 /**
529 * Walk over a gun, or ask for one. The empty list is the first thing tested:
530 * the training arena steps this millions of times a second and never puts a
531 * gun on its floor, so this costs one comparison there.
532 */
533 function updatePickups(world: World, p: Player, input: Input): void {
534 if (world.pickups.length === 0 || world.time < p.nextPickupAt) return;
535 const free = nearestPickup(world, p, true);
536 if (free !== null) return takePickup(world, p, free);
537 // `use` is one button: while it is planting or defusing it is not swapping guns.
538 if (!input.use || useProgress(world, p) !== null) return;
539 const asked = nearestPickup(world, p);
540 if (asked !== null) takePickup(world, p, asked);
541 }
542
432543 // --- the bomb -------------------------------------------------------------
433544
434545 const PLANT_RANGE = 64;
@@ -552,6 +663,7 @@ export function applyInput(world: World, p: Player, input: Input, dt: number): v
552663 if (world.time - p.lastShotAt > 0.35) p.shotIndex = 0;
553664 p.punch = [p.punch[0] * Math.pow(0.02, dt), p.punch[1] * Math.pow(0.02, dt)];
554665 updateBomb(world, p, input, dt);
666 updatePickups(world, p, input);
555667 }
556668
557669 /** One fixed simulation tick. `input` is the person's; bots think for themselves. */
src/pages/game.ts +1 −1
@@ -137,7 +137,7 @@ export function gamePage(db: Database, options: PageOptions): string {
137137 </div>
138138 <div class="row"><button type="button" class="primary" id="play">Play</button></div>
139139 <p class="hint"><kbd>WASD</kbd> move · <kbd>Space</kbd> jump · <kbd>Ctrl</kbd> crouch · <kbd>Shift</kbd> walk ·
140 mouse to aim and fire · <kbd>R</kbd> reload · <kbd>E</kbd> plant or defuse · <kbd>B</kbd> buy ·
140 mouse to aim and fire · <kbd>R</kbd> reload · <kbd>E</kbd> plant, defuse or take a gun · <kbd>B</kbd> buy ·
141141 <kbd>1</kbd><kbd>2</kbd><kbd>3</kbd> guns · <kbd>Tab</kbd> scores · <kbd>Esc</kbd> pause</p>
142142 </div>
143143 <div class="overlay" id="pause" hidden>
src/rl/arena.ts +3
@@ -167,6 +167,9 @@ export function reset(arena: Arena): void {
167167 world.effects.length = 0;
168168 world.feed.length = 0;
169169 world.messages.length = 0;
170 // A duel that ended in a kill left a rifle on the floor. Nothing here wants
171 // it, and an empty list is what keeps the pickup test in applyInput free.
172 world.pickups.length = 0;
170173 arena.ticks = 0;
171174
172175 equip(learner, "m4a4");
static/app.d616a602f9.js added +58

Diff not shown — a line 62,054 characters wide (limit 2,000). +58

View file
static/app.f7b32033ed.js deleted −58

Diff not shown — a line 60,526 characters wide (limit 2,000). −58

View file

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs