diff options
Diffstat (limited to 'lib/rules/target.rb')
| -rw-r--r-- | lib/rules/target.rb | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/lib/rules/target.rb b/lib/rules/target.rb index ffee93a..f74bf7d 100644 --- a/lib/rules/target.rb +++ b/lib/rules/target.rb @@ -1,6 +1,28 @@ FF::Sys.new('Target', priority: 50) do - FF::Cmp::Boids.each do |boid| - boid.cx += ($x_target - boid.x) / $target_strength - boid.cy += ($y_target - boid.y) / $target_strength + + FF::Cmp::Fish[0].entities.each do |ent| + farthest = [] + boid = ent.component[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 + 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::Boids.each do |boid| + # boid.cx += ($config.target_x - boid.x) / $config.target_strength + # boid.cy += ($config.target_y - boid.y) / $config.target_strength + #end end |
