summaryrefslogtreecommitdiffhomepage
path: root/app/systems/death.rb
blob: ae02decca79f775ea715c8a1dd49c5b8da8b2062 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
FF::Scn::BoidRules.add(
  FF::Sys.new("Death", priority: 200) do
    FF::Cmp::Hp.each do |hp|
      if hp.health <= 0
        hp.entities[0].components.each do |manager, manager_array|
          if manager.equal?(FF::Cmp::SingletonPlayer)
            FF::Sys::EndGame.call
          elsif manager.equal?(FF::Cmp::SingletonEnemyTeam)
            FF::Sys::Score.call
          end
          next if manager.equal?(FF::Cmp::Hp)
          manager_array.reverse_each do |component|
            next if component.respond_to?(:singleton)
            component.delete
          end
        end
        hp.entities[0].delete
        hp.delete
      end
    end
  end
)