Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
How do you check for object collisions?
Author Message
Poutine King

Posted: Tue Apr 20, 2004 10:16 am   Post subject: How do you check for object collisions?

As the topic asks, how do you check for object collisions? I tired this:

(the x, y, x2, y2 are the positions of two circles)

if x =x2 and y=y2 then
x:= 0
y:= 0
x2:=100
y2:=100
end if

the ":=0" or ":=100" is so that they go in a prison but the first circle goes there right off the bat.

How do you check for two objects colliding???

Delos

Posted: Tue Apr 20, 2004 11:20 am   Post subject: (No subject)

[url=http://www.compsci.ca/v2/viewtopic.php?t=3525]
Checking for Collision Detection. By DanShadow.
[/url]

That is how.
gamer

Posted: Tue Apr 20, 2004 6:10 pm   Post subject: (No subject)

Poutine King

Posted: Thu Apr 22, 2004 10:09 am   Post subject: (No subject)

Uhh, what about characters?? I can make boundries and walls work but how does it work with another moving odject?
Paul

Posted: Fri Apr 23, 2004 8:55 pm   Post subject: (No subject)

you could use whatdotcolor and check for the edge of one object, or u could just use coordinates and compare the 2 different positions.
Poutine King

Posted: Thu Apr 29, 2004 10:23 am   Post subject: (No subject)

Actually the walls don't work??? Oi! They should, I used whatdotcolor to check if the co-ordinates of the character met those of the walls. But it doesn't work on the corners??? Can you guys give me an example so I can see what you mean. I'm a visual learner ya know.
Paul

Posted: Thu Apr 29, 2004 3:22 pm   Post subject: (No subject)

huh? Idk if this helps u, its just a ball u can move with ur arrow keys, and whatdotcolor collision on the corners work... is this what u mean?
 code: setscreen ("offscreenonly") var x, y : int x := 100 y := 100 var chars : array char of boolean loop     drawfillbox (0, 0, maxx, maxy, black)     drawfillbox (10, 10, maxx - 10, maxy - 10, 0) drawfillbox (maxx div 2, maxy div 2, maxx div 2 +150, maxy div 2 +50, black)     Input.KeyDown (chars)     if chars (KEY_UP_ARROW) then         if whatdotcolor (x, y + 13) = 0                 then             y := y + 5         end if     end if     if chars (KEY_RIGHT_ARROW) then         if whatdotcolor (x + 13 , y) = 0 then             x := x + 5         end if     end if     if chars (KEY_LEFT_ARROW) then         if whatdotcolor (x - 13, y) = 0 then             x := x - 5         end if     end if     if chars (KEY_DOWN_ARROW) then         if whatdotcolor (x, y - 13) = 0 then             y := y - 5         end if     end if     drawfilloval (x, y, 10, 10, 12)     View.Update     delay (10)     cls     end loop
Poutine King

Posted: Fri Apr 30, 2004 8:17 am   Post subject: (No subject)

YES! Thank you so much, now it works! Bless your soul sonny.