Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #50 from judofyr/each_bounding_box_fixes

Don't check collisions against itself:
  • Loading branch information...
commit fcc2177e5605475616d2803993986744733cf941 2 parents 1b65333 + 554dede
@ippa authored
Showing with 5 additions and 3 deletions.
  1. +5 −3 lib/chingu/traits/collision_detection.rb
View
8 lib/chingu/traits/collision_detection.rb
@@ -133,7 +133,8 @@ def first_collision(*klasses)
def each_bounding_circle_collision(*klasses)
Array(klasses).each do |klass|
(klass.respond_to?(:all) ? klass.all : Array(klass)).each do |object|
- next unless self.collidable && object.collidable
+ next if object == self
+ 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
end
@@ -146,7 +147,8 @@ def each_bounding_circle_collision(*klasses)
def each_bounding_box_collision(*klasses)
Array(klasses).each do |klass|
(klass.respond_to?(:all) ? klass.all : Array(klass)).each do |object|
- return false unless self.collidable && object.collidable
+ next if object == self
+ next unless self.collidable && object.collidable
yield(self, object) if self.bounding_box.collide_rect?(object.bounding_box)
end
end
@@ -259,4 +261,4 @@ def each_collision(*klasses)
end
end
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.