mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-09 14:07:57 -06:00
fix: crash when entering right tunnel due to overflowing pixel position calculation
This commit is contained in:
@@ -2,10 +2,9 @@ use glam::{IVec2, UVec2};
|
|||||||
use sdl2::rect::Rect;
|
use sdl2::rect::Rect;
|
||||||
|
|
||||||
pub fn centered_with_size(pixel_pos: IVec2, size: UVec2) -> Rect {
|
pub fn centered_with_size(pixel_pos: IVec2, size: UVec2) -> Rect {
|
||||||
Rect::new(
|
// Ensure the position doesn't cause integer overflow when centering
|
||||||
pixel_pos.x - size.x as i32 / 2,
|
let x = pixel_pos.x.saturating_sub(size.x as i32 / 2);
|
||||||
pixel_pos.y - size.y as i32 / 2,
|
let y = pixel_pos.y.saturating_sub(size.y as i32 / 2);
|
||||||
size.x,
|
|
||||||
size.y,
|
Rect::new(x, y, size.x, size.y)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user