diff options
| author | realtradam <[email protected]> | 2021-12-17 01:29:19 -0500 |
|---|---|---|
| committer | realtradam <[email protected]> | 2021-12-17 01:29:19 -0500 |
| commit | c85f6533efb50981ef8cf59e840a1f8b58b4deef (patch) | |
| tree | 99dd36898baa41b9832072fbab72ce50539cd7c9 | |
| parent | 8c918c1fadebfb076cafcb347b8aac0e8ac28882 (diff) | |
| download | SteelWings-c85f6533efb50981ef8cf59e840a1f8b58b4deef.tar.gz SteelWings-c85f6533efb50981ef8cf59e840a1f8b58b4deef.zip | |
added boid bounds rule
| -rw-r--r-- | app/components/rules/bounds.rb | 5 | ||||
| -rw-r--r-- | app/main.rb | 2 | ||||
| -rw-r--r-- | app/systems/rules/bounds.rb | 20 | ||||
| -rw-r--r-- | app/systems/update_boid_sprite.rb | 6 | ||||
| -rw-r--r-- | app/tick.rb | 2 |
5 files changed, 34 insertions, 1 deletions
diff --git a/app/components/rules/bounds.rb b/app/components/rules/bounds.rb new file mode 100644 index 0000000..71495e6 --- /dev/null +++ b/app/components/rules/bounds.rb @@ -0,0 +1,5 @@ + +FF::Cmp.new('BoidBounds', + xmax: 1280, xmin: 0, + ymax: 720, ymin: 0, + strength: 10) diff --git a/app/main.rb b/app/main.rb index 972a496..cf31f77 100644 --- a/app/main.rb +++ b/app/main.rb @@ -4,8 +4,10 @@ require 'app/scenes/scenes.rb' require 'app/components/sprite.rb' require 'app/components/boid.rb' +require 'app/components/rules/bounds.rb' require 'app/systems/render.rb' require 'app/systems/update_boid_sprite.rb' +require 'app/systems/rules/bounds.rb' require 'app/tick.rb' diff --git a/app/systems/rules/bounds.rb b/app/systems/rules/bounds.rb new file mode 100644 index 0000000..602f19c --- /dev/null +++ b/app/systems/rules/bounds.rb @@ -0,0 +1,20 @@ +FF::Scn::BoidRules.add( + FF::Sys.new('BoidBounds') do + FF::Cmp::BoidBounds.each do |boid_bounds| + boid = boid_bounds.entities[0].components[FF::Cmp::Boid][0] + + if boid.x > boid_bounds.xmax + boid.cx -= boid_bounds.strength + elsif boid.x < boid_bounds.xmin + boid.cx += boid_bounds.strength + end + + if boid.y > boid_bounds.ymax + boid.cy -= boid_bounds.strength + elsif boid.y < boid_bounds.ymin + boid.cy += boid_bounds.strength + end + end + end +) + diff --git a/app/systems/update_boid_sprite.rb b/app/systems/update_boid_sprite.rb index d600fa6..57d5847 100644 --- a/app/systems/update_boid_sprite.rb +++ b/app/systems/update_boid_sprite.rb @@ -1,9 +1,15 @@ FF::Scn::Render.add( FF::Sys.new('UpdateBoidSprite', priority: 98) do FF::Cmp::Boid.each do |boid| + boid.vx += boid.cx + boid.vy += boid.cy + boid.x += boid.vx + boid.y += boid.vy boid.entities[0].components[FF::Cmp::Sprite][0].props[:x] = boid.x boid.entities[0].components[FF::Cmp::Sprite][0].props[:y] = boid.y # based on direction of the vector, needs to update the rotation of sprite too + boid.cx = 0 + boid.cy = 0 end end ) diff --git a/app/tick.rb b/app/tick.rb index a528a22..b8910f4 100644 --- a/app/tick.rb +++ b/app/tick.rb @@ -1,4 +1,4 @@ -FF::Ent.new(FF::Cmp::Sprite.new, FF::Cmp::Boid.new) +FF::Ent.new(FF::Cmp::Sprite.new, FF::Cmp::Boid.new(vx: 10, vy: 10), FF::Cmp::BoidBounds.new) def tick args FelFlame::Stage.call end |
