diff options
Diffstat (limited to 'lib/rules')
| -rw-r--r-- | lib/rules/limit.rb | 10 | ||||
| -rw-r--r-- | lib/rules/seperation.rb | 17 | ||||
| -rw-r--r-- | lib/rules/target.rb | 46 |
3 files changed, 55 insertions, 18 deletions
diff --git a/lib/rules/limit.rb b/lib/rules/limit.rb index dba9f96..b2a8f32 100644 --- a/lib/rules/limit.rb +++ b/lib/rules/limit.rb @@ -3,10 +3,16 @@ FF::Sys.new('Limit') do unless $config.limit < 0 FF::Cmp::Boids.each do |boid| + if boid.entities[0].components[FF::Cmp::Piranha].nil? + multi = 1.0 + else + multi = 0.3 + end + absolute_velocity = Math.sqrt((boid.vx**2) + (boid.vy**2)) if absolute_velocity > $config.limit - boid.vx = (boid.vx / absolute_velocity) * $config.limit - boid.vy = (boid.vy / absolute_velocity) * $config.limit + boid.vx = (boid.vx / absolute_velocity) * $config.limit * multi + boid.vy = (boid.vy / absolute_velocity) * $config.limit * multi end end end diff --git a/lib/rules/seperation.rb b/lib/rules/seperation.rb index 20fd2e6..65493e8 100644 --- a/lib/rules/seperation.rb +++ b/lib/rules/seperation.rb @@ -1,5 +1,6 @@ FF::Sys.new('Seperation', priority: 50) do - FF::Cmp::Boids.each do |boid_update| + FF::Cmp::Fish[0].entities.each do |ent| + boid_update = ent.components[FF::Cmp::Boids].first newvec = [0.0,0.0] FF::Cmp::Boids.each do |boid_check| next if boid_check == boid_update @@ -11,6 +12,20 @@ FF::Sys.new('Seperation', priority: 50) do boid_update.cx += newvec[0] / $config.seperation boid_update.cy += newvec[1] / $config.seperation end + FF::Cmp::Piranha[0].entities.each do |ent| + boid_update = ent.components[FF::Cmp::Boids].first + newvec = [0.0,0.0] + FF::Cmp::Piranha[0].entities.each do |ent2| + boid_check = ent2.components[FF::Cmp::Boids].first + next if boid_check == boid_update + if Math.sqrt(((-boid_check.x + boid_update.x)**2) + ((-boid_check.y + boid_update.y)**2)).abs < $config.seperation_distance + newvec[0] -= boid_check.x - boid_update.x + newvec[1] -= boid_check.y - boid_update.y + end + end + boid_update.cx += newvec[0] / ($config.seperation / 10) + boid_update.cy += newvec[1] / ($config.seperation / 10) + end end =begin diff --git a/lib/rules/target.rb b/lib/rules/target.rb index f74bf7d..9177845 100644 --- a/lib/rules/target.rb +++ b/lib/rules/target.rb @@ -1,25 +1,41 @@ FF::Sys.new('Target', priority: 50) do + FF::Cmp::Piranha[0].entities.each do |ent| + closest = [] + boid = ent.components[FF::Cmp::Boids].first + FF::Cmp::Fish[0].entities.each do |_fish| + fish = _fish.components[FF::Cmp::Boids].first + if closest[0].nil? || Math.sqrt(((boid.x - fish.x)**2) + ((boid.y - fish.y)**2)).abs < closest[0] + closest[0] = Math.sqrt(((boid.x - fish.x)**2) + ((boid.y - fish.y)**2)).abs + closest[1] = fish + end + end + boid.cx += ((closest[1].x - boid.x) / $config.target_strength) + boid.cy += ((closest[1].y - boid.y) / $config.target_strength) + end + FF::Cmp::Fish[0].entities.each do |ent| - farthest = [] - boid = ent.component[FF::Cmp::Boids].first + closest = [] + boid = ent.components[FF::Cmp::Boids].first FF::Cmp::Piranha[0].entities.each do |_piranha| - piranha = _piranha.component[FF::Cmp::Boids].first - if farthest[0].nil? || Math.sqrt(((boid.x - piranha.x)**2) + ((boid.y + piranha.y)**2)).abs < farthest[0] - farthest[0] = Math.sqrt(((boid.x - piranha.x)**2) + ((boid.y + piranha.y)**2)).abs - farthest[1] = piranha + piranha = _piranha.components[FF::Cmp::Boids].first + unless Math.sqrt(((boid.x - piranha.x)**2) + ((boid.y + piranha.y)**2)).abs > 250 + boid.cx -= ($config.target_strength / (piranha.x - boid.x)) + boid.cy -= ($config.target_strength / (piranha.y - boid.y)) + #boid.cy -= ((piranha.y - boid.y) / (1.0 / $config.target_strength)) end + #if closest[0].nil? || Math.sqrt(((boid.x - fish.x)**2) + ((boid.y + fish.y)**2)).abs < closest[0] + # closest[0] = Math.sqrt(((boid.x - fish.x)**2) + ((boid.y + fish.y)**2)).abs + # closest[1] = fish + #end end - boid.cx -= (2 * (piranha.x - boid.x) / $config.target_strength) - boid.cy -= (2 * (piranha.y - boid.y) / $config.target_strength) end - - # FF::Cmp::Piranha[0].entities.each do |ent| - # boid = ent.components[FF::Cmp::Boids].first - # boid.cx += ($config.target_x - boid.x) / $config.target_strength - # boid.cy += ($config.target_y - boid.y) / $config.target_strength - # #find closest fish - # end + # FF::Cmp::Piranha[0].entities.each do |ent| + # boid = ent.components[FF::Cmp::Boids].first + # boid.cx += ($config.target_x - boid.x) / $config.target_strength + # boid.cy += ($config.target_y - boid.y) / $config.target_strength + # #find closest fish + # end #FF::Cmp::Boids.each do |boid| # boid.cx += ($config.target_x - boid.x) / $config.target_strength |
