i made an example for you.
the slide trick is that you try moving x and y in sequence, and not together.
#option_explicit
// Project: Test Axis Aligned Bounding Box
// Created: 2017-12-01
// MR 01.12.2017
SetWindowTitle( "Test Axis Aligned Bounding Box" )
SetWindowSize( 640, 640, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 100, 100 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
type Vector2
x as float
y as float
endtype
type Rect
a as Vector2 //1 Left,Top
b as Vector2 //2 Right,Bottom
endtype
Main()
end
Function Main()
local list as Rect[]
Add(list,10,10,20,20)
Add(list,35,10,15,15)
Add(list,60,50,15,35)
Add(list,20,60,30,20)
local i as Integer
local offset as Vector2
local col1 as integer
local col2 as integer
col1 = MakeColor(255,255,0) //yellow
col2 = MakeColor(255, 0,0) //red
local temp as Rect
local ok as integer
local selected as integer
selected=0
do
Print("Move Rect with Cursor or Gamepad, Tab Select Next")
if GetRawKeyPressed(9)
selected = selected + 1
if selected > 3 then selected = 0
endif
//---------------------------- Try X
offset.x=GetDirectionX()
offset.y=0
temp = list[selected]
Move(temp,offset)
ok = 1
for i = 0 to list.length
if i<>selected and Separate(temp,list[i]) = 0
ok = 0
exit
endif
next
if ok = 1 then list[selected] = temp
//---------------------------- Try Y
offset.x=0
offset.y=GetDirectionY()
temp = list[selected]
Move(temp,offset)
ok = 1
for i = 0 to list.length
if i<>selected and Separate(temp,list[i]) = 0
ok = 0
exit
endif
next
if ok = 1 then list[selected] = temp
//---------------------------- Draw
for i = 0 to list.length
Draw(list[i],col1)
next
Sync()
loop
EndFunction
Function Draw(r as Rect,col)
DrawBox(r.a.x,r.a.y,r.b.x,r.b.y,col,col,col,col,0)
EndFunction
Function Move(r ref as Rect,offset as Vector2)
r.a.x = r.a.x + offset.x
r.a.y = r.a.y + offset.y
r.b.x = r.b.x + offset.x
r.b.y = r.b.y + offset.y
EndFunction
Function Add(list ref as Rect[],x as float,y as float,w as float,h as float)
local r as Rect
r.a.x=x
r.a.y=y
r.b.x=x+w
r.b.y=y+h
list.insert(r) //copy into
EndFunction
Function Separate(a as Rect,b as Rect)
//Separate Rule
//Rect A & Rect B
//A x2 < B x1 or B x2 < A x1 or
//A y2 < B y1 or B y2 < A y1
local ret as integer
if (a.b.x < b.a.x or b.b.x < a.a.x) or (a.b.y < b.a.y or b.b.y < a.a.y)
ret = 1
else
ret = 0
endif
EndFunction ret
AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.11.2) Radeon R7 265 : Mac mini OS High Sierra (10.13)