diff --git a/src/ant.rs b/src/ant.rs index 53130c8..47895ef 100644 --- a/src/ant.rs +++ b/src/ant.rs @@ -6,6 +6,7 @@ use macroquad::prelude::*; use macroquad::rand::RandomRange; use std::f32::consts::PI; +#[derive(Debug)] pub(crate) struct Ant { pos: Vec2, dir: f32, @@ -31,9 +32,8 @@ impl Ant { let acceleration = Vec2::new(self.dir.sin(), -self.dir.cos()); self.pos += acceleration * ANT_SPEED * frame_time; - // TODO: this is not fixing out of bounds write - self.pos.x = self.pos.x.clamp(0., MAP_WIDTH as f32); - self.pos.y = self.pos.y.clamp(0., MAP_HEIGHT as f32); + self.pos.x = self.pos.x.clamp(0., (MAP_WIDTH - 1) as f32); + self.pos.y = self.pos.y.clamp(0., (MAP_HEIGHT - 1) as f32); // TODO: change color over time trail_map.set_pixel(self.pos.x as u32, self.pos.y as u32, RED);