Skip to content

Commit

Permalink
revert last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ippa committed Dec 11, 2010
1 parent 8062e2d commit 525a761
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions lib/chingu/traits/collision_detection.rb
Expand Up @@ -111,15 +111,15 @@ def bounding_box_bounding_circle_collision?(object2)
#
def each_collision(*klasses)
Array(klasses).each do |klass|
klass.each do |object|
(klass.respond_to?(:all) ? klass.all : Array(klass)).each do |object|
yield(self, object) if collides?(object)
end
end
end

def first_collision(*klasses)
Array(klasses).each do |klass|
klass.each do |object|
(klass.respond_to?(:all) ? klass.all : Array(klass)).each do |object|
return object if collides?(object)
end
end
Expand All @@ -132,7 +132,7 @@ def first_collision(*klasses)
#
def each_bounding_circle_collision(*klasses)
Array(klasses).each do |klass|
klass.each do |object|
(klass.respond_to?(:all) ? klass.all : Array(klass)).each do |object|
next unless self.collidable && object.collidable
yield(self, object) if Gosu.distance(self.x, self.y, object.x, object.y) < self.radius + object.radius
end
Expand All @@ -145,7 +145,7 @@ def each_bounding_circle_collision(*klasses)
#
def each_bounding_box_collision(*klasses)
Array(klasses).each do |klass|
klass.each do |object|
(klass.respond_to?(:all) ? klass.all : Array(klass)).each do |object|
return false unless self.collidable && object.collidable
yield(self, object) if self.bounding_box.collide_rect?(object.bounding_box)
end
Expand All @@ -161,7 +161,7 @@ module ClassMethods
# Enemy.each_at(sword.x, sword.y) { |enemy| enemy.die }
#
def each_at(x,y)
self.each do |object|
self.all.each do |object|
next unless object.collidable
yield object if object.respond_to?(:bb) && object.bb.collide_point?(x,y)
yield object if object.respond_to?(:radius) && Gosu.distance(object.x, object.y, x, y) < object.radius
Expand All @@ -172,9 +172,12 @@ def each_at(x,y)
# Works like each_collision but with inline-code for speedups
#
def each_bounding_circle_collision(*klasses)
Array(klasses).each do |klass|
self.each do |object1|
klass.each do |object2|
Array(klasses).each do |klass|
object2_list = (klass.respond_to?(:all) ? klass.all : Array(klass))
#total_radius = object1.radius + object2.radius # possible optimization?

self.all.each do |object1|
object2_list.each do |object2|
next if object1 == object2 # Don't collide objects with themselves
next unless object1.collidable && object2.collidable
yield object1, object2 if Gosu.distance(object1.x, object1.y, object2.x, object2.y) < object1.radius + object2.radius
Expand All @@ -188,8 +191,9 @@ def each_bounding_circle_collision(*klasses)
#
def each_bounding_box_collision(*klasses)
Array(klasses).each do |klass|
self.each do |object1|
klass.each do |object2|
object2_list = (klass.respond_to?(:all) ? klass.all : Array(klass))
self.all.each do |object1|
object2_list.each do |object2|
next if object1 == object2 # Don't collide objects with themselves
next unless object1.collidable && object2.collidable
yield object1, object2 if object1.bounding_box.collide_rect?(object2.bounding_box)
Expand Down Expand Up @@ -243,9 +247,9 @@ def each_collision(*klasses)
# end
# end
#end

self.each do |object1|
klass.each do |object2|
object2_list = (klass.respond_to?(:all) ? klass.all : Array(klass))
self.all.each do |object1|
object2_list.each do |object2|
next if object1 == object2 # Don't collide objects with themselves
yield object1, object2 if object1.collides?(object2)
end
Expand Down

0 comments on commit 525a761

Please sign in to comment.