Wednesday, December 24, 2014

Monkey getting started - simple Rectangle Overlap example code


Function Main:Int()
    If rectsoverlap(10,10,10,10,12,12,10,10) = False Then
    Print("No Collision")
    Else
    Print("Collision")
    End If
    Return 0
End Function

Function rectsoverlap:Bool(x1:Int, y1:Int, w1:Int, h1:Int, x2:Int, y2:Int, w2:Int, h2:Int)
    If x1 >= (x2 + w2) Or (x1 + w1) <= x2 Then Return False
    If y1 >= (y2 + h2) Or (y1 + h1) <= y2 Then Return False
    Return True
End

1 comment:

  1. Hah, I needed this sometime ago. I used a FOR/NEXT loop to look for overlapping pixels. Good job on getting the logic right above !

    ReplyDelete

Note: Only a member of this blog may post a comment.