Added multidirectional collision detection (only left to detect on wich face and to predict the position)
This commit is contained in:
+20
-7
@@ -237,23 +237,36 @@ impl Game{
|
|||||||
let posx_2 = posx + bloc.charge.x;
|
let posx_2 = posx + bloc.charge.x;
|
||||||
let posy_2 = posy + bloc.charge.y;
|
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;
|
let tmp_y;
|
||||||
tmp_y = posy + (tmp_x-posx)*((posy_2-posy) / (posx_2-posx));
|
//tmp_y = posy + (tmp_x-posx)*((posy_2-posy) / (posx_2-posx));
|
||||||
//check the tile in the new Point
|
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_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;
|
let tmp_index_1d = tmp_index_2d.x + map.size.x * tmp_index_2d.y;
|
||||||
|
|
||||||
match map.grid[tmp_index_1d as usize]{
|
match map.grid[tmp_index_1d as usize]{
|
||||||
Tile::Rock =>{
|
Tile::Rock =>{
|
||||||
bloc.charge = Point::new(0, 0);
|
bloc.charge = Point::new(0, 0);
|
||||||
|
println!("rock");
|
||||||
}
|
}
|
||||||
_=>{
|
_=>{
|
||||||
//nothing
|
println!("Not rock");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user