This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
moves rectangle A by (dx, dy) and checks for a collision | |
with rectangle B. | |
if no collision occurs, returns false. | |
if a collision does occur, returns: | |
- the time within the movement when the collision occurs (from 0-1) | |
- the x component of the normal vector | |
- the y component of the normal vector |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function async(f) | |
local co | |
local function await(promise) | |
if promise:isFinished() then return end | |
promise:after(function() | |
local success, message = coroutine.resume(co) | |
if not success then error(message) end | |
end) | |
coroutine.yield() | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function sign(x) | |
return x < 0 and -1 or 1 | |
end | |
local function signedPower(x, n) | |
return sign(x) * (math.abs(x) ^ n) | |
end | |
local regularFont = love.graphics.newFont('font/CourierPrime-Bold.ttf', 48) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// based on https://stackoverflow.com/a/1084899 | |
// Vec2 is from the vek crate | |
type Entrance = Vec2<f32>; | |
type Exit = Vec2<f32>; | |
fn line_segment_and_circle_intersections( | |
line_segment_start: Vec2<f32>, | |
line_segment_end: Vec2<f32>, | |
circle_center: Vec2<f32>, |