Skip to content
This repository was archived by the owner on Apr 14, 2026. It is now read-only.

Commit b86ec43

Browse files
authored
Reset velocity on borders (#8)
* Refactor game structure: move paddle logic to game module and update viewport constants for default values * Add ball module and implement ball movement system; refactor paddle creation * Make BALL_RADIUS and PADDLE_SIZE public; adjust paddle size calculation * Refactor ball radius calculation to use PADDLE_SIZE; update wall collision logic accordingly * Add missing allow attribute for dead code in ScalingStrategy enum * Implement ball physics and collision systems; add walls module and update game structure * Reorder update systems to ensure viewport updates occur alongside game logic * Add ball holding and launching mechanics; clean up build tasks * Refactor wall creation logic into a helper closure for improved readability and maintainability * Update workflow to trigger on pull requests for Rust files and Cargo.toml * bump version to 0.6.0 in Cargo.toml * Super-Linter: Fix linting issues * QoL Refactoring of the paddle movement system to reset velocity on direction change when hitting walls * Bump version to 0.7.0 in Cargo.toml
1 parent 0b5c6ea commit b86ec43

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "Breakout"
3-
version = "0.6.0"
3+
version = "0.7.0"
44
authors = ["Vianpyro"]
55
edition = "2024"
66

src/game/paddle.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,16 @@ pub fn paddle_movement_system(
6868
// Move by current velocity
6969
transform.translation.x += paddle.velocity * delta_time;
7070

71-
// Clamp to world bounds
71+
// Clamp to world bounds and reset velocity
7272
let half_paddle_width = PADDLE_SIZE.x / 2.0;
73-
transform.translation.x = transform
74-
.translation
75-
.x
76-
.clamp(-half_world_width + half_paddle_width, half_world_width - half_paddle_width);
73+
let min_x = -half_world_width + half_paddle_width;
74+
let max_x = half_world_width - half_paddle_width;
75+
let prev_x = transform.translation.x;
76+
let clamped_x = prev_x.clamp(min_x, max_x);
77+
transform.translation.x = clamped_x;
78+
// Reset velocity so player can move immediately in the other direction
79+
if (clamped_x - prev_x).abs() > f32::EPSILON {
80+
paddle.velocity = 0.0;
81+
}
7782
}
7883
}

0 commit comments

Comments
 (0)