Skip to content

Instantly share code, notes, and snippets.

@vbalagovic
Created March 3, 2023 14:33
Show Gist options
  • Save vbalagovic/7667c769d21eb29a84595ad1a3c11e1a to your computer and use it in GitHub Desktop.
Save vbalagovic/7667c769d21eb29a84595ad1a3c11e1a to your computer and use it in GitHub Desktop.
@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