summaryrefslogtreecommitdiffhomepage
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
parenta402265fc290cbadf51b3d72925657f1f5cb84e4 (diff)
downloadSteelWings-264b2f9e92a475db75904f72cad2bc8131b39dda.tar.gz
SteelWings-264b2f9e92a475db75904f72cad2bc8131b39dda.zip
implement separation rule
-rw-r--r--app/components/rules/separation.rb3
-rw-r--r--app/main.rb2
-rw-r--r--app/systems/rules/separation.rb26
-rw-r--r--app/tick.rb61
4 files changed, 70 insertions, 22 deletions
diff --git a/app/components/rules/separation.rb b/app/components/rules/separation.rb
new file mode 100644
index 0000000..00fee32
--- /dev/null
+++ b/app/components/rules/separation.rb
@@ -0,0 +1,3 @@
+FF::Cmp.new('BoidsSeparation',
+ strength: 100,
+ distance: 100)
diff --git a/app/main.rb b/app/main.rb
index 20cc937..6b3abe6 100644
--- a/app/main.rb
+++ b/app/main.rb
@@ -7,6 +7,7 @@ require 'app/components/boid.rb'
require 'app/components/rules/bounds.rb'
require 'app/components/rules/cohesion.rb'
require 'app/components/rules/alignment.rb'
+require 'app/components/rules/separation.rb'
require 'app/components/debug/debug_vector_arrow.rb'
require 'app/systems/render.rb'
@@ -15,6 +16,7 @@ require 'app/systems/update_boid_position.rb'
require 'app/systems/rules/bounds.rb'
require 'app/systems/rules/cohesion.rb'
require 'app/systems/rules/alignment.rb'
+require 'app/systems/rules/separation.rb'
require 'app/systems/rules/reset_change_vector.rb'
require 'app/systems/debug/debug_render_vector_arrow.rb'
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
+)
diff --git a/app/tick.rb b/app/tick.rb
index 077c4bb..60ffbd5 100644
--- a/app/tick.rb
+++ b/app/tick.rb
@@ -1,26 +1,43 @@
-FF::Ent.new(FF::Cmp::Sprite.new,
- FF::Cmp::Boid.new(x: 10, y: 10, vx: 0, vy: 0),
- FF::Cmp::BoidBounds.new,
- FF::Cmp::BoidsAlignment.new,
- FF::Cmp::BoidsCohesion.new)
-FF::Ent.new(FF::Cmp::Sprite.new,
- FF::Cmp::Boid.new(x: 50, y: 50),
- FF::Cmp::BoidBounds.new,
- FF::Cmp::BoidsAlignment.new,
- FF::Cmp::BoidsCohesion.new)
-FF::Ent.new(FF::Cmp::Sprite.new,
- FF::Cmp::Boid.new(x: 70, y: 20),
- FF::Cmp::BoidBounds.new,
- FF::Cmp::BoidsAlignment.new,
- FF::Cmp::BoidsCohesion.new)
-FF::Ent.new(FF::Cmp::DebugVectorArrow.new(length: 5),
- FF::Cmp::Sprite.new,
- FF::Cmp::Boid.new(x: 150, y: 250),
- FF::Cmp::BoidBounds.new,
- FF::Cmp::BoidsAlignment.new,
- FF::Cmp::BoidsCohesion.new)
+debug_arrow = FF::Cmp::DebugVectorArrow.new(length: 5)
+FF::Ent.new(
+ FF::Cmp::Sprite.new,
+ FF::Cmp::Boid.new(x: 10, y: 10),
+ FF::Cmp::BoidBounds.new,
+ #FF::Cmp::BoidsAlignment.new,
+ FF::Cmp::BoidsSeparation.new,
+ #FF::Cmp::BoidsCohesion.new,
+ debug_arrow,
+)
+FF::Ent.new(
+ FF::Cmp::Sprite.new,
+ FF::Cmp::Boid.new(x: 50, y: 50),
+ FF::Cmp::BoidBounds.new,
+ #FF::Cmp::BoidsAlignment.new,
+ FF::Cmp::BoidsSeparation.new,
+ #FF::Cmp::BoidsCohesion.new,
+ debug_arrow,
+)
+FF::Ent.new(
+ FF::Cmp::Sprite.new,
+ FF::Cmp::Boid.new(x: 70, y: 20),
+ FF::Cmp::BoidBounds.new,
+ #FF::Cmp::BoidsAlignment.new,
+ FF::Cmp::BoidsSeparation.new,
+ #FF::Cmp::BoidsCohesion.new,
+ debug_arrow,
+)
+FF::Ent.new(
+ FF::Cmp::Sprite.new,
+ FF::Cmp::Boid.new(x: 150, y: 250),
+ FF::Cmp::BoidBounds.new,
+ #FF::Cmp::BoidsAlignment.new,
+ FF::Cmp::BoidsSeparation.new,
+ #FF::Cmp::BoidsCohesion.new,
+ debug_arrow,
+)
FF::Scn::Debug.add(FF::Sys::DebugRenderVectorArrow)
-@pause = false
+@pause = true
+FF::Stg.remove FF::Scn::BoidRules
def tick args
args.outputs.background_color = [0,0,0]
FelFlame::Stage.call