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
Artificial intelligence/templates/examples/rts/rpg/strategy ect. in MonkeyX/CerberusX language. You can download the free version of MonkeyX from itch.io or Cerberus-x.com The Flash applets will stop working in around 2020.
Wednesday, December 24, 2014
Monkey getting started - simple Rectangle Overlap example code
Subscribe to:
Post Comments (Atom)
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