summaryrefslogtreecommitdiffhomepage
path: root/lib/rules/target.rb
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2021-08-10 00:15:17 -0400
committerrealtradam <[email protected]>2021-08-10 00:15:17 -0400
commitc34e1d372676709f4eb05237025c67b878bf76d6 (patch)
treeae410bde79e576edd2c43057ba0f0ff63627b4f7 /lib/rules/target.rb
parentf80fd9ea0e340db6286feb014e437c9ca0c93dd0 (diff)
downloadruboids-c34e1d372676709f4eb05237025c67b878bf76d6.tar.gz
ruboids-c34e1d372676709f4eb05237025c67b878bf76d6.zip
readme and cleanup
Diffstat (limited to 'lib/rules/target.rb')
-rw-r--r--lib/rules/target.rb23
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/rules/target.rb b/lib/rules/target.rb
index 9177845..c0ced5c 100644
--- a/lib/rules/target.rb
+++ b/lib/rules/target.rb
@@ -5,13 +5,17 @@ FF::Sys.new('Target', priority: 50) do
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
+ 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
end
end
- boid.cx += ((closest[1].x - boid.x) / $config.target_strength)
- boid.cy += ((closest[1].y - boid.y) / $config.target_strength)
+ unless closest[0].nil?
+ boid.cx += ((closest[1].x - boid.x) / $config.target_strength)
+ boid.cy += ((closest[1].y - boid.y) / $config.target_strength)
+ end
end
FF::Cmp::Fish[0].entities.each do |ent|
@@ -19,10 +23,11 @@ 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 > 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))
+ 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
#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