Description

This is a simple tutorial for teaching how to check for overlap between two boxes.

Z - show bounds


Code

If you wanted to turn this into a function for checking overlap, you would just need to return true if all the conditions in the tutorial were false, but return false if any of the conditions were true.

There are two code examples below. The first is a little more verbose. The second is done in a single line of code.

--assumes a/b have .x1/.y1/.x2/.y2
function overlap(a,b)
 if (a.x1>b.x2 or a.y1>b.y2 or a.x2<b.x1 or a.y2<b.y1) then
  return false
 else
  return true
 end
end
--assumes a/b have .x1/.y1/.x2/.y2
function overlap(a,b)
 return not (a.x1>b.x2 or a.y1>b.y2 or a.x2<b.x1 or a.y2<b.y1)
end

More information

Published 26 days ago
StatusReleased
PlatformsHTML5
Rating
(1)
AuthorMBoffin
GenreSimulation
TagsEducation, PICO-8

Comments

Log in with your itch.io account to leave a comment.

This is super helpful!