summaryrefslogtreecommitdiffhomepage
path: root/app/systems/rules
diff options
context:
space:
mode:
Diffstat (limited to 'app/systems/rules')
-rw-r--r--app/systems/rules/bounds.rb2
-rw-r--r--app/systems/rules/cohesion.rb27
-rw-r--r--app/systems/rules/reset_change_vector.rb8
3 files changed, 36 insertions, 1 deletions
diff --git a/app/systems/rules/bounds.rb b/app/systems/rules/bounds.rb
index 602f19c..0f1fc74 100644
--- a/app/systems/rules/bounds.rb
+++ b/app/systems/rules/bounds.rb
@@ -1,5 +1,5 @@
FF::Scn::BoidRules.add(
- FF::Sys.new('BoidBounds') do
+ FF::Sys.new('BoidBounds', priority: 50) do
FF::Cmp::BoidBounds.each do |boid_bounds|
boid = boid_bounds.entities[0].components[FF::Cmp::Boid][0]
diff --git a/app/systems/rules/cohesion.rb b/app/systems/rules/cohesion.rb
new file mode 100644
index 0000000..7e33961
--- /dev/null
+++ b/app/systems/rules/cohesion.rb
@@ -0,0 +1,27 @@
+FF::Scn::BoidRules.add(
+ FF::Sys.new('BoidsCohesion', priority: 50) do
+ center_mass = [0.0, 0.0]
+ boids_count = FF::Cmp::BoidsCohesion.data.count
+
+ FF::Cmp::BoidsCohesion.each do |cohesion|
+ boid = cohesion.entities[0].components[FF::Cmp::Boid][0]
+ center_mass[0] += boid.x
+ center_mass[1] += boid.y
+ #puts boid.x
+ #puts boid.y
+ end
+
+ #puts center_mass
+ FF::Cmp::BoidsCohesion.each do |cohesion|
+ boid_update = cohesion.entities[0].components[FF::Cmp::Boid][0]
+ move_boid = center_mass.dup
+ move_boid[0] -= boid_update.x
+ move_boid[1] -= boid_update.y
+ move_boid[0] /= boids_count - 1.0
+ move_boid[1] /= boids_count - 1.0
+
+ boid_update.cx += (move_boid[0] - boid_update.x) / cohesion.strength.to_i
+ boid_update.cy += (move_boid[1] - boid_update.y) / cohesion.strength.to_i
+ end
+ end
+)
diff --git a/app/systems/rules/reset_change_vector.rb b/app/systems/rules/reset_change_vector.rb
new file mode 100644
index 0000000..28656e0
--- /dev/null
+++ b/app/systems/rules/reset_change_vector.rb
@@ -0,0 +1,8 @@
+FF::Scn::BoidRules.add(
+ FF::Sys.new('ResetChangeVector', priority: 45) do
+ FF::Cmp::Boid.each do |boid|
+ boid.cx = 0
+ boid.cy = 0
+ end
+ end
+)