diff options
Diffstat (limited to 'app/systems')
| -rw-r--r-- | app/systems/rules/separation.rb | 26 |
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 +) |
