
-----------------------------------
adamlover
Thu May 30, 2013 7:12 pm

Circular Collision Detection- HELP!
-----------------------------------
Hi all, this is my first ever question, so bare with me.

For my ISU, I'm making a game where the user moves around the screen, collecting stars and avoiding enemies. These circular enemies will kill the circular user. My issue is with detecting collision. 

The enemies are not random, but they do move across the screen using "for" statements; the user moves with the keyboard arrows. I'm using processes and the distance formula and radii, but for some reason, the distance between the two circles is not recognized, so the program won't "GAME OVER". Any help/advice/suggestions are beyond greatly appreciated. Thanks-


[code]

var answer : string (1)
var down : string := chr (208)
var up : string := chr (200)
var left : string := chr (203)
var right : string := chr (205)

var userxlocation : int := maxx div 2
var userylocation : int := maxy div 2

var foo : int := 0


process user
    loop
        drawfilloval (userxlocation, userylocation, 20, 20, 48)     %draw user
        getch (answer)
        if answer = up then     %arrow key moves up
            userylocation := userylocation + 18
            if userylocation > maxy - 18 then
                userylocation := maxy - 18
            end if
        elsif answer = down then     %arrow key moves down
            userylocation := userylocation - 18
            if userylocation < 18 then
                userylocation := 18
            end if
        elsif answer = left then     %arrow key moves left
            userxlocation := userxlocation - 18
            if userxlocation < 18 then
                userxlocation := 18
            end if
        elsif answer = right then     %arrow key moves right
            userxlocation := userxlocation + 18
            if userxlocation > maxx - 18 then
                userxlocation := maxx - 18
            end if
        end if
        delay (10)
        cls
        drawfilloval (userxlocation, userylocation, 20, 20, 48)     %redraw
    end loop
end user


process enemy1
    for i : 1 .. maxx
        drawfilloval (100 + i, 100, 60, 60, blue)
        delay (1)
        drawfilloval (100 + i, 100, 60, 60, black)
    end for
    cls
    for decreasing i : maxx .. 1
        drawfilloval (100 + i, 100, 60, 60, blue)
        delay (1)
        drawfilloval (100 + i, 100, 60, 60, black)
        foo := i
    end for
end enemy1


setscreen ("graphics:max;max,nobuttonbar")
View.Set ("position:0;0")

colourback (black)
cls
View.Update


loop
    cls
    View.Update
    fork user
    delay (1020)
    fork enemy1
    delay (1060)
    fork user
    delay (1750)
    View.Update
      
    %40 is the radii of both circles added together
    if sqrt ((userxlocation - (100 + foo)) ** 2 + (userylocation - 100) ** 2) 