summaryrefslogtreecommitdiffhomepage
path: root/app/systems/collision_damage.rb
blob: 676589da0c1b53b899bec7cb8eb0c74861eb184d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
FF::Scn::BoidRules.add(
  FF::Sys.new("CollisionDamage", priority: 98) do

    FF::Cmp::SingletonEnemyTeam[0].entities.each do |enemy_entity|
      sprite = enemy_entity.components[FF::Cmp::Sprite][0].props
      if (sprite[:x] < 1312) && (sprite[:x] > -32) && (sprite[:y] < 752) && (sprite[:y] > -32)
        hitcircle_self = enemy_entity.components[FF::Cmp::Hitcircle][0]
        boid_self = hitcircle_self.entities[0].components[FF::Cmp::Boid][0]
        FF::Cmp::SingletonBullet[0].entities.each do |bullet_entity|
          hitcircle_target = bullet_entity.components[FF::Cmp::Hitcircle][0]
          boid_target = hitcircle_target.entities[0].components[FF::Cmp::Boid][0]
          if Math.sqrt(((boid_self.x - boid_target.x) ** 2) + ((boid_self.y - boid_target.y) ** 2)) < (hitcircle_target.r + hitcircle_self.r)
            #puts 'checks here'.upcase
            #puts 'hp dont exist' if hitcircle_target.entities[0].components[FF::Cmp::Hp].nil?
            #puts 'collision damage dont exist' if hitcircle_target.entities[0].components[FF::Cmp::CollisionDamage].nil?
            #puts 'checks end'.upcase
            hitcircle_target.entities[0].components[FF::Cmp::Hp][0].health -= hitcircle_self.entities[0].components[FF::Cmp::CollisionDamage][0].damage
            hitcircle_self.entities[0].components[FF::Cmp::Hp][0].health -= hitcircle_target.entities[0].components[FF::Cmp::CollisionDamage][0].damage
          end

        end

        player = FF::Cmp::SingletonPlayer[0].entities[0]
        unless player.nil?
          hitcircle_target = player.components[FF::Cmp::Hitcircle][0]
          boid_target = hitcircle_target.entities[0].components[FF::Cmp::Boid][0]
          if Math.sqrt(((boid_self.x - boid_target.x) ** 2) + ((boid_self.y - boid_target.y) ** 2)) < (hitcircle_target.r + hitcircle_self.r)
            hitcircle_target.entities[0].components[FF::Cmp::Hp][0].health -= hitcircle_self.entities[0].components[FF::Cmp::CollisionDamage][0].damage
            hitcircle_self.entities[0].components[FF::Cmp::Hp][0].health -= hitcircle_target.entities[0].components[FF::Cmp::CollisionDamage][0].damage
          end
        end
      end
    end
  end
)
=begin
FF::Cmp::Hitcircle.each do |hitcircle_self|
  boid_self = hitcircle_self.entities[0].components[FF::Cmp::Boid][0]
  FF::Cmp::Hitcircle.each do |hitcircle_target|
    next if hitcircle_self == hitcircle_target
    next if hitcircle_self.entities[0].components[FF::Cmp::Team][0].team == hitcircle_target.entities[0].components[FF::Cmp::Team][0].team
    #puts 'passed first check'
    boid_target = hitcircle_target.entities[0].components[FF::Cmp::Boid][0]
    if Math.sqrt(((boid_self.x - boid_target.x) ** 2) + ((boid_self.y - boid_target.y) ** 2)) < (hitcircle_target.r + hitcircle_self.r)
      puts 'checks here'.upcase
      puts 'hp dont exist' if hitcircle_target.entities[0].components[FF::Cmp::Hp].nil?
      puts 'collision damage dont exist' if hitcircle_target.entities[0].components[FF::Cmp::CollisionDamage].nil?
      puts 'checks end'.upcase
      hitcircle_target.entities[0].components[FF::Cmp::Hp][0].health -= hitcircle_self.entities[0].components[FF::Cmp::CollisionDamage][0].damage
    end
  end
end
end
)
=end