summaryrefslogtreecommitdiffhomepage
path: root/lib/rules/target.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rules/target.rb')
-rw-r--r--lib/rules/target.rb23
1 files changed, 11 insertions, 12 deletions
diff --git a/lib/rules/target.rb b/lib/rules/target.rb
index c0ced5c..8bd53a5 100644
--- a/lib/rules/target.rb
+++ b/lib/rules/target.rb
@@ -1,15 +1,14 @@
-FF::Sys.new('Target', priority: 50) do
+# frozen_string_literal: true
+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
- unless (fish.x > $config.xmax) || (fish.x < $config.xmin) || (fish.y > $config.ymax) || (fish.y < $config.ymin)
- 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
+ if !((fish.x > $config.xmax) || (fish.x < $config.xmin) || (fish.y > $config.ymax) || (fish.y < $config.ymin)) && (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
unless closest[0].nil?
@@ -23,12 +22,12 @@ FF::Sys.new('Target', priority: 50) do
boid = ent.components[FF::Cmp::Boids].first
FF::Cmp::Piranha[0].entities.each do |_piranha|
piranha = _piranha.components[FF::Cmp::Boids].first
- unless Math.sqrt(((boid.x - piranha.x)**2) + ((boid.y - piranha.y)**2)).abs > $config.target_fear
- #boid.cx -= ($config.target_strength / (piranha.x + boid.x))
- #boid.cy -= ($config.target_strength / (piranha.y + boid.y))
- boid.cx -= ((piranha.x - boid.x) / ($config.target_strength))
- boid.cy -= ((piranha.y - boid.y) / ($config.target_strength))
- end
+ next if Math.sqrt(((boid.x - piranha.x)**2) + ((boid.y - piranha.y)**2)).abs > $config.target_fear
+
+ #boid.cx -= ($config.target_strength / (piranha.x + boid.x))
+ #boid.cy -= ($config.target_strength / (piranha.y + boid.y))
+ boid.cx -= ((piranha.x - boid.x) / $config.target_strength)
+ boid.cy -= ((piranha.y - boid.y) / $config.target_strength)
#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