
-----------------------------------
xHoly-Divinity
Mon Jan 17, 2005 8:12 pm

shooter game -- checking colisions
-----------------------------------
I am not sure if this attatchment will successfully attatch. If it does you can see that I have all the characters, the target, and the explosion after you shoot. If you cannot, I will post a copy of the code so perhaps you can sort of make it out (there are picture attatchments, so this is why just the source code will not work). Anyhow, my problem is I don't know how to check it a person has been shot or not. Because this is a sophisticated .bmp image with uneven edges/shapes, I can't really use Math.Distance. If I use whatdotcolour, there would be at least 200 different checks that I would have to conduct. I've tried using a check to see for whatdotcolor if it doesn't match any of the bg colors but this too is a lot of code and some bg colours appear in the .bmp images. Help needed! Thanks!


setscreen ("offscreenonly")
var x, y, button, a, b : int
x := 350
y := 50
var bullet : int := 30
var score : int := 0
var p1, q1, p2, q2, p3, q3, p4, q4, bin, bush, kerry : int
p1 := 100
q1 := 200
p2 := 360
q2 := 160
p3 := 600
q3 := 100
var who : int

bin := Pic.FileNew ("C:/Pics/bin.bmp")
bush := Pic.FileNew ("C:/Pics/bush.bmp")
kerry := Pic.FileNew ("C:/Pics/kerry.bmp")
Pic.SetTransparentColor (bin, brightred)
Pic.SetTransparentColor (bush, brightred)
Pic.SetTransparentColor (kerry, brightred)

proc target
    drawoval (x, y, 30, 30, brightred)
    drawline (x, y + 40, x, y - 40, brightred)
    drawline (x + 40, y, x - 40, y, brightred)
end target

proc erase_target
    drawoval (x, y, 30, 30, white)
    drawline (x, y + 40, x, y - 40, white)
    drawline (x + 40, y, x - 40, y, white)
end erase_target

proc bg
    %ground
    drawline (0, 275, maxx, 275, black)
    %left box
    drawfillbox (100, 200, 250, 320, brown)
    drawbox (100, 200, 250, 320, black)
    %right box
    drawfillbox (200, 150, 350, 250, brown)
    drawbox (200, 150, 350, 250, black)
    %cylinder
    drawline (355, 160, 355, 280, black)
    drawline (465, 160, 465, 280, black)
    drawfilloval (410, 280, 55, 10, black)
    drawarc (411, 161, 55, 10, 180, 0, black)
    drawfill (370, 200, red, black)
    drawfill (356, 276, red, black)
    drawfill (464, 276, red, black)
    drawfilloval (410, 210, 30, 30, 1)
    %           left tri
    drawline (410, 210, 380, 210, black)
    drawline (410, 210, 395, 185, black)
    drawline (380, 210, 395, 185, black)
    %           right tri
    drawline (410, 210, 440, 210, black)
    drawline (410, 210, 425, 185, black)
    drawline (440, 210, 425, 185, black)
    %           top tri
    drawline (395, 236, 425, 236, black)
    drawline (395, 236, 410, 210, black)
    drawline (425, 236, 410, 210, black)
    drawfill (395, 205, yellow, black)
    drawfill (408, 231, yellow, black)
    drawfill (423, 203, yellow, black)
    %           dump
    drawfillbox (maxx - 50, 100, maxx, 350, 3)
    drawbox (maxx - 50, 100, maxx, 350, black)
end bg

proc shoot (a, b : int)
    drawline (215 + a, 103 + b, 200 + a, 110 + b, 41)
    drawline (200 + a, 110 + b, 207 + a, 96 + b, 41)
    drawline (207 + a, 96 + b, 201 + a, 87 + b, 41)
    drawline (201 + a, 87 + b, 214 + a, 92 + b, 41)
    drawline (214 + a, 92 + b, 218 + a, 75 + b, 41)
    drawline (218 + a, 75 + b, 223 + a, 89 + b, 41)
    drawline (223 + a, 89 + b, 234 + a, 85 + b, 41)
    drawline (234 + a, 85 + b, 227 + a, 96 + b, 41)
    drawline (227 + a, 96 + b, 234 + a, 104 + b, 41)
    drawline (234 + a, 104 + b, 224 + a, 101 + b, 41)
    drawline (215 + a, 103 + b, 219 + a, 115 + b, 41)
    drawline (219 + a, 115 + b, 224 + a, 101 + b, 41)
    drawfill (218 + a, 96 + b, yellow, 41)
end shoot

proc erase_shoot (a, b : int)
    drawfilloval (219 + a, 95 + b, 25, 25, white)
end erase_shoot

proc main
    locatexy (10, maxy - 10)
    put score
    erase_target
    mousewhere (x, y, button)
    a := x - 215
    b := y - 100
    delay (10)
    Pic.Draw (bin, p1, q1, picCopy)
    Pic.Draw (bush, p2, q2, picCopy)
    Pic.Draw (kerry, p3, q3, picCopy)
    bg
    if button = 1 then
        shoot (a, b)
        target
        View.Update
        delay (100)
        erase_shoot (a, b)
        Pic.Draw (bin, p1, q1, picCopy)
        Pic.Draw (bush, p2, q2, picCopy)
        Pic.Draw (kerry, p3, q3, picCopy)
        bg
        View.Update
    end if
    target
    View.Update
end main

loop
    randint (who, 1, 4)
    if who = 1 then
        loop
            if q1  302 then
                drawfillbox (p1, q1 - 2, 240, q1 + 175, white)
                q1 := 200
                exit
            end if
        end loop
    elsif who = 2 then
        loop
            if q2  275 then
                drawfillbox (p2, q2 - 2, p2 + 100, q2 + 150, white)
                q2 := 160
                exit
            end if
        end loop
    elsif who = 3 then
        loop
            if p3 