feat: Add bonus flash effect for player pickups and update rendering logic

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-23 12:11:19 +01:00
parent 604923618a
commit 8ed460b03e
7 changed files with 165 additions and 37 deletions
@@ -102,5 +102,18 @@ void main() {
}
expect(player.lives, 9);
});
test('successful pickups trigger bonus flash and it fades over time', () {
final player = Player(x: 1.5, y: 1.5, angle: 0)..health = 50;
final food = HealthCollectible(x: 1, y: 1, mapId: MapObject.food);
expect(player.bonusFlash, 0.0);
player.tryPickup(food);
expect(player.bonusFlash, 1.0);
player.tick(const Duration(milliseconds: 16));
expect(player.bonusFlash, lessThan(1.0));
expect(player.bonusFlash, greaterThan(0.0));
});
});
}
@@ -46,17 +46,38 @@ void main() {
expect(expectedNoKeyIndex, isNotNull);
final goldKeyCall = renderer.drawCalls.firstWhere(
(call) => call.startY == 164 && call.startX == 30,
(call) => call.startY == 164 && call.startX == 240,
orElse: () => throw StateError('Gold key slot was not rendered.'),
);
final silverKeyCall = renderer.drawCalls.firstWhere(
(call) => call.startY == 180 && call.startX == 30,
(call) => call.startY == 180 && call.startX == 240,
orElse: () => throw StateError('Silver key slot was not rendered.'),
);
expect(goldKeyCall.imageIndex, expectedGoldKeyIndex);
expect(silverKeyCall.imageIndex, expectedNoKeyIndex);
});
test('standard VGA HUD face follows current health band', () {
final engine = _buildEngine();
engine.init();
engine.player.health = 20;
final renderer = _HudProbeRenderer(vgaImages: engine.data.vgaImages);
renderer.drawHudForTest(engine);
final expectedFaceIndex = engine.data.registry.hud
.faceForHealth(engine.player.health)
?.vgaIndex;
expect(expectedFaceIndex, isNotNull);
final faceCall = renderer.drawCalls.firstWhere(
(call) => call.startY == 164 && call.startX == 136,
orElse: () => throw StateError('Face slot was not rendered.'),
);
expect(faceCall.imageIndex, expectedFaceIndex);
});
}
class _HudProbeRenderer extends RendererBackend<int> {