Play (wrong) door sound effect when the door opens or closes

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-15 21:13:41 +01:00
parent b3b909a9b6
commit b0852543b0
18 changed files with 268 additions and 485 deletions

View File

@@ -1,48 +1,34 @@
import 'package:flutter/services.dart';
import 'package:wolf_3d_engine/wolf_3d_engine.dart';
import 'package:wolf_3d_entities/wolf_3d_entities.dart';
class InputManager {
class WolfInput {
Set<LogicalKeyboardKey> _previousKeys = {};
bool isMovingForward = false;
bool isMovingBackward = false;
bool isTurningLeft = false;
bool isTurningRight = false;
// Discrete (triggers once per press)
bool isInteracting = false;
// Continuous
bool isFiring = false;
WeaponType? requestedWeapon;
void update() {
final pressedKeys = HardwareKeyboard.instance.logicalKeysPressed;
// Calculate all keys that were pressed exactly on this frame
final newlyPressedKeys = pressedKeys.difference(_previousKeys);
// * Movement
isMovingForward = pressedKeys.contains(LogicalKeyboardKey.keyW);
isMovingBackward = pressedKeys.contains(LogicalKeyboardKey.keyS);
isTurningLeft = pressedKeys.contains(LogicalKeyboardKey.keyA);
isTurningRight = pressedKeys.contains(LogicalKeyboardKey.keyD);
// * Interaction (Space)
// Much simpler now using the newlyPressedKeys set
isInteracting = newlyPressedKeys.contains(LogicalKeyboardKey.space);
// * Firing (Left Control)
// - Keeping this continuous for machine guns
isFiring =
pressedKeys.contains(LogicalKeyboardKey.controlLeft) &&
!pressedKeys.contains(LogicalKeyboardKey.space);
// * Manual Weapon Switching
requestedWeapon = null;
// Iterate through newly pressed keys and switch on them
for (final LogicalKeyboardKey key in newlyPressedKeys) {
switch (key) {
case LogicalKeyboardKey.digit1:
@@ -56,7 +42,17 @@ class InputManager {
}
}
// * Save state for next tick
_previousKeys = Set.from(pressedKeys);
}
/// Exports the current state as a clean DTO for the engine
EngineInput get currentInput => EngineInput(
isMovingForward: isMovingForward,
isMovingBackward: isMovingBackward,
isTurningLeft: isTurningLeft,
isTurningRight: isTurningRight,
isFiring: isFiring,
isInteracting: isInteracting,
requestedWeapon: requestedWeapon,
);
}