Changed the border behaviour

This commit is contained in:
2022-05-11 12:43:30 +02:00
parent 1ce9945f05
commit e27180a4b3

View File

@@ -26,7 +26,7 @@ const BIRD_SIZE:i32 = 15;
const VISION_RANGE:i32 = 150;
const COHERENCE_RATE:i32 = 1;
const SEPRATION_RATE:i32 = 1;
const ALIGNEMENT_RATE:i32 = 2;
const ALIGNEMENT_RATE:i32 = 1;
const NEIGHBOUR_TRESHOLD:i32 = 10;
pub struct Bird{
@@ -177,27 +177,60 @@ impl Simulation{
let mut posy = bird.shape.y;
let width:i32 = bird.shape.width() as i32;
let height:i32 = bird.shape.height() as i32;
//let left_wall = WINDOW_WIDTH - width;
//let bottom_wall = WINDOW_HEIGHT- height;
if posx + bird.velocity.x > WINDOW_WIDTH - width{
posx = 0;
//bird.velocity.x -= bird.velocity.x / 2;
let push_back = 1;
let soft_border_margin = 30;
let left_soft_border = 0 + soft_border_margin;
let right_soft_border = WINDOW_WIDTH - soft_border_margin;
let top_soft_border = 0 + soft_border_margin;
let bottom_soft_border = WINDOW_HEIGHT -soft_border_margin;
if posx + bird.velocity.x > WINDOW_WIDTH - width || posx + bird.velocity.x < 0{
bird.velocity.x = 0;
}
if posx + bird.velocity.x < 0{
posx = WINDOW_WIDTH - bird.shape.width() as i32;
//bird.velocity.x += bird.velocity.x / 2;
if posy + bird.velocity.y > WINDOW_HEIGHT - height || posy + bird.velocity.y < 0{
bird.velocity.y = 0;
}
if posx + bird.velocity.x > right_soft_border && bird.velocity.x <= 0{
//the bird is coming from the border so we accelerate it
bird.velocity.x -= push_back;
}else{
bird.velocity.x += push_back;
}
if posx - bird.velocity.x < left_soft_border && bird.velocity.x >= 0{
//the bird is coming from the border so we accelerate it
bird.velocity.x += push_back;
}else{
bird.velocity.x -= push_back;
}
if posy + bird.velocity.y > WINDOW_HEIGHT - height{
posy = 0;
//bird.velocity.y -= bird.velocity.y / 2;
if posy + bird.velocity.y > bottom_soft_border && bird.velocity.y <= 0{
//the bird is coming from the border so we accelerate it
bird.velocity.y -= push_back;
}else{
bird.velocity.y += push_back;
}
if posy + bird.velocity.y < 0{
posy = WINDOW_HEIGHT - bird.shape.height() as i32;
//bird.velocity.x += bird.velocity.x / 2;
if posy - bird.velocity.y < top_soft_border && bird.velocity.y >= 0{
//the bird is coming from the border so we accelerate it
bird.velocity.y += push_back;
}else{
bird.velocity.y -= push_back;
}
if bird.velocity.y > MAX_BIRD_SPEED{
bird.velocity.y = MAX_BIRD_SPEED;
}else if bird.velocity.y < -MAX_BIRD_SPEED{
bird.velocity.y = -MAX_BIRD_SPEED;
}
if bird.velocity.x > MAX_BIRD_SPEED{
bird.velocity.x = MAX_BIRD_SPEED;
}else if bird.velocity.x < -MAX_BIRD_SPEED{
bird.velocity.x = -MAX_BIRD_SPEED;
}
posx += bird.velocity.x;
posy += bird.velocity.y;
bird.shape.set_x(posx);