
-----------------------------------
Pacman
Fri Nov 24, 2006 1:35 am

Not Understanding Colission
-----------------------------------
I read tutorials etc and im still not understanding the whole colision/detection thing. A little help would be much appreciated, I need my Pacman (the one that chomps and move with arrows keys) to not just run over the dots and leave a black streak behind but to also detect he has and give 10 points or w/e for each, just a little explanation would be perfect. He is the code so far, i dont have all of the dots put in, just a few, i can make the rest later.


setscreen ("graphics:490;540,nobuttonbar") 
View.Update 
colorback (black) 
cls 
color (white) 
%Normal For Game/Maze 
const backgrnd : int := black 
const pacrad : int := 11 
const wall : int := 30 
const room : int := 4 
var direction : int := 360 
var x : int := 245 
var y : int := 230 
var x_temp, y_temp : int := 0 
var xInc, yInc : int := 0 
var mouthangl : int := 0 
var move : string (1) := KEY_RIGHT_ARROW 
const DEL : int := 15 
%Controls Font 
var font1 : int 
font1 := Font.New ("arial:15") 
%Created By Font 
var font2 : int 
font2 := Font.New ("arial:8") 

%Copy, At Beginning ------------ 
const backgrnd2 : int := black 
const pacrad2 : int := 11 
var direction2 : int := 360 
var x2 : int := 245 
var y2 : int := 230 
var x_temp2, y_temp2 : int := 0 
var xInc2, yInc2 : int := 0 
var mouthangl2 : int := 0 



%GAME PROCEDURES---------------------------------------------- 
procedure walls 
    colourback (backgrnd) 
    cls 
    %Draw Walls 
    var box1x : array 1 .. 49 of int := init (0, 0, 0, 490, 0, 480, 50, 140, 190, 240, 290, 340, 0, 440, 50, 90, 140, 290, 390, 390, 0, 90, 0, 140, 190, 240, 340, 390, 390, 400, 0, 90, 0, 390, 390, 
        390, 
        140, 340, 140, 290, 50, 390, 190, 240, 50, 140, 290, 390, 240) 
    var box1y : array 1 .. 49 of int := init (0, 0, 530, 260, 300, 300, 50, 50, 100, 100, 50, 60, 100, 100, 150, 160, 160, 160, 160, 160, 210, 260, 260, 260, 210, 210, 260, 260, 260, 200, 300, 360, 
        350, 
        350, 300, 300, 300, 300, 350, 350, 400, 400, 400, 410, 450, 450, 450, 450, 450) 
    var box2x : array 1 .. 49 of int := init (10, 490, 490, 480, 10, 490, 200, 150, 300, 250, 440, 350, 50, 490, 100, 100, 200, 350, 400, 440, 100, 100, 90, 150, 300, 250, 350, 480, 400, 480, 100, 
        100, 
        100, 480, 480, 400, 150, 350, 200, 350, 100, 440, 300, 250, 100, 200, 350, 440, 250) 
    var box2y : array 1 .. 49 of int := init (260, 10, 540, 0, 540, 540, 60, 110, 110, 50, 60, 110, 110, 110, 160, 100, 150, 150, 100, 150, 200, 200, 250, 200, 200, 150, 200, 250, 200, 210, 310, 310, 
        360, 360, 310, 360, 410, 410, 360, 360, 410, 410, 410, 350, 490, 490, 490, 490, 540) 

    for i : 1 .. 49 
        drawfillbox (box1x (i), box1y (i), box2x (i), box2y (i), brightblue) 
    end for 
    for i : 45 .. 48 
        drawfillbox (box1x (i) + 10, box1y (i) + 10, box2x (i) - 10, box2y (i) - 10, black) 
    end for 
end walls 

%Mouth Opening and closing.... 

%Draw mouth close 
procedure drawMouthClose (x : int, y : int) 
    mouthangl := mouthangl mod 45 + 1 
    drawfillarc (x, y, pacrad, pacrad, mouthangl + direction, -mouthangl + direction, 14) 
end drawMouthClose 



%Erase Pacman 
procedure erasePacman (x : int, y : int) 
    drawfillarc (x, y, pacrad, pacrad, mouthangl + direction, -mouthangl + direction, backgrnd) 
end erasePacman 

