Improved weapon switching
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:wolf_dart/features/weapon/weapon.dart';
|
||||
|
||||
class InputManager {
|
||||
Set<LogicalKeyboardKey> _previousKeys = {};
|
||||
@@ -14,7 +15,7 @@ class InputManager {
|
||||
// Continuous
|
||||
bool isFiring = false;
|
||||
|
||||
int? requestedWeaponIndex;
|
||||
WeaponType? requestedWeapon;
|
||||
|
||||
void update() {
|
||||
final pressedKeys = HardwareKeyboard.instance.logicalKeysPressed;
|
||||
@@ -39,17 +40,19 @@ class InputManager {
|
||||
!pressedKeys.contains(LogicalKeyboardKey.space);
|
||||
|
||||
// * Manual Weapon Switching
|
||||
requestedWeaponIndex = null;
|
||||
requestedWeapon = null;
|
||||
|
||||
// Iterate through newly pressed keys and switch on them
|
||||
for (final LogicalKeyboardKey key in newlyPressedKeys) {
|
||||
switch (key) {
|
||||
case LogicalKeyboardKey.digit1:
|
||||
requestedWeaponIndex = 0; // Knife
|
||||
requestedWeapon = WeaponType.knife;
|
||||
case LogicalKeyboardKey.digit2:
|
||||
requestedWeaponIndex = 1; // Pistol
|
||||
requestedWeapon = WeaponType.pistol;
|
||||
case LogicalKeyboardKey.digit3:
|
||||
requestedWeaponIndex = 2; // Machine Gun
|
||||
requestedWeapon = WeaponType.machineGun;
|
||||
case LogicalKeyboardKey.digit4:
|
||||
requestedWeapon = WeaponType.chainGun;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user