Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #undef boolean
  2. #undef true
  3. #undef false
  4. #define boolean ubyte
  5. #define true 1
  6. #define false 0
  7.  
  8. type Pnt
  9.     as integer x
  10.     as integer y
  11. end type
  12.  
  13. type Rect
  14.     as Pnt position
  15.     as Pnt size
  16. end type
  17.  
  18. function rectIntersects(r1 as Rect ptr, r2 as Rect ptr) as boolean
  19.     #define r1p r1->position
  20.     #define r1s r1->size
  21.     #define r2p r2->position
  22.     #define r2s r2->size
  23.    
  24.     if(r1p.x < r2p.x+r2s.x ORELSE r1p.x+r1s.x > r2p.x) then return false
  25.     if(r1p.y < r2p.y+r2s.y ORELSE r1p.y+r1s.y > r2p.y) then return false
  26.    
  27.     'if(r1->position.x > r2->position.x + r2->size.x OR r2->position.x > r1->position.x + r1->size.x) then return false
  28.     'if(r1->position.y < r2->position.y + r2->size.y OR r2->position.y < r1->position.y + r1->size.y) then return false
  29.     return true
  30. end function
  31.  
  32. function createRect(x as integer, y as integer, w as integer, h as integer) as Rect
  33.     return type<Rect>(type<Pnt>(x,y),type<Pnt>(w,h))
  34. end function
  35.  
  36. 'createRect(x, y, width, height)
  37.  
  38. dim as Rect r1 = any, r2 = any
  39. r1 = createRect(50,50,50,50)
  40. r2 = createRect(75,75,50,50)
  41. print(str(rectIntersects(@r1, @r2)))
  42.  
  43. sleep()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement