Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with collision detection
#11
Ok, here it is, I had to convert it from Javascript but it only takes 8 IF calcs MAX per 2 pic dection. Sorry It took so long...

Code:
'8 Calc 2 pic collision dection made by Mitth'raw'nuruodo
Pic1x = what ever the x coordinate for the top left corner of pic 1 is
Pic1y = y coordinate for the top left corner for pic 1
Pic2x = you understand yet?
Pic2y = same idea here
Pic1Len = Length in pixels of Pic 1 (horizontal)
Pic1Hig = Height in pixels of Pic 1 (vertical)
Pic2Len = Length for Pic2
Pic2Hig = Samething
'time for collision dection

IF Pic1x >= Pic2x AND Pic1x <= Pic2x + Pic2Len THEN
  ' This in here was originally a sub (Checky):
  IF Pic1y >= Pic2y AND Pic1y <= Pic2y + PicHig[i] THEN CollsionHandler
  IF Pic1y + Pic1Hig >= Pic2y AND Pic1y + Pic1Hig <= Pic2y + Pic2Hig THEN CollisionHandler
  IF Pic2y >= Pic1y AND Pic2y <= Pic1y + Pic1Hig THEN CollisionHandler
  IF Pic2y + Pic2Hig >= Pic1y AND Pic2y + Pic2Hig <= Pic1y + Pic1Hig THEN CollisionHandler
END IF

IF Pic1x + Pic1Len >= Pic2x AND Pic1x + Pic1Len <= Pic2x+Pic2Len THEN
  SUB Checky as above
END IF

IF Pic2x >= Pic1x AND Pic2x <= Pic1x + Pic1Len THEN
  SUB Checky as above
END IF

IF Pic2x + Pic2Len >= Pic1x AND Pic2x + Pic2Len <= Pic1x + Pic1Len THEN
  SUB Checky as above
END IF
i]"But...it was so beautifully done"[/i]
Reply
#12
[syntax="qbasic"]DECLARE FUNCTION Collision%(x AS INTEGER, y AS INTEGER)
REDIM SHARED Map(1, 1)

'' Resize array, and load map-set

[...]

FUNCTION Collision%(x AS INTEGER, y AS INTEGER)
Collision=-1
IF Map(x, y) <> 0 THEN '' Where 0 is NULL space
Collision%=Map(x, y)
END IF
END FUNCTION[/syntax]

SOmething like that should work
Oz~[/code]
Reply
#13
^_^ not for characters moved pixel-by-pixel colliding with tiles
Reply
#14
Hey but guess what? Mine does it all! ^_^

Regardless. Just get the (X,Y) coordinate of the top left corner of both pics, and then their Length and Height and a max of 8 If calcs later it tells you if they're touching!

This works for tiles and pixel pics both. Also with them together too!
i]"But...it was so beautifully done"[/i]
Reply
#15
Thanks to everybody for the help! Smile
EEL THE BEAT OF EURODANCE!!! Smile
Reply
#16
Your Welcome.
i]"But...it was so beautifully done"[/i]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)