Skip to content

Commit

Permalink
fix: pure grid movement
Browse files Browse the repository at this point in the history
player moves only on the grid, and the grid updates its position! Ingenious!
  • Loading branch information
mdwmage committed May 24, 2024
1 parent 426c717 commit 478f448
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/entities/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,27 @@ impl Player {
if is_key_down(KeyCode::Space) {
// Special Movement
if is_key_pressed(KeyCode::W) || is_key_pressed(KeyCode::Up) {
self.y -= 200.0;
self.position.1 -= 2;
} else if is_key_pressed(KeyCode::S) || is_key_pressed(KeyCode::Down) {
self.y += 200.0;
self.position.1 += 2;
} else if is_key_pressed(KeyCode::A) || is_key_pressed(KeyCode::Left) {
self.x -= 200.0;
self.position.0 -= 2;
} else if is_key_pressed(KeyCode::D) || is_key_pressed(KeyCode::Right) {
self.x += 200.0;
self.position.0 += 2;
}
}
// Movement
else if is_key_pressed(KeyCode::W) || is_key_pressed(KeyCode::Up) {
self.y -= 100.0;
self.position.1 -= 1;
} else if is_key_pressed(KeyCode::S) || is_key_pressed(KeyCode::Down) {
self.y += 100.0;
self.position.1 += 1;
} else if is_key_pressed(KeyCode::A) || is_key_pressed(KeyCode::Left) {
self.x -= 100.0;
self.position.0 -= 1;
} else if is_key_pressed(KeyCode::D) || is_key_pressed(KeyCode::Right) {
self.x += 100.0;
self.position.0 += 1;
}
self.x = self.position.0 as f32 * 100.0 + 50.0;
self.y = self.position.1 as f32 * 100.0 + 50.0;
}
}

Expand Down

0 comments on commit 478f448

Please sign in to comment.