summaryrefslogtreecommitdiffhomepage
path: root/app/systems/rules/follow.rb
diff options
context:
space:
mode:
authorArnold <[email protected]>2021-12-26 18:39:15 -0500
committerGitHub <[email protected]>2021-12-26 18:39:15 -0500
commitb7dea8016b5b1328808e28b76cc12343907de63e (patch)
tree5339c23bbde03c4d6c8c79d96b2033ab9e838ec0 /app/systems/rules/follow.rb
parentf70283e5ad5f5a5744ca0695a184f72f88803aca (diff)
downloadSteelWings-b7dea8016b5b1328808e28b76cc12343907de63e.tar.gz
SteelWings-b7dea8016b5b1328808e28b76cc12343907de63e.zip
implement ai randomizer, gameover screen, and other bug fixes
* Cleaned up factory. Fixed most bugs with death(last bug should be with move camera). * check if player entity is nil before shooting or moving camera * implement ai randomizer * separate button click detection to new system * implement gameover screen with button to return to menu * use reverse_each instead of cloning Co-authored-by: realtradam <[email protected]>
Diffstat (limited to 'app/systems/rules/follow.rb')
-rw-r--r--app/systems/rules/follow.rb27
1 files changed, 18 insertions, 9 deletions
diff --git a/app/systems/rules/follow.rb b/app/systems/rules/follow.rb
index abaabd7..47835f2 100644
--- a/app/systems/rules/follow.rb
+++ b/app/systems/rules/follow.rb
@@ -5,11 +5,19 @@ FF::Scn::BoidRules.add(
target_coords = [0.0, 0.0]
case follow.target
when FF::Cmp::Boid
- target_coords[0] = follow.target.x
- target_coords[1] = follow.target.y
+ mag = Helpers::Vectors.magnitude(follow.target.x,
+ follow.target.y,
+ boid.x,
+ boid.y)
+ target_coords[0] = (follow.target.x - boid.x) / mag
+ target_coords[1] = (follow.target.y - boid.y) / mag
when Array
- target_coords[0] = follow.target[0]
- target_coords[1] = follow.target[1]
+ mag = Helpers::Vectors.magnitude(follow.target[0],
+ follow.target[1],
+ boid.x,
+ boid.y)
+ target_coords[0] = (follow.target[0] - boid.x) / mag
+ target_coords[1] = (follow.target[1] - boid.y) / mag
when :mouse
camera = FF::Cmp::SingletonCamera[0]
angle = camera.angle * (Math::PI / 180)
@@ -23,6 +31,7 @@ FF::Scn::BoidRules.add(
mouse_y,
half_width,
half_height) / camera.zoom
+ # Caps the maximum power the mouse distance can inflict
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
@@ -31,15 +40,15 @@ FF::Scn::BoidRules.add(
#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]
+ #$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
+ target_coords[0] = (((mouse_x - half_width) / camera.zoom) * Math.cos(-angle)) - (((mouse_y - half_height) / camera.zoom) * Math.sin(-angle)) + camera.x - boid.x
+ target_coords[1] = (((mouse_x - half_width) / camera.zoom) * Math.sin(-angle)) + (((mouse_y - half_height) / camera.zoom) * Math.cos(-angle)) + camera.y - boid.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] * follow.strength.to_f
+ boid.cy += target_coords[1] * follow.strength.to_f
end
end
)