I was messing around with my isometric tile map and stumbled onto this. This may only be useful in 2d tile-based game however.
sync on
sync rate 0
do
gosub Test
sync
cls
loop
Test:
gosub Display
gosub Control
return
Display:
ink rgb(255,255,255),0
box 100,100,200,200
ink rgb(255,0,0),0
line 100,100,200,100
line 100,100,100,200
line 100,200,200,100
ink rgb(200,200,255),0
text 0,0,"Collision: "+str$(Collision)
return
Control:
Collision = 0
if CheckArea(100,100,200,200)
mx = mousex()-100
my = mousey()-100
if mx+my < 100 then Collision = 1
endif
return
Function CheckArea(x1,y1,x2,y2)
mx = mousex()
my = mousey()
if mx > x1 and mx < x2 and my > y1 and my < y2 then value = 1 else value = 0
EndFunction value
The example shows a rough collision check of the top left corner of the box. It is also possible for all the other corners and you can adjust the length of a side.
sync on
sync rate 0
do
gosub Test
sync
cls
loop
Test:
gosub Display
gosub Control
return
Display:
ink rgb(255,255,255),0
box 100,100,200,200
ink rgb(255,0,0),0
line 100,100,200,100
line 100,100,100,150
line 100,150,200,100
ink rgb(200,200,255),0
text 0,0,"Collision: "+str$(Collision)
return
Control:
Collision = 0
if CheckArea(100,100,200,200)
mx = mousex()-100
my = mousey()-100
if mx+(my*2) < 100 then Collision = 1
endif
return
Function CheckArea(x1,y1,x2,y2)
mx = mousex()
my = mousey()
if mx > x1 and mx < x2 and my > y1 and my < y2 then value = 1 else value = 0
EndFunction value