summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2021-12-19 22:51:56 -0500
committerrealtradam <[email protected]>2021-12-19 22:51:56 -0500
commitb203083dc920985da2e44e8bcfd6079ce2a900ba (patch)
tree991383255cf8aae029229c079760b3f707bb7e14
parent0c2d73d8a43d8aab8f6549a738084a3f4d8549ce (diff)
downloadSteelWings-b203083dc920985da2e44e8bcfd6079ce2a900ba.tar.gz
SteelWings-b203083dc920985da2e44e8bcfd6079ce2a900ba.zip
minimum speed component
-rw-r--r--app/components/rules/minimum_speed.rb3
-rw-r--r--app/main.rb3
-rw-r--r--app/systems/rules/minimum_speed.rb13
-rw-r--r--app/systems/start_game.rb1
-rw-r--r--app/systems/update_boid_position.rb2
5 files changed, 21 insertions, 1 deletions
diff --git a/app/components/rules/minimum_speed.rb b/app/components/rules/minimum_speed.rb
new file mode 100644
index 0000000..2e0e7fe
--- /dev/null
+++ b/app/components/rules/minimum_speed.rb
@@ -0,0 +1,3 @@
+
+FF::Cmp.new('BoidMinimumSpeed',
+ speed: 5)
diff --git a/app/main.rb b/app/main.rb
index 3bd54a2..23851df 100644
--- a/app/main.rb
+++ b/app/main.rb
@@ -11,6 +11,7 @@ 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/rules/minimum_speed.rb'
require 'app/components/debug/singleton_debug_vector_arrow.rb'
require 'app/components/singleton_camera.rb'
require 'app/components/stats/collision_damage.rb'
@@ -40,6 +41,8 @@ require 'app/systems/collision_damage.rb'
require 'app/systems/death.rb'
require 'app/systems/player_weapon.rb'
require 'app/systems/move_camera.rb'
+require 'app/systems/rules/minimum_speed.rb'
+
require 'app/factories/bullet.rb'
require 'app/factories/ships/osprey.rb'
diff --git a/app/systems/rules/minimum_speed.rb b/app/systems/rules/minimum_speed.rb
new file mode 100644
index 0000000..a78ee21
--- /dev/null
+++ b/app/systems/rules/minimum_speed.rb
@@ -0,0 +1,13 @@
+FF::Scn::BoidRules.add(
+ FF::Sys.new('BoidMinimumSpeed', priority: 98) do
+ FF::Cmp::BoidMinimumSpeed.each do |minspeed_component|
+ boid = minspeed_component.entities[0].components[FF::Cmp::Boid][0]
+ mag = Math.sqrt((boid.vx ** 2) + (boid.vy ** 2))
+ if mag < minspeed_component.speed
+ boid.vx = (boid.vx / mag) * minspeed_component.speed
+ boid.vy = (boid.vy / mag) * minspeed_component.speed
+ end
+ end
+ end
+)
+
diff --git a/app/systems/start_game.rb b/app/systems/start_game.rb
index 678100b..ebb972d 100644
--- a/app/systems/start_game.rb
+++ b/app/systems/start_game.rb
@@ -44,6 +44,7 @@ FF::Sys.new('StartGame', priority: 50 ) do
FF::Cmp::SingletonPlayer[0],
FF::Cmp::Team.new(team: 'player'),
FF::Cmp::Weapon.new,
+ FF::Cmp::BoidMinimumSpeed.new,
)
diff --git a/app/systems/update_boid_position.rb b/app/systems/update_boid_position.rb
index 81d053e..e5ca37a 100644
--- a/app/systems/update_boid_position.rb
+++ b/app/systems/update_boid_position.rb
@@ -1,5 +1,5 @@
FF::Scn::BoidRules.add(
- FF::Sys.new('UpdateBoidPosition', priority: 98) do
+ FF::Sys.new('UpdateBoidPosition', priority: 97) do
FF::Cmp::Boid.each do |boid|
boid.vx += boid.cx
boid.vy += boid.cy