Coming from a WinAPI background I find it easier to use POINT and RECT structures for such things, just my way of coding
heres a few helper functions for using such structures in AGK
// POINT Structure
Type POINT
x as integer
y as integer
EndType
// RECT Structure
Type RECT
left as integer
top as integer
right as integer
bottom as integer
EndType
// Is the point inside the rect?
Function IsPtInRect(pt as POINT, rc as RECT)
result as integer
if pt.x >= rc.left and pt.x <= rc.right and pt.y >= rc.top and pt.y <= rc.bottom
result=1
endif
EndFunction result
// get mouse position as POINT
Function MouseToPoint()
pt as POINT
pt.x = GetRawMouseX()
pt.y = GetRawMouseY()
EndFunction pt
// Get sprite as RECT
Function SpriteToRect(spr_id)
rc as RECT
if GetSpriteExists(spr_id)
rc.left = GetSpriteX(spr_id)
rc.top = GetSpriteY(spr_id)
rc.right = GetSpriteX(spr_id)+GetSpriteWidth(spr_id)
rc.bottom = GetSpriteY(spr_id)+GetSpriteHeight(spr_id)
endif
EndFunction rc
// test RECt (for box)
rc as RECT
rc.left = 100
rc.top = 100
rc.right = 200
rc.bottom = 200
// Test Sprite
spr = CreateSprite(0)
SetSpritePosition(spr, 300, 100)
SetSpriteSize(spr, 200, 200)
do
// draw a box with our RECT
DrawBox(rc.left, rc.top, rc.right, rc.bottom, 255, 255, 255, 255, 0)
// is the mouse in the box?
Print( IsPtInRect(MouseToPoint(), rc) )
// is the mouse in the sprite?
Print( IsPtInRect(MouseToPoint(), SpriteToRect(spr)))
Sync()
loop