feat: Enhance weapon switching logic and add tests for animation pacing and menu behavior
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -115,5 +115,22 @@ void main() {
|
||||
expect(player.bonusFlash, lessThan(1.0));
|
||||
expect(player.bonusFlash, greaterThan(0.0));
|
||||
});
|
||||
|
||||
test('weapon switch animates at canonical tic pacing', () {
|
||||
final player = Player(x: 1.5, y: 1.5, angle: 0);
|
||||
player.weapons[WeaponType.machineGun] = MachineGun();
|
||||
|
||||
player.requestWeaponSwitch(WeaponType.machineGun);
|
||||
expect(player.switchState, WeaponSwitchState.lowering);
|
||||
|
||||
player.tick(const Duration(milliseconds: 86));
|
||||
expect(player.switchState, WeaponSwitchState.raising);
|
||||
expect(player.weaponAnimOffset, closeTo(500.0, 0.001));
|
||||
expect(player.currentWeapon.type, WeaponType.machineGun);
|
||||
|
||||
player.tick(const Duration(milliseconds: 86));
|
||||
expect(player.switchState, WeaponSwitchState.idle);
|
||||
expect(player.weaponAnimOffset, closeTo(0.0, 0.001));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -49,6 +49,27 @@ void main() {
|
||||
expect(mapPixels.contains(ColorPalette.vga32Bit[2]), isTrue);
|
||||
expect(mapPixels[hudProbeIndex], equals(normalPixels[hudProbeIndex]));
|
||||
});
|
||||
|
||||
test('software renderer does not apply bonus flash while menu is open', () {
|
||||
final input = _MutableInput();
|
||||
final engine = _buildEngine(input: input);
|
||||
engine.init();
|
||||
input.isBack = true;
|
||||
engine.tick(const Duration(milliseconds: 16));
|
||||
input.isBack = false;
|
||||
|
||||
expect(engine.isMenuOpen, isTrue);
|
||||
|
||||
final renderer = SoftwareRenderer();
|
||||
|
||||
engine.player.bonusFlash = 0.0;
|
||||
final List<int> menuBaseline = List<int>.from(renderer.render(engine).pixels);
|
||||
|
||||
engine.player.bonusFlash = 1.0;
|
||||
final List<int> menuWithFlash = List<int>.from(renderer.render(engine).pixels);
|
||||
|
||||
expect(menuWithFlash, equals(menuBaseline));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -69,7 +90,12 @@ class _StaticInput extends Wolf3dInput {
|
||||
}
|
||||
}
|
||||
|
||||
WolfEngine _buildEngine() {
|
||||
class _MutableInput extends Wolf3dInput {
|
||||
@override
|
||||
void update() {}
|
||||
}
|
||||
|
||||
WolfEngine _buildEngine({Wolf3dInput? input}) {
|
||||
final wallGrid = _buildGrid();
|
||||
final objectGrid = _buildGrid();
|
||||
|
||||
@@ -115,7 +141,7 @@ WolfEngine _buildEngine() {
|
||||
difficulty: Difficulty.medium,
|
||||
startingEpisode: 0,
|
||||
frameBuffer: FrameBuffer(96, 96),
|
||||
input: _StaticInput(),
|
||||
input: input ?? _StaticInput(),
|
||||
onGameWon: () {},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user