Skip to content

Commit

Permalink
Fix the auto jump loop issue
Browse files Browse the repository at this point in the history
  • Loading branch information
imaNNeo committed Nov 19, 2024
1 parent 2b5adc5 commit 0080f9c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
14 changes: 13 additions & 1 deletion lib/presentation/bloc/multiplayer/multiplayer_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,9 @@ class MultiplayerCubit extends Cubit<MultiplayerState> {
));
if (state.isCurrentPlayerAutoJump) {
const Duration(milliseconds: 300);
startPlaying();
if (!isClosed) {
startPlaying();
}
}
}
}
Expand Down Expand Up @@ -460,4 +462,14 @@ class MultiplayerCubit extends Cubit<MultiplayerState> {

return super.close();
}

void onGamePageOpened(String matchId) async {
assert(matchId == state.matchId);
if (state.isCurrentPlayerAutoJump) {
await Future.delayed(const Duration(milliseconds: 300));
if (!isClosed) {
startPlaying();
}
}
}
}
6 changes: 5 additions & 1 deletion lib/presentation/component/dash/auto_jump_dash.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,18 @@ class AutoJumpDash extends Component with ParentIsA<Dash> {
} else {
return;
}
randomFail = false;
}

if (position.y > getBottomLineEdge(nextPipe) && velocityY > 10) {
parent.jump();
}
}

void onDashDied() {
randomFail = false;
_nextPipe = null;
}

@override
void render(Canvas canvas) {
super.render(canvas);
Expand Down
5 changes: 4 additions & 1 deletion lib/presentation/component/dash/dash.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class Dash extends PositionComponent

final bool autoJump;

AutoJumpDash? _autoJumpDash;

set isNameVisible(bool value) {
_isNameVisible = value;
if (value) {
Expand Down Expand Up @@ -101,7 +103,7 @@ class Dash extends PositionComponent
_resetCorrectPositionAfter();

if (autoJump) {
add(AutoJumpDash());
add(_autoJumpDash = AutoJumpDash());
}
}

Expand Down Expand Up @@ -260,6 +262,7 @@ class Dash extends PositionComponent
other.removeFromParent();
} else if (other is Pipe) {
game.gameOver(x, y, _velocityY);
_autoJumpDash?.onDashDied();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class _MultiPlayerGamePageState extends State<MultiPlayerGamePage> {
multiplayerCubit,
leaderboardCubit,
);
multiplayerCubit.onGamePageOpened(widget.matchId);
super.initState();
}

Expand Down

0 comments on commit 0080f9c

Please sign in to comment.