
-----------------------------------
The Lone Ranger
Tue Dec 15, 2009 12:31 pm

Collsion Detection Help For My Game
-----------------------------------
I am trying to use a collision for my game in Turing. I added something that should use collison detection but it's not working. The program should also exit after the collision, but that to doesn't work. Please help.



loop
        if x2 < x and y2 = y then
            put "They have collided!"
            exit
        end if

        loop

            Input.KeyDown (chars)

            if chars (KEY_RIGHT_ARROW) then
                x := x + 5
            elsif chars (KEY_LEFT_ARROW) then
                x := x - 5
            end if

            if pic = 0 then
                put "Unable to load JPEG: ", Error.LastMsg
            end if

            Pic.Draw (pic, x, y, picCopy)
            delay (10)   
        end loop 


    end loop
end loop


The bolded section is the collision detection.

-----------------------------------
mirhagk
Tue Dec 15, 2009 2:49 pm

RE:Collsion Detection Help For My Game
-----------------------------------
your collision detection is pretty ghastly so first I want to point out that it only runs the collsion detection part once because it's outside of the innermost loop (which never exits)
remove the middle loop and then your on your way to making it work

-----------------------------------
The Lone Ranger
Tue Dec 15, 2009 2:59 pm

Re: Collsion Detection Help For My Game
-----------------------------------
Which one is the middle loop? Also if I remove the middle loop will the collision detection work?

-----------------------------------
mirhagk
Tue Dec 15, 2009 3:08 pm

RE:Collsion Detection Help For My Game
-----------------------------------
the one that is highlighted in black is the middle loop (move the code below it into the same loop as the Pic.Draw)

no I don't believe it will work in spite of that because right now as long as the asteroids y position is the same as the player's and the x position is less than his position (ie. to the left of it)

what you want is x2=x and y2=y (but that only checks for the middle of the asteroid. Look [url=http://compsci.ca/v3/viewtopic.php?t=13661]here for better collision detection)

I strongly suggest you check out the above link

-----------------------------------
The Lone Ranger
Tue Dec 15, 2009 3:52 pm

Re: Collsion Detection Help For My Game
-----------------------------------
Do you want me to use the tutorial on the first page?

-----------------------------------
The Lone Ranger
Tue Dec 15, 2009 5:07 pm

Re: Collsion Detection Help For My Game
-----------------------------------
Sorry for the double post, but could someone please help me improve my collision detection, so that I can finish my program. 

In my you play as a ship and are trying to dodge falling asteroids. Unfortunatley I haven't figured out how to properly use a collision.

Any help at all  would be greatly appreciated.

-----------------------------------
Tony
Tue Dec 15, 2009 6:47 pm

RE:Collsion Detection Help For My Game
-----------------------------------
I find it interesting how you post a question, use the answer to change your code a bit, but not enough to actually solve your problem, and so you create a new thread asking essentially the same question.

-----------------------------------
The Lone Ranger
Tue Dec 15, 2009 9:32 pm

Re: Collsion Detection Help For My Game
-----------------------------------
Yes... So can you help?

-----------------------------------
mirhagk
Wed Dec 16, 2009 8:18 am

RE:Collsion Detection Help For My Game
-----------------------------------
if you had clicked on the link I had given you then you wouldn't need our help. First off there's many different kind's of collision detection

There's rectangular collision detection (if two boxes intersect or not), circular collision detection (if two circles collide or not), mix and match(if a circle and a box collide), whatdotcolour(very precise, not very effecient), or linear collision detection (the most difficult to learn but the best in my opinion).

In your program you will likely want circular collision detetion, it's very easy to learn. go to this tutorial

http://compsci.ca/v3/viewtopic.php?t=13661

but basically you use Math.Distance which returns the distance between two points which you specify. For example:

if Math.Distance(x1,y1,x2,y2)