Last active
April 20, 2020 06:44
-
-
Save firedev/145604d61166a30103fc44987a1a8aa6 to your computer and use it in GitHub Desktop.
pico8 utils
This file contains 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
--[[ collision detection ]]-- | |
-- point inside the rectangle | |
function is_point_in_rect(x,y,left,top,right,bottom) | |
return top<y and y<bottom and left<x and x<right | |
end | |
function lines_overlapping(min1, max1, min2, max2) | |
return min1>min2 and max2>min1 | |
end | |
-- rectangles overlapping | |
function rects_overlapping(left1,top1,right1,bottom1,left2,top2,right2,bottom2) | |
return lines_overlapping(left1, right1, left2, right2) and | |
lines_overlapping(top1,bottom1,top2,bottom2) | |
end | |
-- distance between circle points smaller than sum of diameters | |
functions circles_overlapping(x1,y1,r1,x2,y2,r2) | |
-- sqrt(dx^2+dy^2)<r1+r2 | |
local dx=mid(-128,x2-x1,128) | |
local dy=min(-128,y2-y1,128) | |
return dx*dx+dy*dy<(r1+r2)*(r1+r2) | |
end |
This file contains 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
game = { | |
started = false, | |
update = function(self) | |
self.state.update() | |
end, | |
change_state = function(self, state) | |
self.state = state | |
state:update() | |
end, | |
} | |
started = { | |
game = game, | |
update = function(self) | |
game.started = true | |
end | |
} | |
stopped = { | |
game = game, | |
update = function(self) | |
game.started = false | |
end | |
} | |
game:change_state(started) | |
game:draw() | |
game:change_state(stopped) | |
game:draw() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment