Verbessere Formatierung und Fehlerbehandlung im Ball-Update und der Eingabeverarbeitung
Some checks failed
Continuous integration / Test Suite (push) Has been cancelled
Continuous integration / Rustfmt (push) Has been cancelled
Continuous integration / Clippy (push) Has been cancelled
Continuous integration / build (push) Has been cancelled
Continuous integration / Check (push) Has been cancelled

This commit is contained in:
2025-07-07 15:18:50 +02:00
parent 3d7917ff8e
commit 52a138a144

View File

@ -112,7 +112,9 @@ impl Ball {
self.color = [
0.2 + 0.8 * (self.position[0].abs() / bounds_x),
0.2 + 0.8 * (self.position[1].abs() / bounds_y),
0.2 + 0.6 * ((self.position[0].abs() + self.position[1].abs()) / (bounds_x + bounds_y)),
0.2 + 0.6
* ((self.position[0].abs() + self.position[1].abs())
/ (bounds_x + bounds_y)),
];
}
// if the y position plus the radius is greater than the bounds_y or the y position minus the radius is less than -bounds_y, then bounce off the wall
@ -124,7 +126,9 @@ impl Ball {
self.color = [
0.2 + 0.8 * (self.position[0].abs() / bounds_x),
0.2 + 0.8 * (self.position[1].abs() / bounds_y),
0.2 + 0.6 * ((self.position[0].abs() + self.position[1].abs()) / (bounds_x + bounds_y)),
0.2 + 0.6
* ((self.position[0].abs() + self.position[1].abs())
/ (bounds_x + bounds_y)),
];
}
}
@ -405,10 +409,10 @@ impl State {
// Define key mappings: (axis_index, direction_value)
let key_mapping = match key_code {
// Some is a Rust Type Option that is used to indicate a valid mapping
KeyCode::KeyW => Some((1, 1.0)), // Y-axis, positive
KeyCode::KeyS => Some((1, -1.0)), // Y-axis, negative
KeyCode::KeyA => Some((0, -1.0)), // X-axis, negative
KeyCode::KeyD => Some((0, 1.0)), // X-axis, positive
KeyCode::KeyW => Some((1, 1.0)), // Y-axis, positive
KeyCode::KeyS => Some((1, -1.0)), // Y-axis, negative
KeyCode::KeyA => Some((0, -1.0)), // X-axis, negative
KeyCode::KeyD => Some((0, 1.0)), // X-axis, positive
KeyCode::Space if pressed => {
self.ball.toggle_control_mode();
return;
@ -561,7 +565,7 @@ impl ApplicationHandler for App {
Ok(_) => {}
Err(wgpu::SurfaceError::Lost) => state.resize(state.size),
Err(wgpu::SurfaceError::OutOfMemory) => event_loop.exit(),
Err(e) => eprintln!("{:?}", e),
Err(e) => eprintln!("{e:?}"),
}
// Request another frame for continuous animation