summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorArnold <[email protected]>2021-12-19 14:34:40 -0500
committerGitHub <[email protected]>2021-12-19 14:34:40 -0500
commit196e18f1fd61ea9ef0e985bf9a6463a1188747c9 (patch)
treeb768a9e3b4e1483dd4ad2c7bcce045c37bc76527
parentbd645871ff96a45c23c05f6fc7a82ac1e2749616 (diff)
parent271134c11b369a65097cbd2cd674563bf6c9b19f (diff)
downloadSteelWings-196e18f1fd61ea9ef0e985bf9a6463a1188747c9.tar.gz
SteelWings-196e18f1fd61ea9ef0e985bf9a6463a1188747c9.zip
Merge pull request #2 from realtradam/follow-dev
implement follow component + system
-rw-r--r--app/components/rules/follow.rb3
-rw-r--r--app/main.rb2
-rw-r--r--app/systems/rules/follow.rb27
-rw-r--r--app/systems/start_game.rb10
4 files changed, 42 insertions, 0 deletions
diff --git a/app/components/rules/follow.rb b/app/components/rules/follow.rb
new file mode 100644
index 0000000..868d44f
--- /dev/null
+++ b/app/components/rules/follow.rb
@@ -0,0 +1,3 @@
+FF::Cmp.new('Follow',
+ :target,
+ strength: 100)
diff --git a/app/main.rb b/app/main.rb
index 5c4797e..12cd6dd 100644
--- a/app/main.rb
+++ b/app/main.rb
@@ -10,6 +10,7 @@ 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/rules/follow.rb'
require 'app/components/debug/debug_vector_arrow.rb'
require 'app/components/camera.rb'
@@ -24,6 +25,7 @@ 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/rules/follow.rb'
require 'app/systems/debug/debug_render_vector_arrow.rb'
require 'app/systems/camera.rb'
diff --git a/app/systems/rules/follow.rb b/app/systems/rules/follow.rb
new file mode 100644
index 0000000..0b5045e
--- /dev/null
+++ b/app/systems/rules/follow.rb
@@ -0,0 +1,27 @@
+FF::Scn::BoidRules.add(
+ FF::Sys.new('Follow', priority: 70) do
+ FF::Cmp::Follow.each do |follow|
+ boid = follow.entities[0].components[FF::Cmp::Boid][0]
+ 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
+ when Array
+ target_coords[0] = follow.target[0]
+ target_coords[1] = follow.target[1]
+ when :mouse
+ camera = FF::Cmp::SingletonCamera[0]
+ angle = camera.angle * (Math::PI / 180)
+ mouse = $gtk.args.inputs.mouse
+ 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
+ end
+
+ boid.cx += (target_coords[0] - boid.x) / follow.strength.to_f
+ boid.cy += (target_coords[1] - boid.y) / follow.strength.to_f
+ end
+ end
+)
diff --git a/app/systems/start_game.rb b/app/systems/start_game.rb
index cb29092..b71086e 100644
--- a/app/systems/start_game.rb
+++ b/app/systems/start_game.rb
@@ -32,6 +32,16 @@ FF::Sys.new('StartGame', priority: 50 ) do
)
end
+ sprite = FF::Cmp::Sprite.new
+ sprite.props[:path] = 'sprites/kenny/Ships/ship_0011.png'
+ FF::Ent.new(
+ FF::Cmp::Boid.new(x: position_range.sample, y: position_range.sample, vx: 25, vy: 25, w: sprite.props[:w], h: sprite.props[:h]),
+ sprite,
+ debug_arrow,
+ FF::Cmp::SingletonCamera[0],
+ FF::Cmp::Follow.new(target: :mouse, strength: 500)
+ )
+
FF::Stg.add(
FF::Scn::BoidRules,
FF::Scn::Debug,