General purpose collision detection library for the use with LÖVE.
Go to file
Ali Rezvani 2ce5f592a6
Merge pull request #68 from rzvxa/master
Added a function for raycasting in the physics world.
2023-08-26 18:21:08 +03:30
docs Added documentation for raycast function 2023-08-18 21:40:48 +03:30
class.lua Adhere to new class commons specs. 2013-07-21 12:51:35 +02:00
gjk.lua Removed unnecessary statements 2017-11-05 19:46:31 -03:00
hc-0.1-1.rockspec Fix #54: Invalid rockspec 2018-04-08 14:12:09 +02:00
init.lua Fixed indentention 2023-08-23 18:18:09 +00:00
polygon.lua Prevents trying to create sub-polygons (triangles) with less than 3 non-collinear points when triangulating a polygon 2018-02-08 21:45:08 +01:00
README.md rzvxa will maintain thes - update README 2023-08-26 10:18:03 +02:00
shapes.lua Accomodate API change in love 0.10.0 2021-09-07 13:48:53 +02:00
spatialhash.lua Fix #44 - Spatialhash now keeps strong references 2018-04-08 14:40:38 +02:00
vector-light.lua Switch to light vector module 2012-04-12 16:07:50 +02:00

HC - General Purpose 2D Collision Detection System with LÖVE

Documentation and examples here: http://hc.readthedocs.org/

HC = require 'HC'

-- array to hold collision messages
local text = {}

function love.load()
    -- add a rectangle to the scene
    rect = HC.rectangle(200,400,400,20)

    -- add a circle to the scene
    mouse = HC.circle(400,300,20)
    mouse:moveTo(love.mouse.getPosition())
end

function love.update(dt)
    -- move circle to mouse position
    mouse:moveTo(love.mouse.getPosition())

    -- rotate rectangle
    rect:rotate(dt)

    -- check for collisions
    for shape, delta in pairs(HC.collisions(mouse)) do
        text[#text+1] = string.format("Colliding. Separating vector = (%s,%s)",
                                      delta.x, delta.y)
    end

    while #text > 40 do
        table.remove(text, 1)
    end
end

function love.draw()
    -- print messages
    for i = 1,#text do
        love.graphics.setColor(255,255,255, 255 - (i-1) * 6)
        love.graphics.print(text[#text - (i-1)], 10, i * 15)
    end

    -- shapes can be drawn to the screen
    love.graphics.setColor(255,255,255)
    rect:draw('fill')
    mouse:draw('fill')
end