%Change Direction 
procedure directionChange 
    if hasch then 
        getch (move) 
        if ord (move) = ORD_DOWN_ARROW then 
            direction := 270 
            xInc := 0 
            yInc := -1 
        elsif ord (move) = ORD_UP_ARROW then 
            direction := 90 
            xInc := 0 
            yInc := 1 
        elsif ord (move) = ORD_LEFT_ARROW then 
            direction := 180 
            xInc := -1 
            yInc := 0 
        elsif ord (move) = ORD_RIGHT_ARROW then 
            direction := 0 
            xInc := 1 
            yInc := 0 

        end if 
    end if 
end directionChange 
%------------------------------------------------------------- 

% MUSIC/SOUNDS------------------------------------------------ 
procedure musicbegin 
    Music.PlayFile ("GAMEBEGINNING.wav") 
end musicbegin 
procedure soundchomp 
loop 
    Music.PlayFile ("pacchomp.wav") 
    end loop 
end soundchomp 
%------------------------------------------------------------- 


%Mouth Opening And Closing For The Main Menu (not working)----------------------------------- 
procedure drawMouthClose2 (x2 : int, y2 : int) 
    mouthangl2 := mouthangl2 mod 45 + 1 
    drawfillarc (x2, y2, pacrad2, pacrad2, mouthangl2 + direction2, -mouthangl2 + direction2, 14) 
end drawMouthClose2 

%Erase Pacman 
procedure erasePacman2 (x : int, y : int) 
    drawfillarc (x2, y2, pacrad2, pacrad2, mouthangl2 + direction2, -mouthangl2 + direction2, backgrnd2) 
end erasePacman2 

%Movement Mouth Speed 
const DEL2 : int := 8 

procedure paceat 
    loop 
        drawMouthClose2 (x2, y2) 
        delay (DEL2) 
        erasePacman2 (x2, y2) 
        x_temp2 := x2 + xInc2 
        y_temp2 := y2 + yInc2 
    end loop 
end paceat 

%Start Menu 
procedure gui12 
    %Background ----------------------- 
    const picesizeb : int := 20 

    var picb : int := Pic.FileNew ("the best pic ever.bmp") 
    var newPicb : int 
    var picWidthb, picHeightb : int 
    picWidthb := Pic.Width (picb) 
    picHeightb := Pic.Height (picb) 
    newPicb := Pic.Scale (picb, picWidthb div 1, picHeightb div 1) 
    Pic.Draw (newPicb, maxx div 2000 + 2, maxy div 1000 + 1, picCopy) 
    Pic.Free (newPicb) 

    % Start Button ------------------- 
    const picesize : int := 20 

    var pic : int := Pic.FileNew ("startgame.bmp") 
    var newPic : int 
    var picWidth, picHeight : int 
    picWidth := Pic.Width (pic) 
    picHeight := Pic.Height (pic) 
    newPic := Pic.Scale (pic, picWidth div .8, picHeight div .8) 
    Pic.Draw (newPic, maxx div 2.6 + 10, maxy div 5 + 60, picCopy) 
    Pic.Free (newPic) 

    % Controls Button -------------- 
    const picesize2 : int := 20 

    var pic2 : int := Pic.FileNew ("controls.bmp") 
    var newPic2 : int 
    var picWidth2, picHeight2 : int 
    picWidth2 := Pic.Width (pic2) 
    picHeight2 := Pic.Height (pic2) 
    newPic2 := Pic.Scale (pic2, picWidth2 div .8, picHeight2 div .8) 
    Pic.Draw (newPic2, maxx div 2.5 + 10, maxy div 5 + 30, picCopy) 
    Pic.Free (newPic2) 

    %Exit Button ---------------- 
    const picesize3 : int := 20 

    var pic3 : int := Pic.FileNew ("exit2.bmp") 
    var newPic3 : int 
    var picWidth3, picHeight3 : int 
    picWidth3 := Pic.Width (pic3) 
    picHeight3 := Pic.Height (pic3) 
    newPic3 := Pic.Scale (pic3, picWidth3 div .8, picHeight3 div .8) 
    Pic.Draw (newPic3, maxx div 2.32 + 10, maxy div 5 + 1, picCopy) 
    Pic.Free (newPic3) 

    Font.Draw ("Created By pacmaN & Sinergy", 290, 5, font2, brightred) 
end gui12 

var c, d, button, button2 : int 
gui12 

