Skip to content

Commit

Permalink
refactor: 💡 keybord event & private methods
Browse files Browse the repository at this point in the history
  • Loading branch information
panicdragon committed Apr 16, 2023
1 parent 1dbb372 commit 2b9e6d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class MainGame extends FlameGame with KeyboardEvents, HasGameRef {

if (!isKeyDown) return super.onKeyEvent(event, keysPressed);

if (event.logicalKey == LogicalKeyboardKey.keyA) {
if (event.logicalKey == LogicalKeyboardKey.keyA || event.logicalKey == LogicalKeyboardKey.arrowLeft) {
keyDirection = Direction.left;
} else if (event.logicalKey == LogicalKeyboardKey.keyD) {
} else if (event.logicalKey == LogicalKeyboardKey.keyD || event.logicalKey == LogicalKeyboardKey.arrowRight) {
keyDirection = Direction.right;
} else if (event.logicalKey == LogicalKeyboardKey.keyW) {
} else if (event.logicalKey == LogicalKeyboardKey.keyW || event.logicalKey == LogicalKeyboardKey.arrowUp) {
keyDirection = Direction.up;
} else if (event.logicalKey == LogicalKeyboardKey.keyS) {
} else if (event.logicalKey == LogicalKeyboardKey.keyS || event.logicalKey == LogicalKeyboardKey.arrowDown) {
keyDirection = Direction.down;
}

Expand Down
5 changes: 2 additions & 3 deletions lib/src/push_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ class PushGame {
late int stageWidth;
late int stageHeight;
List<String> stageDataList = LineSplitter.split(stageData).toList();
late List<Object> stageState;
late List<Object> stageState = _stageState;

PushGame() {
stageWidth = stageDataList.first.length;
stageHeight = stageDataList.length;
stageState = getStageState();
}

List<Object> getStageState() {
List<Object> get _stageState {
final List<Object>stageStateList = List<Object>.filled(stageWidth * stageHeight, Object.unknown);
int x, y;
x = y = 0;
Expand Down

0 comments on commit 2b9e6d8

Please sign in to comment.