Ooops
May 26, 2020, 07:19:56 PM

Author Topic: Collision Detection 2 boxes (QB64)  (Read 356 times)

Offline bplus

  • Full Member
  • ***
  • Posts: 134
Collision Detection 2 boxes (QB64)
« on: November 14, 2019, 06:31:43 PM »
Piece of cake!
Code: [Select]
FUNCTION collision% (b1x, b1y, b1w, b1h, b2x, b2y, b2w, b2h)
    ' x, y represent the box left most x and top most y
    ' w, h represent the box width and height which is the usual way sprites / tiles / images are described
    ' such that boxbottom = by + bh
    '        and boxright = bx + bw

    IF (b1y + b1h < b2y) OR (b1y > b2y + b2h) OR (b1x > b2x + b2w) OR (b1x + b1w < b2x) THEN
        collision% = 0
    ELSE
        collision% = 1
    END IF
END FUNCTION

Two circles even easier!

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal