>‹?ÿÿÿðÿððððÿðÿðÿððÿððÿðÿÿÿÿÿÿÿÿÿÿÿÿððÿðððððððÿðððððððÿÿðÿðÿððÿðÿððÿððÿÿÿÿðÿÿÿÿðÿÿÿÿðÿÿÿÿÿðÿðððððÿÿððððððÿðÿð33333333333333333333333333333333333333333333333333000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000033333333333333333333333333333333333333333333333333ÿÿððððÿðÿððÿðÿððÿÿÿÿððÿÿÿððÿÿÿÿððÿÿÿÿðððððððððððððÿðÿððÿððÿððððÿðÿÿðÿÿÿðÿÿðÿÿðÿððððððQ-- title: point & rect collision -- author: txgruppi -- desc: a simple tool to visualize how we can detect collisions between a point and a rectangle -- site: https://github.com/txgruppi -- license: MIT License -- version: 0.3 -- script: lua local w = 100 local h = 100 local x = 5 local y = 10 function clamp(min,curr,max) if currmax then return max end return curr end function check_point_rect_coll(px, py, rx1, ry1, rx2, ry2) return px >= rx1 and px <= rx2 and py >= ry1 and py <= ry2 end function TIC() if btn(0) then y=y-1 end if btn(1) then y=y+1 end if btn(2) then x=x-1 end if btn(3) then x=x+1 end if btn(4) then w=w+1 end if btn(5) then w=w-1 end if btn(6) then h=h+1 end if btn(7) then h=h-1 end y=clamp(0,y,135) x=clamp(0,x,239) w=clamp(1,w,240-16) h=clamp(1,h,136-16) local x1=(240-w)/2 local y1=(136-h)/2 local x2=x1+w local y2=y1+h local coll=check_point_rect_coll(x, y, x1, y1, x2, y2) local c=14 if coll then c=3 end cls(0) rectb((240-w)/2,(136-h)/2,w,h,c) pix(x,y,13) print("x="..x.." y="..y.." x1="..x1.." y1="..y1.." x2="..x2.." y2="..y2,0,0,15,true,1,true) print("x>=x1 and x<=x2 and y>=y1 and y<=y2 == "..tostring(coll),0,130,15,true,1,true) print("x1,y1",x1-20,y1-6,15,true,1,true) print("x2,y2",x2,y2,15,true,1,true) end