mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-13 14:12:20 -06:00
fix: avoid rendering path lines between far apart cells
This commit is contained in:
19
src/game.rs
19
src/game.rs
@@ -14,7 +14,7 @@ use sdl2::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
asset::{get_asset_bytes, Asset},
|
asset::{get_asset_bytes, Asset},
|
||||||
audio::Audio,
|
audio::Audio,
|
||||||
constants::RAW_BOARD,
|
constants::{CELL_SIZE, RAW_BOARD},
|
||||||
entity::{
|
entity::{
|
||||||
ghost::{Ghost, GhostType},
|
ghost::{Ghost, GhostType},
|
||||||
pacman::Pacman,
|
pacman::Pacman,
|
||||||
@@ -222,12 +222,17 @@ impl Game {
|
|||||||
|
|
||||||
// Draw lines between the offset positions
|
// Draw lines between the offset positions
|
||||||
for window in offset_positions.windows(2) {
|
for window in offset_positions.windows(2) {
|
||||||
canvas
|
if let (Some(from), Some(to)) = (window.first(), window.get(1)) {
|
||||||
.draw_line(
|
// Skip if the distance is too far (used for preventing lines between tunnel portals)
|
||||||
(window[0].x as i32, window[0].y as i32),
|
if from.distance_squared(*to) > (CELL_SIZE * 16).pow(2) as f32 {
|
||||||
(window[1].x as i32, window[1].y as i32),
|
continue;
|
||||||
)
|
}
|
||||||
.map_err(anyhow::Error::msg)?;
|
|
||||||
|
// Draw the line
|
||||||
|
canvas
|
||||||
|
.draw_line((from.x as i32, from.y as i32), (to.x as i32, to.y as i32))
|
||||||
|
.map_err(anyhow::Error::msg)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user