summaryrefslogtreecommitdiffhomepage
path: root/app/systems/rules/follow.rb
diff options
context:
space:
mode:
author_Tradam <[email protected]>2021-12-23 03:39:35 -0500
committerGitHub <[email protected]>2021-12-23 03:39:35 -0500
commitf70283e5ad5f5a5744ca0695a184f72f88803aca (patch)
treef9a182ccbc6ade03524f70f4483244a2e86ae6d1 /app/systems/rules/follow.rb
parent18f869d18fac469e44f9a6a4772494a262c1b0cb (diff)
downloadSteelWings-f70283e5ad5f5a5744ca0695a184f72f88803aca.tar.gz
SteelWings-f70283e5ad5f5a5744ca0695a184f72f88803aca.zip
cleaned up boid rules, changed how strength works (#8)
Diffstat (limited to 'app/systems/rules/follow.rb')
-rw-r--r--app/systems/rules/follow.rb26
1 files changed, 22 insertions, 4 deletions
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
)