X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fcore%2Flevel%2Fmod.rs;fp=src%2Fcore%2Flevel%2Fmod.rs;h=5df8ba6e12640dba431e65c9c624e29ceb24fd79;hb=d59c7f04922541543adb533ab07a26a781341777;hp=ac13e4ebb090468699cb636a457a79df75f8fe00;hpb=d01df1fc6e3bfafd385b2533e6155ddd8714fcfb;p=kaka%2Frust-sdl-test.git diff --git a/src/core/level/mod.rs b/src/core/level/mod.rs index ac13e4e..5df8ba6 100644 --- a/src/core/level/mod.rs +++ b/src/core/level/mod.rs @@ -14,15 +14,15 @@ pub use self::lvlgen::LevelGenerator; pub struct Level { pub gravity: Point, pub grid: Grid, - walls: Vec>, + walls: Vec, wall_grid: Grid>>, } impl Level { - pub fn new(gravity: Point, grid: Grid, mut walls: Vec>) -> Self { + pub fn new(gravity: Point, grid: Grid, mut walls: Vec) -> Self { let size = (2560, 1440); // TODO: get actual size from walls or something let wall_grid = Level::build_wall_grid(&mut walls, &size.into()); - dbg!(&wall_grid.cell_size); + dbg!(&wall_grid.scale); Level { gravity, grid, @@ -35,11 +35,11 @@ impl Level { fn build_wall_grid(walls: &mut Vec, lvlsize: &Dimension) -> Grid>> { let size = dimen!(lvlsize.width / 20, lvlsize.height / 20); // TODO: make sure all walls fit within the grid bounds let cs = point!(lvlsize.width / size.width, lvlsize.height / size.height); - //let cs = point!(cell_size.width as f64, cell_size.height as f64); + //let cs = point!(scale.width as f64, scale.height as f64); let mut grid = Grid { cells: vec!(vec!(vec!(); size.height); size.width), size, - cell_size: dimen!(cs.x, cs.y), + scale: dimen!(cs.x as f64, cs.y as f64), }; for wall in walls { @@ -56,7 +56,7 @@ impl Level { pub fn render(&mut self, renderer: &mut Renderer, _sprites: &SpriteManager) { // original grid renderer.canvas().set_draw_color((64, 64, 64)); - let size = &self.grid.cell_size; + let size = &self.grid.scale; for x in 0..self.grid.size.width { for y in 0..self.grid.size.height { if self.grid.cells[x][y] { @@ -71,7 +71,7 @@ impl Level { // wall grid renderer.canvas().set_draw_color((0, 32, 0)); - let size = &self.wall_grid.cell_size; + let size = &self.wall_grid.scale; for x in 0..self.wall_grid.size.width { for y in 0..self.wall_grid.size.height { if !self.wall_grid.cells[x][y].is_empty() { @@ -125,7 +125,7 @@ pub enum IntersectResult<'a> { #[derive(Debug, Default)] pub struct Grid { pub size: Dimension, - pub cell_size: Dimension, + pub scale: Dimension, pub cells: Vec>, } @@ -154,8 +154,7 @@ impl Grid { /// Returns a list of grid coordinates that a line in world coordinates passes through. pub fn grid_coordinates_on_line(&self, p1: Point, p2: Point) -> Vec> { - let scale = (self.cell_size.width as f64, self.cell_size.height as f64); - supercover_line(p1 / scale, p2 / scale) + supercover_line(p1 / self.scale, p2 / self.scale) .iter() .map(|c| self.to_grid_coordinate(*c)) .flatten()