summaryrefslogtreecommitdiffhomepage
path: root/app/systems/rules
diff options
context:
space:
mode:
Diffstat (limited to 'app/systems/rules')
-rw-r--r--app/systems/rules/alignment.rb4
-rw-r--r--app/systems/rules/cohesion.rb6
-rw-r--r--app/systems/rules/decay_speed.rb6
-rw-r--r--app/systems/rules/follow.rb26
4 files changed, 31 insertions, 11 deletions
diff --git a/app/systems/rules/alignment.rb b/app/systems/rules/alignment.rb
index 2c2af11..cbb3d99 100644
--- a/app/systems/rules/alignment.rb
+++ b/app/systems/rules/alignment.rb
@@ -17,8 +17,8 @@ FF::Scn::BoidRules.add(
move_boid[0] /= boids_count - 1.0
move_boid[1] /= boids_count - 1.0
- boid_update.cx += (move_boid[0] - boid_update.vx) / alignment.strength
- boid_update.cy += (move_boid[1] - boid_update.vy) / alignment.strength
+ boid_update.cx += (move_boid[0] - boid_update.vx) * alignment.strength
+ boid_update.cy += (move_boid[1] - boid_update.vy) * alignment.strength
end
end
)
diff --git a/app/systems/rules/cohesion.rb b/app/systems/rules/cohesion.rb
index 7e33961..6347a39 100644
--- a/app/systems/rules/cohesion.rb
+++ b/app/systems/rules/cohesion.rb
@@ -10,7 +10,7 @@ FF::Scn::BoidRules.add(
#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]
@@ -20,8 +20,8 @@ FF::Scn::BoidRules.add(
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
+ 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/decay_speed.rb b/app/systems/rules/decay_speed.rb
index 490c7d0..dd7761f 100644
--- a/app/systems/rules/decay_speed.rb
+++ b/app/systems/rules/decay_speed.rb
@@ -2,8 +2,10 @@ FF::Scn::BoidRules.add(
FF::Sys.new('DecaySpeed', priority: 50) do
FF::Cmp::DecaySpeed.each do |decay|
boid = decay.entities[0].components[FF::Cmp::Boid][0]
- boid.vx *= decay.strength
- boid.vy *= decay.strength
+ #boid.vx *= decay.strength
+ #boid.vy *= decay.strength
+ boid.cx += (boid.vx * decay.strength) - boid.vx
+ boid.cy += (boid.vy * decay.strength) - boid.vy
end
end
)
diff --git a/app/systems/rules/follow.rb b/app/systems/rules/follow.rb
index 0b5045e..abaabd7 100644
--- a/app/systems/rules/follow.rb
+++ b/app/systems/rules/follow.rb
@@ -14,14 +14,32 @@ FF::Scn::BoidRules.add(
camera = FF::Cmp::SingletonCamera[0]
angle = camera.angle * (Math::PI / 180)
mouse = $gtk.args.inputs.mouse
+ mouse_x = mouse.x
+ mouse_y = mouse.y
half_width = $gtk.args.grid.w * 0.5
half_height = $gtk.args.grid.h * 0.5
- target_coords[0] = (((mouse.x - half_width) / camera.zoom) * Math.cos(-angle)) - (((mouse.y - half_height) / camera.zoom) * Math.sin(-angle)) + camera.x
- target_coords[1] = (((mouse.x - half_width) / camera.zoom) * Math.sin(-angle)) + (((mouse.y - half_height) / camera.zoom) * Math.cos(-angle)) + camera.y
+
+ mag = Helpers::Vectors.magnitude(mouse_x,
+ mouse_y,
+ half_width,
+ half_height) / camera.zoom
+ if mag > half_height
+ mouse_x = (((mouse_x - half_width) / mag) * half_height) + half_width
+ mouse_y = (((mouse_y - half_height) / mag) * half_height) + half_height
+ end
+ #puts "x: #{mouse_x}"
+ #puts "y: #{mouse_y}"
+ #puts "x mag: #{mouse_x / mag}"
+ #puts "y mag: #{mouse_y / mag}"
+ $gtk.args.outputs.solids << [mouse_x, mouse_y, 250, 250, 255, 0, 0, 255]
+
+ target_coords[0] = (((mouse_x - half_width) / camera.zoom) * Math.cos(-angle)) - (((mouse_y - half_height) / camera.zoom) * Math.sin(-angle)) + camera.x
+ target_coords[1] = (((mouse_x - half_width) / camera.zoom) * Math.sin(-angle)) + (((mouse_y - half_height) / camera.zoom) * Math.cos(-angle)) + camera.y
+
end
- boid.cx += (target_coords[0] - boid.x) / follow.strength.to_f
- boid.cy += (target_coords[1] - boid.y) / follow.strength.to_f
+ boid.cx += (target_coords[0] - boid.x) * follow.strength.to_f
+ boid.cy += (target_coords[1] - boid.y) * follow.strength.to_f
end
end
)