Computer Science Canada

Need Help Making A Collision

Author:  The Lone Ranger [ Mon Dec 14, 2009 5:13 pm ]
Post subject:  Need Help Making A Collision

I am making a game in Turing, in this game I need to use a collision. I made a program that should detect a collision, but it doesn't work.

Here is the program that I made,


var x1, y1, x2, y2 : int
var x11, y11, x22, y22 : int
var ship : int := Pic.FileNew ("E:\\images2.jpg")
var asteroid : int := Pic.FileNew ("E:\\Asteroid.jpg")



x1 := 300
y1 := 300
x2 := 150
y2 := 150
x11 := 300
y11 := 125
x22 := 350
y22 := 175
loop

cls
Pic.Draw (ship,x1,y1,picCopy)
Pic.Draw (asteroid,x11,y11,picCopy)
delay (20)

y1 -= 2
y2 -= 2

if x1 > x11 and y1 > y11 then
put "They have collided!"
exit
end if
end loop


I think it may have something to do with this part of the code,
if x1 > x11 and y1 > y11 then

I would really appreciate it if someone could help me out.

Author:  Tony [ Mon Dec 14, 2009 5:30 pm ]
Post subject:  Re: Need Help Making A Collision

The Lone Ranger @ Mon Dec 14, 2009 5:13 pm wrote:

I think it may have something to do with this part of the code,
if x1 > x11 and y1 > y11 then

It does indeed. Can you sketch out an area where this statement is true?

That is, take a screenshot of your game, pick some point x11/y11, and then shade all of the area such that if x1/y1 is anywhere inside that area, the above statement is true. This is the area of where "collision" occurs.

Author:  The Lone Ranger [ Mon Dec 14, 2009 5:42 pm ]
Post subject:  Re: Need Help Making A Collision

I'm sorry can you clarify that please.

Author:  Tony [ Mon Dec 14, 2009 5:51 pm ]
Post subject:  RE:Need Help Making A Collision

Draw me (well, for yourself really) a picture.

Author:  The Lone Ranger [ Mon Dec 14, 2009 5:52 pm ]
Post subject:  Re: Need Help Making A Collision

Thats ok, I just figured it out, thanks for your help.


: