summaryrefslogtreecommitdiffhomepage
path: root/app/systems/rules/bounds.rb
blob: 0f1fc74fcffe75aaa34fee4a7bfbe0217ef875fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
FF::Scn::BoidRules.add(
  FF::Sys.new('BoidBounds', priority: 50) 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
)