Skip to content

Commit 0b58955

Browse files
committed
Fix pong clippy issues
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent f98debf commit 0b58955

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

src/games/pong.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use crate::control::GameControlArg;
2-
use crate::matrix::{GameState, Grid, State, HEIGHT, LEDS, WIDTH};
3-
4-
use heapless::Vec;
2+
use crate::matrix::{GameState, Grid, State, HEIGHT, WIDTH};
53

64
const PADDLE_WIDTH: usize = 5;
75

@@ -23,13 +21,14 @@ struct Ball {
2321

2422
#[derive(Clone)]
2523
pub struct PongState {
24+
// TODO: Properly calculate score and display it
2625
score: Score,
2726
ball: Ball,
2827
paddles: (usize, usize),
2928
pub speed: u64,
3029
}
3130

32-
pub fn start_game(state: &mut State, random: u8) {
31+
pub fn start_game(state: &mut State, _random: u8) {
3332
state.game = Some(GameState::Pong(PongState {
3433
score: Score { upper: 0, lower: 0 },
3534
ball: Ball {
@@ -95,31 +94,18 @@ fn hit_paddle(ball: Position, paddles: (usize, usize)) -> Option<usize> {
9594
}
9695
}
9796

98-
pub fn game_step(state: &mut State, random: u8) {
97+
pub fn game_step(state: &mut State, _random: u8) {
9998
if let Some(GameState::Pong(ref mut pong_state)) = state.game {
10099
pong_state.ball.pos = {
101100
let (vx, vy) = pong_state.ball.direction;
102-
let (x, y) = pong_state.ball.pos;
103101
let (x, y) = add_velocity(pong_state.ball.pos, pong_state.ball.direction);
104-
let x = if x < 0 {
105-
0
106-
} else if x > WIDTH - 1 {
107-
WIDTH - 1
108-
} else {
109-
x
110-
};
102+
let x = if x > WIDTH - 1 { WIDTH - 1 } else { x };
111103
if x == 0 || x == WIDTH - 1 {
112104
// Hit wall, bounce back
113105
pong_state.ball.direction = (-vx, vy);
114106
}
115107

116-
let y = if y < 0 {
117-
0
118-
} else if y > HEIGHT - 1 {
119-
HEIGHT - 1
120-
} else {
121-
y
122-
};
108+
let y = if y > HEIGHT - 1 { HEIGHT - 1 } else { y };
123109
let (x, y) = if let Some(paddle_hit) = hit_paddle((x, y), pong_state.paddles) {
124110
// Hit paddle, bounce back
125111
// TODO: Change vy direction slightly depending on where the paddle was hit

0 commit comments

Comments
 (0)