HC/README.md

51 lines
1.2 KiB
Markdown
Raw Permalink Normal View History

## HC - General Purpose 2D Collision Detection System with [LÖVE](https://love2d.org)
2021-09-07 11:53:36 +00:00
Documentation and examples here: http://hc.readthedocs.org/
2021-09-07 11:53:36 +00:00
```lua
HC = require 'HC'
2021-09-07 11:53:36 +00:00
-- array to hold collision messages
local text = {}
2021-09-07 11:53:36 +00:00
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
```