Created
March 3, 2023 14:33
-
-
Save vbalagovic/7667c769d21eb29a84595ad1a3c11e1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@override | |
bool onKeyEvent(RawKeyEvent event, Set<LogicalKeyboardKey> keysPressed) { | |
final isKeyUp = event is RawKeyUpEvent; | |
// | |
if (isKeyUp) { | |
if (current == PlayerState.right || current == PlayerState.left || current == PlayerState.jump) { | |
stop(); | |
current = PlayerState.regular; | |
} | |
} | |
if (keysPressed.contains(LogicalKeyboardKey.arrowLeft)) { | |
current = PlayerState.left; | |
moveLeft(); | |
} | |
if (keysPressed.contains(LogicalKeyboardKey.arrowRight)) { | |
current = PlayerState.right; | |
moveRight(); | |
} | |
// During development, its useful to "cheat" | |
if (keysPressed.contains(LogicalKeyboardKey.arrowUp)) { | |
current = PlayerState.jump; | |
moveUp(); | |
} | |
if (keysPressed.contains(LogicalKeyboardKey.arrowDown)) { | |
moveDown(); | |
} | |
if (keysPressed.contains(LogicalKeyboardKey.space)) { | |
current = PlayerState.hit; | |
Future.delayed(const Duration(milliseconds: 99), () { | |
if (current == PlayerState.hit) { | |
current = PlayerState.regular; | |
} | |
}); | |
} | |
if (keysPressed.contains(LogicalKeyboardKey.shiftLeft)) { | |
current = PlayerState.shoot; | |
final ice = Ice(); | |
(gameRef as MortalKombat).add(ice); | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment