summaryrefslogtreecommitdiffhomepage
path: root/app/systems/rules/cohesion.rb
diff options
context:
space:
mode:
authorarngo <[email protected]>2021-12-17 21:19:15 -0500
committerarngo <[email protected]>2021-12-17 21:19:15 -0500
commitb8b008c726810dc5e3f18b5637a5e5c882da7dd4 (patch)
treea64630f800ca3cdd304cf664e27b03970c71aace /app/systems/rules/cohesion.rb
parentc85f6533efb50981ef8cf59e840a1f8b58b4deef (diff)
downloadSteelWings-b8b008c726810dc5e3f18b5637a5e5c882da7dd4.tar.gz
SteelWings-b8b008c726810dc5e3f18b5637a5e5c882da7dd4.zip
add cohesion and debug stuff
Diffstat (limited to 'app/systems/rules/cohesion.rb')
-rw-r--r--app/systems/rules/cohesion.rb27
1 files changed, 27 insertions, 0 deletions
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
+)