mirror of
https://github.com/vrld/HC.git
synced 2024-11-18 12:54:23 +00:00
Quick exit on shape:collidesWith(shape)
This commit is contained in:
parent
b20fc496eb
commit
5125f35e71
@ -123,6 +123,7 @@ end
|
|||||||
-- collision dispatching:
|
-- collision dispatching:
|
||||||
-- let circle shape or compund shape handle the collision
|
-- let circle shape or compund shape handle the collision
|
||||||
function ConvexPolygonShape:collidesWith(other)
|
function ConvexPolygonShape:collidesWith(other)
|
||||||
|
if self == other then return false end
|
||||||
if other._type ~= Shape.POLYGON then
|
if other._type ~= Shape.POLYGON then
|
||||||
local collide, sx,sy = other:collidesWith(self)
|
local collide, sx,sy = other:collidesWith(self)
|
||||||
return collide, sx and -sx, sy and -sy
|
return collide, sx and -sx, sy and -sy
|
||||||
@ -133,6 +134,7 @@ function ConvexPolygonShape:collidesWith(other)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function ConcavePolygonShape:collidesWith(other)
|
function ConcavePolygonShape:collidesWith(other)
|
||||||
|
if self == other then return false end
|
||||||
if other._type == Shape.POINT then
|
if other._type == Shape.POINT then
|
||||||
return other:collidesWith(self)
|
return other:collidesWith(self)
|
||||||
end
|
end
|
||||||
@ -151,6 +153,7 @@ function ConcavePolygonShape:collidesWith(other)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function CircleShape:collidesWith(other)
|
function CircleShape:collidesWith(other)
|
||||||
|
if self == other then return false end
|
||||||
if other._type == Shape.CIRCLE then
|
if other._type == Shape.CIRCLE then
|
||||||
local px,py = self._center.x-other._center.x, self._center.y-other._center.y
|
local px,py = self._center.x-other._center.x, self._center.y-other._center.y
|
||||||
local d = vector.len2(px,py)
|
local d = vector.len2(px,py)
|
||||||
@ -174,6 +177,7 @@ function CircleShape:collidesWith(other)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function PointShape:collidesWith(other)
|
function PointShape:collidesWith(other)
|
||||||
|
if self == other then return false end
|
||||||
if other._type == Shape.POINT then
|
if other._type == Shape.POINT then
|
||||||
return (self._pos == other._pos), 0,0
|
return (self._pos == other._pos), 0,0
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user