%Mainline 
loop 
    mousewhere (c, d, button) 
    if button = 1 and 200 = 168 then 
        cls 
        walls 
        musicbegin 
        walls 
        %Draws Dots-------------------------------------------------------- 
        %Draws Point Dots 
        for draw1 : 1 .. 15 
            drawfilloval (30 * draw1, 30, 5, 5, yellow) 
        end for 
        drawfilloval (30, 55, 5, 5, yellow) 
        drawfilloval (30, 80, 5, 5, yellow) 
        drawfilloval (60, 80, 5, 5, yellow) 
        drawfilloval (90, 80, 5, 5, yellow) 
        for draw2 : 3 .. 17 
            drawfilloval (120, 30 * draw2, 5, 5, yellow) 
        end for 
        drawfilloval (220, 55, 5, 5, yellow) 
        drawfilloval (220, 80, 5, 5, yellow) 
        drawfilloval (195, 80, 5, 5, yellow) 
        drawfilloval (170, 80, 5, 5, yellow) 
        drawfilloval (170, 105, 5, 5, yellow) 
        for draw3 : 5 .. 12 
            drawfilloval (30 * draw3, 130, 5, 5, yellow) 
        end for 

        %Draws Booster Dots 
        drawfilloval (30, 130, 10, 10, brightgreen) 
        drawfilloval (460, 130, 10, 10, brightgreen) 
        drawfilloval (460, 470, 10, 10, brightgreen) 
        drawfilloval (30, 470, 10, 10, brightgreen) 
        %----------------------------------------------------------------- 
        loop 
            drawMouthClose (x, y) 
            View.Update 
            delay (DEL) 
            erasePacman (x, y) 
            x_temp := x + xInc 
            y_temp := y + yInc 
            directionChange 
            if x_temp = 15 then 
                x := 475 
            elsif x_temp = 475 then 
                x := 15 
            end if 
            if whatdotcolor (x_temp + pacrad, y_temp) ~= brightblue 
                    and whatdotcolor (x_temp + pacrad + room, y_temp) ~= brightblue 
                    and whatdotcolor (x_temp - pacrad - room, y_temp) ~= brightblue 
                    and whatdotcolor (x_temp, y_temp + pacrad + room) ~= brightblue 
                    and whatdotcolor (x_temp, y_temp - pacrad - room) ~= brightblue 
                    and whatdotcolor (x_temp + pacrad + room, y_temp + pacrad + room) ~= brightblue 
                    and whatdotcolor (x_temp - pacrad - room, y_temp - pacrad - room) ~= brightblue 
                    and whatdotcolor (x_temp - pacrad - room, y_temp + pacrad + room) ~= brightblue 
                    and whatdotcolor (x_temp + pacrad + room, y_temp - pacrad - room) ~= brightblue 
                    and whatdotcolor (x_temp + pacrad, y_temp + pacrad + room) ~= brightblue 
                    and whatdotcolor (x_temp - pacrad, y_temp - pacrad - room) ~= brightblue 
                    and whatdotcolor (x_temp - pacrad, y_temp + pacrad + room) ~= brightblue 
                    and whatdotcolor (x_temp + pacrad, y_temp - pacrad - room) ~= brightblue 
                    and whatdotcolor (x_temp + pacrad + room, y_temp + pacrad) ~= brightblue 
                    and whatdotcolor (x_temp - pacrad - room, y_temp - pacrad) ~= brightblue 
                    and whatdotcolor (x_temp - pacrad - room, y_temp + pacrad) ~= brightblue 
                    and whatdotcolor (x_temp + pacrad + room, y_temp - pacrad) ~= brightblue 
                    then 
                x := x + xInc 
                y := y + yInc 
            end if 
        end loop 
        x := x + xInc 
        y := y + yInc 

    elsif button = 1 and 200 = 138 then 
        cls 
        Font.Draw ("Use Your Arrow Keys, Up Down Left Right,", 5, 400, font1, yellow) 
        Font.Draw ("Move Your Pacman To Eat All The Dots", 5, 370, font1, brightred) 
        Font.Draw ("Collect All Of The Dots And Move To The Next Level!", 5, 340, font1, yellow) 
        Font.Draw ("Collect Green Dots To Get A Booster Pac!", 5, 310, font1, brightred) 
        Font.Draw ("Back To Main", 5, 100, font1, brightred) 
        drawbox (1, 90, 140, 120, white) 
    end if 
    exit when button = 1 and 200 