diff --git a/src/main.rs b/src/main.rs index dcd81bf..f2d6d0a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -237,23 +237,36 @@ impl Game{ let posx_2 = posx + bloc.charge.x; let posy_2 = posy + bloc.charge.y; - for _i in 1..1{ - println!("coucou"); + + let mut range = posx..posx_2; + if posx < posx_2{ + range = posx..posx_2; + }else if posx > posx_2 && posx > 0{ + range = posx_2..posx; + }else{ + //there is not velocity in the x axis + range = posx..posx+1; } - - for tmp_x in posx..posx_2{ + + for tmp_x in range{ let tmp_y; - tmp_y = posy + (tmp_x-posx)*((posy_2-posy) / (posx_2-posx)); - //check the tile in the new Point + //tmp_y = posy + (tmp_x-posx)*((posy_2-posy) / (posx_2-posx)); + if posx_2-posx == 0{ + tmp_y = posy + (tmp_x-posx)*1; + }else{ + tmp_y = posy + (tmp_x-posx)*((posy_2-posy) / (posx_2-posx)); + } + //check the tile in the new Point let tmp_index_2d = Point::new(tmp_x / (WINDOW_WIDTH / map.size.x),tmp_y / (WINDOW_HEIGHT / map.size.y)); let tmp_index_1d = tmp_index_2d.x + map.size.x * tmp_index_2d.y; match map.grid[tmp_index_1d as usize]{ Tile::Rock =>{ bloc.charge = Point::new(0, 0); + println!("rock"); } _=>{ - //nothing + println!("Not rock"); } }