Skip to content

Commit cc0c11b

Browse files
committed
fix: update refill consumption to use player hurtbox bounds
1 parent 058080c commit cc0c11b

3 files changed

Lines changed: 28 additions & 6 deletions

File tree

src/GameScene.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ export class GameScene extends Phaser.Scene {
13971397
private updateRefills(): number {
13981398
if (this.refills.length === 0) return 0;
13991399

1400-
const player = this.player.getHitboxBounds();
1400+
const player = this.player.getPlayerColliderBounds();
14011401
const consumed = this.world.consumeTouchingRefills(player, (target) => this.player.tryRefill(target));
14021402
for (const refill of consumed) {
14031403
this.refillEmitter.setParticleTint(this.refillColor(refill.type));

src/player/Player.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { DEFAULT_ASSIST_OPTIONS, type AssistOptions } from "../assists";
22
import { COLORS, PLAYER_CONFIG, PLAYER_GEOMETRY, PlayerConfig, WORLD } from "../constants";
33
import { CollisionWorld } from "../entities/CollisionWorld";
44
import { Hitbox } from "../entities/core/Hitbox";
5+
import type { Aabb } from "../entities/types";
56
import {
67
addFloat,
78
approach,
@@ -357,18 +358,23 @@ export class Player extends Actor {
357358
return out;
358359
}
359360

360-
getCollisionBounds(): { x: number; y: number; w: number; h: number } {
361+
getCollisionBounds(): Aabb {
361362
return this.getHitboxBounds();
362363
}
363364

364-
getHitboxBounds(): { x: number; y: number; w: number; h: number } {
365+
getHitboxBounds(): Aabb {
365366
return this.bodyBoundsFor(this.requireBodyHitbox(), this.x, this.y);
366367
}
367368

368-
getHurtboxBounds(): { x: number; y: number; w: number; h: number } {
369+
getHurtboxBounds(): Aabb {
369370
return this.bodyBoundsFor(this.hurtbox, this.x, this.y);
370371
}
371372

373+
// Celeste temporarily swaps Collider to hurtbox for PlayerCollider checks.
374+
getPlayerColliderBounds(): Aabb {
375+
return this.getHurtboxBounds();
376+
}
377+
372378
setAssistOptions(options: AssistOptions): void {
373379
const previousMaxDashes = this.maxAirDashes();
374380
this.assistOptions = { ...options };
@@ -1791,7 +1797,7 @@ export class Player extends Actor {
17911797
return collider;
17921798
}
17931799

1794-
private bodyBoundsFor(hitbox: Hitbox, entityX: number, entityY: number): { x: number; y: number; w: number; h: number } {
1800+
private bodyBoundsFor(hitbox: Hitbox, entityX: number, entityY: number): Aabb {
17951801
return {
17961802
x: entityX + hitbox.left,
17971803
y: entityY + hitbox.top,

tests/entities/refill.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,28 @@ describe("Refill entity", () => {
1313
world.update(DT, 0.5);
1414
player.update(DT, makeInput());
1515
let freeze = player.consumeFreezeRequest();
16-
const consumed = world.consumeTouchingRefills(player.getHitboxBounds(), (target) => player.tryRefill(target));
16+
const consumed = world.consumeTouchingRefills(player.getPlayerColliderBounds(), (target) => player.tryRefill(target));
1717
if (consumed.length > 0) {
1818
freeze = Math.max(freeze, PLAYER_CONFIG.dash.freezeTime);
1919
}
2020

2121
expect(consumed).toHaveLength(1);
2222
expect(freeze).toBe(PLAYER_CONFIG.dash.freezeTime);
2323
});
24+
25+
test("refill pickup uses the player hurtbox instead of the body hitbox", () => {
26+
const hitboxWorld = buildWorld([
27+
{ kind: "refill", x: 96, y: 96, type: "max" },
28+
]);
29+
const hitboxPlayer = createPlayer(hitboxWorld, 96, 95);
30+
31+
expect(hitboxWorld.consumeTouchingRefills(hitboxPlayer.getHitboxBounds(), () => true)).toHaveLength(1);
32+
33+
const hurtboxWorld = buildWorld([
34+
{ kind: "refill", x: 96, y: 96, type: "max" },
35+
]);
36+
const hurtboxPlayer = createPlayer(hurtboxWorld, 96, 95);
37+
38+
expect(hurtboxWorld.consumeTouchingRefills(hurtboxPlayer.getPlayerColliderBounds(), () => true)).toHaveLength(0);
39+
});
2440
});

0 commit comments

Comments
 (0)