Basic Collision For Pico-8

code:

--basic collision


--position and size of a

--position and size of b



function coll(ax,ay,aw,ah,bx,by,bw,bh)

 if ax+aw>bx 

 and ay+ah>by

 and ax<bx+bw

 and ay<by+bh

 then return true

 end

 

end







--map collision


--position, size, flag and type


--all returns true if any corner touches flag 


--res returns which corner is touching flag


--ul = up left

--ur = up right

--dr = down right

--dl = down left

--n = nothing 



function collmap(x,y,w,h,f,c)

 if c=="all" then

  if fget(mget((x)/8,(y)/8),f)

  or fget(mget((x+w)/8,(y)/8),f)

  or fget(mget((x+w)/8,(y+h)/8),f)

  or fget(mget((x)/8,(y+h)/8),f)

  then return true

  end

 end

 

 if c=="res" then

  if fget(mget((x)/8,(y)/8),f)

  then return "ul"

  end

  if fget(mget((x+w)/8,(y)/8),f)

  then return "ur"

  end  

  if fget(mget((x+w)/8,(y+h)/8),f)

  then return "dr"

  end

  if fget(mget((x)/8,(y+h)/8),f)

  then return "dl"

  end

  if not fget(mget((x)/8,(y+h)/8),f)

  and not fget(mget((x+w)/8,(y+h)/8),f)

  and not fget(mget((x+w)/8,(y)/8),f)

  and not fget(mget((x)/8,(y)/8),f)

  then return "n"

  end

 end

end