Skip to content

Commit

Permalink
Quick exit on shape:collidesWith(shape)
Browse files Browse the repository at this point in the history
  • Loading branch information
vrld committed Jul 10, 2012
1 parent b20fc49 commit 5125f35
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions shapes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ end
-- collision dispatching:
-- let circle shape or compund shape handle the collision
function ConvexPolygonShape:collidesWith(other)
if self == other then return false end
if other._type ~= Shape.POLYGON then
local collide, sx,sy = other:collidesWith(self)
return collide, sx and -sx, sy and -sy
Expand All @@ -133,6 +134,7 @@ function ConvexPolygonShape:collidesWith(other)
end

function ConcavePolygonShape:collidesWith(other)
if self == other then return false end
if other._type == Shape.POINT then
return other:collidesWith(self)
end
Expand All @@ -151,6 +153,7 @@ function ConcavePolygonShape:collidesWith(other)
end

function CircleShape:collidesWith(other)
if self == other then return false end
if other._type == Shape.CIRCLE then
local px,py = self._center.x-other._center.x, self._center.y-other._center.y
local d = vector.len2(px,py)
Expand All @@ -174,6 +177,7 @@ function CircleShape:collidesWith(other)
end

function PointShape:collidesWith(other)
if self == other then return false end
if other._type == Shape.POINT then
return (self._pos == other._pos), 0,0
end
Expand Down

0 comments on commit 5125f35

Please sign in to comment.