fixed some things
This commit is contained in:
28
src/main.rs
28
src/main.rs
@@ -23,10 +23,10 @@ const MAX_BIRD_SPEED:i32 = 15;
|
||||
const BIRDS_COUNT:i32 = 500;
|
||||
const BIRD_SIZE:i32 = 15;
|
||||
|
||||
const VISION_RANGE:i32 = 100;
|
||||
const COHERENCE_RATE:i32 = 3;
|
||||
const SEPRATION_RATE:i32 = 0;
|
||||
const ALIGNEMENT_RATE:i32 = 5;
|
||||
const VISION_RANGE:i32 = 150;
|
||||
const COHERENCE_RATE:i32 = 1;
|
||||
const SEPRATION_RATE:i32 = 1;
|
||||
const ALIGNEMENT_RATE:i32 = 2;
|
||||
const NEIGHBOUR_TRESHOLD:i32 = 10;
|
||||
|
||||
pub struct Bird{
|
||||
@@ -59,7 +59,7 @@ impl Simulation{
|
||||
x_offset = (target.shape.x - bird.shape.x).abs();
|
||||
y_offset = (target.shape.y - bird.shape.y).abs();
|
||||
|
||||
if x_offset < VISION_RANGE && y_offset < VISION_RANGE{
|
||||
if x_offset <= VISION_RANGE && y_offset <= VISION_RANGE{
|
||||
sum.x += bird.shape.x;
|
||||
sum.y += bird.shape.y;
|
||||
neighbours_count += 1;
|
||||
@@ -82,7 +82,7 @@ impl Simulation{
|
||||
}else{
|
||||
bird.velocity.x -= COHERENCE_RATE;
|
||||
}
|
||||
}else{
|
||||
}else if posx < average.x{
|
||||
if bird.velocity.x + COHERENCE_RATE > MAX_BIRD_SPEED{
|
||||
bird.velocity.x = MAX_BIRD_SPEED;
|
||||
}else{
|
||||
@@ -96,7 +96,7 @@ impl Simulation{
|
||||
}else{
|
||||
bird.velocity.y -= COHERENCE_RATE;
|
||||
}
|
||||
}else{
|
||||
}else if posy < average.y{
|
||||
if bird.velocity.y + COHERENCE_RATE > MAX_BIRD_SPEED{
|
||||
bird.velocity.y = MAX_BIRD_SPEED;
|
||||
}else{
|
||||
@@ -119,7 +119,7 @@ impl Simulation{
|
||||
x_offset = (target.shape.x - bird.shape.x).abs();
|
||||
y_offset = (target.shape.y - bird.shape.y).abs();
|
||||
|
||||
if x_offset < NEIGHBOUR_TRESHOLD && y_offset < NEIGHBOUR_TRESHOLD{
|
||||
if x_offset <= NEIGHBOUR_TRESHOLD && y_offset <= NEIGHBOUR_TRESHOLD{
|
||||
sum.x += bird.shape.x;
|
||||
sum.y += bird.shape.y;
|
||||
neighbours_count += 1;
|
||||
@@ -142,7 +142,7 @@ impl Simulation{
|
||||
}else{
|
||||
bird.velocity.x += SEPRATION_RATE;
|
||||
}
|
||||
}else{
|
||||
}else if posx < average.x{
|
||||
if bird.velocity.x - SEPRATION_RATE < -MAX_BIRD_SPEED{
|
||||
bird.velocity.x = -MAX_BIRD_SPEED;
|
||||
}else{
|
||||
@@ -156,7 +156,7 @@ impl Simulation{
|
||||
}else{
|
||||
bird.velocity.y += SEPRATION_RATE;
|
||||
}
|
||||
}else{
|
||||
}else if posy < average.y{
|
||||
if bird.velocity.y - SEPRATION_RATE < -MAX_BIRD_SPEED{
|
||||
bird.velocity.y = -MAX_BIRD_SPEED;
|
||||
}else{
|
||||
@@ -177,21 +177,25 @@ 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;
|
||||
//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;
|
||||
}
|
||||
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 = 0;
|
||||
//bird.velocity.y -= bird.velocity.y / 2;
|
||||
}
|
||||
if posy + bird.velocity.y < 0{
|
||||
posy = WINDOW_HEIGHT - bird.shape.height() as i32;
|
||||
//bird.velocity.x += bird.velocity.x / 2;
|
||||
}
|
||||
|
||||
posx += bird.velocity.x;
|
||||
|
||||
Reference in New Issue
Block a user