Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
fix: make dash always respawn behind (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsgalarraga authored Nov 14, 2023
1 parent 3a0ae7a commit 86417de
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/game/entities/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,19 @@ class Player extends JumperCharacter<DashRunGame> {

void respawn() {
// Get closest value to gridX and gridY in respawnPoints.
final closestRespawn = respawnPoints.reduce((a, b) {
return (a - position).length2 < (b - position).length2 ? a : b;
final respawnPointsBehind = respawnPoints.where((point) {
return point.x < position.x;
});

Vector2 closestRespawn;
if (respawnPointsBehind.isEmpty) {
closestRespawn = spawn;
} else {
closestRespawn = respawnPointsBehind.reduce((a, b) {
return (a - position).length2 < (b - position).length2 ? a : b;
});
}

isPlayerRespawning = true;
isPlayerInvincible = true;
walking = false;
Expand Down

0 comments on commit 86417de

Please sign in to comment.