summaryrefslogtreecommitdiffhomepage
path: root/app/systems
diff options
context:
space:
mode:
authorarngo <[email protected]>2021-12-17 23:41:50 -0500
committerarngo <[email protected]>2021-12-17 23:41:50 -0500
commit264b2f9e92a475db75904f72cad2bc8131b39dda (patch)
tree151316559bb65558cd61eb2d8a610b923d4dafde /app/systems
parenta402265fc290cbadf51b3d72925657f1f5cb84e4 (diff)
downloadSteelWings-264b2f9e92a475db75904f72cad2bc8131b39dda.tar.gz
SteelWings-264b2f9e92a475db75904f72cad2bc8131b39dda.zip
implement separation rule
Diffstat (limited to 'app/systems')
-rw-r--r--app/systems/rules/separation.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/app/systems/rules/separation.rb b/app/systems/rules/separation.rb
new file mode 100644
index 0000000..4a20193
--- /dev/null
+++ b/app/systems/rules/separation.rb
@@ -0,0 +1,26 @@
+FF::Scn::BoidRules.add(
+ FF::Sys.new('BoidsSeparation', priority: 50) do
+ FF::Cmp::BoidsSeparation.each do |separation|
+ newvec = [0.0, 0.0]
+ boid_update = separation.entities[0].components[FF::Cmp::Boid][0]
+
+ FF::Cmp::Boid.each do |boid_check|
+ next if boid_check == boid_update
+
+ if Math.sqrt(((-boid_check.x + boid_update.x)**2) + ((-boid_check.y + boid_update.y)**2)).abs < separation.distance
+ #if (boid_check.x - boid_update.x).abs < separation.distance and (boid_check.y - boid_update.y).abs < separation.distance
+ newvec[0] -= boid_check.x - boid_update.x
+ newvec[1] -= boid_check.y - boid_update.y
+ end
+ end
+
+ #unless separation.entities[0].components[FF::Cmp::DebugVectorArrow].nil?
+ # puts "newvec: #{newvec}"
+ # puts "cx: #{boid_update.cx} cy: #{boid_update.cy}"
+ # puts "vx: #{boid_update.vx} vy: #{boid_update.vy}"
+ #end
+ boid_update.cx += newvec[0].to_f * separation.strength
+ boid_update.cy += newvec[1].to_f * separation.strength
+ end
+ end
+)