
-----------------------------------
Zerimas
Sat Jan 22, 2005 6:30 pm

Collision Detection help Now with more complications!!!
-----------------------------------
EDIT (I forgot to post this earlier): I am using version 3.1.1a of turing 
I'm working on  a turing version of  space invaders and I'm have trouble with collision detection.
Note in this progam "1" signifies your ship and "2" signifies and enemy ship.

These procedures are used for checking if the ship has crashed

proc coldecup
    for col : 1 .. 13
        for row : 1 .. 8
            crash := false
            if memory (col, row).shptype = 1 and memory (col, row +
                    1).shptype = 2 then
                crash := true
            end if
        end for
    end for
end coldecup

proc coldecdown
    for col : 1 .. 13
        for decreasing row : 9 .. 2
            crash := false
            if memory (col, row).shptype = 1 and memory (col, row -
                    1).shptype = 2 then
                crash := true
            end if
        end for
    end for
end coldecdown

proc coldecright
    for col : 1 .. 12
        for row : 1 .. 9
            crash := false
            if memory (col, row).shptype = 1 and memory (col + 1,
                    row).shptype = 2 then
                crash := true
            end if
        end for
    end for
end coldecright

proc coldecleft
    for decreasing col : 13 .. 2
        for row : 1 .. 9
            crash := false
            if memory (col, row).shptype = 1 and memory (col - 1,
                    row).shptype = 2
                    then
                crash := true
            end if
        end for
    end for
end coldecleft



I've included the proceudres in a process to move the ship



process moveship
    loop

        locate (1, 1)
        showmem
        if hasch then
            getch (ch)
            if ord (ch) = 203 then %left
                for col : 1 .. 13
                    for row : 1 .. 9
                        coldecleft %check for collision

                        if memory (col, row).shptype = 1 and col > 1 then
                            memory (col - 1, row).shptype := 1
                            memory (col, row).shptype := 0
                        end if
                    end for
                end for
            elsif ord (ch) = 205 then %right
                for decreasing col : 13 .. 1
                    for row : 1 .. 9
                        coldecright
                        if memory (col, row).shptype = 1 and col < 13
                                then
                            memory (col + 1, row).shptype := 1
                            memory (col, row).shptype := 0

                        end if
                    end for
                end for
            elsif ord (ch) = 200 then % up
                for col : 1 .. 13
                    for decreasing row : 9 .. 1
                        coldecup

                        if memory (col, row).shptype = 1 and row < 9 then
                            memory (col, row + 1).shptype := 1
                            memory (col, row).shptype := 0
                        end if
                    end for
                end for
            elsif ord (ch) = 208 then % down
                for col : 1 .. 13
                    for row : 1 .. 9
                        coldecdown
                        if memory (col, row).shptype = 1 and row > 1 then
                            memory (col, row - 1).shptype := 1
                            memory (col, row).shptype := 0
                        end if
                    end for
                end for
            end if
        end if
        BLACKBOXXX
        %changepol
        drawship

    end loop
end moveship


Sometime my ship will be right next to the enemy ship and when I "collide " with the ship everything works properly.  However, most of the time I'll be two "squares" (the ships are drawn based on the numbers in the array) away and mu ship will have "collided".  

Any help would doubleplusappriciated!    :D

-----------------------------------
Cervantes
Sat Jan 22, 2005 6:53 pm


-----------------------------------
Welcome to CompSci.ca.  :)
The first thing I can think of is that you're using procedures for your collision detection rather than functions.  
Let's take an example: coldecup.  See, when you use procedures, and have them set up like that, it's really only checking if memory (13,8 ).shptype = 1 and memory (13, 9) = 2.  The reason is that regardless of what happens before in the for loops, crash is reset to false.  Then, when col = 13 and row = 8, it checks if there's a collision.  You could overcome this by not using those two for loops and just checking at (shipRow, shipCol + 1) to see if there's an enemy ship there.  Even if you do this, you should still be using a function (that returns a boolean variable).

Second, don't use processes.  In Turing, they suck.
-Cervantes

-----------------------------------
Unreal_Origin
Sat Jan 22, 2005 6:55 pm

hey just post all of your code
-----------------------------------
i would suggest


your ship  should has a var for its top right (x2, y2) coordinate and top left (x1, y2)

also you should have bottom left  and bottom right of your the enemy (e_x1, e_y1) and the bottom left  (e_x2,e_y1) 

have an if statement that if the y coordinates of the enemies is in the area of the players ship 

THIS IS BLIND PROGRAMING

if e_y1> y2 and e_y1< y1 then 
    if e_x1> x1 and e_x1=< x2 or e_x1=> x1 and e_x2< x2  then % it may need to be 