Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help With My PacMan Game
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
helpmesodesperate




PostPosted: Mon Feb 20, 2006 11:04 pm   Post subject: Help With My PacMan Game

This is due in the morning, I've tried so many things to make the pill appear randomly and I just cant do anymore. I'm done. I want to go to sleep Ive been sitting here for 6 hours straight. Please help. The pill needs to appear randomly on the left side, then u eat it, then left side, then u eat it etc. and i wanted the backround to be black but whatever. Thanks. I will give you my soul for this.

code:

colourback (green)
cls
var font : int
font := Font.New ("times:48")
var key : string (1)
var midx, midy : int
midx := maxx div 2
midy := maxy div 2
var x, y : int                % x and y of Pacman's centre
x := midx
y := midy
var dx, dy : int                        % direction Pacman moves
dx := 0                                % Pacman will move to the right
dy := 0                                 % Pacman will not be going up or
var mouth : int := 0                    % size of mouth
var dir : int := 0                      % mouth direction, 0=right, 90=up,
var px, py : int
var input : char
const r : int := 5


%drawfillbox (0, 0, maxx, maxy, 16)
drawbox (0, 0, maxx, maxy, red)          % draws border around outside of screen


drawfillbox (midx - 10, 0, midx + 10, midy - 40, red)    % draws barrier at bottom of screen
drawfillbox (midx - 10, midy + 40, midx + 10, maxy, red) % draws barrier attop of screen





loop

    randint (px, 0, maxx)
    randint (py, 0, maxy)
    drawfilloval (px, py, r, r, blue)

    loop

    exit when x
   
        %----------------------------------------------------------------------------------------
       
        if dir = 0 then

            if whatdotcolour (x + 22, y) = red then
                dx := 0
                x := x - 1
            end if

            if whatdotcolour (x + 22, y + 22) = red or whatdotcolour (x + 22, y - 22) = red then
                dx := 0
                x := x - 1
            end if

        end if
        %----------------------------------------------------------------------------------------
        if dir = 90 then

            if whatdotcolour (x, y + 22) = red then
                dy := 0
                y := y - 1
            end if

            if whatdotcolour (x + 22, y + 22) = red or whatdotcolour (x - 22, y + 22) = red then
                dy := 0
                y := y - 1
            end if

        end if
        %------------------------------------------------------------------------------------------
        if dir = 180 then

            if whatdotcolour (x - 22, y) = red then
                dx := 0
                x := x + 1
            end if

            if whatdotcolour (x - 22, y + 22) = red or whatdotcolour (x - 22, y - 22) = red then
                dx := 0
                x := x + 1
            end if

        end if
        %-------------------------------------------------------------------------------------------
        if dir = 270 then
            if whatdotcolour (x, y - 22) = red then
                dy := 0
                y := y + 1
            end if
            if whatdotcolour (x + 22, y - 22) = red or whatdotcolour (x - 22, y - 22) = red then
                dy := 0
                y := y + 1
            end if
        end if
        %-------------------------------------------------------------------------------------------
        if x > maxx - 22 then
            dx := 0
        end if

        if y > maxy - 22 then
            dy := 0
        end if

        if x < 22 then
            dx := 0
        end if

        if y < 22 then
            dy := 0
        end if
        %-------------------------------------------------------------------------------------------
        if hasch then
            getch (key)


            if ord (key) = 205 then
                dx := 2
                dy := 0
                dir := 0

                if whatdotcolour (x + 22, y) = red then
                    dx := 0
                    x := x - 1
                end if

                if whatdotcolour (x + 22, y + 22) = red or whatdotcolour (x + 22, y - 22) = red then
                    dx := 0
                    x := x - 1
                end if

                if x > maxx - 22 then
                    dx := 0
                end if
                %-------------------------------------------------------------------------------------------
            elsif ord (key) = 200 then
                dx := 0
                dy := 2
                dir := 90

                if whatdotcolour (x, y + 22) = red then
                    dy := 0
                    y := y - 1
                end if

                if whatdotcolour (x + 22, y + 22) = red or whatdotcolour (x - 22, y + 22) = red then
                    dy := 0
                    y := y - 1
                end if


                if y > maxy - 22 then
                    dy := 0
                end if
                %-------------------------------------------------------------------------------------------
            elsif ord (key) = 203 then

                dx := -2
                dy := 0
                dir := 180

                if whatdotcolour (x - 22, y) = red then
                    dx := 0
                    x := x + 1
                end if

                if whatdotcolour (x - 22, y + 22) = red or whatdotcolour (x - 22, y - 22) = red then
                    dx := 0
                    x := x + 1
                end if

                if x < 22 then
                    dx := 0
                end if
                %-------------------------------------------------------------------------------------------
            elsif ord (key) = 208 then

                dx := 0
                dy := -2
                dir := 270

                if whatdotcolour (x, y - 22) = red then
                    dy := 0
                    y := y + 1
                end if
                if whatdotcolour (x + 22, y - 22) = red or whatdotcolour (x - 22, y - 22) = red then
                    dy := 0
                    y := y + 1
                end if

                if y < 22 then
                    dy := 0
                end if
                %-------------------------------------------------------------------------------------------
            end if

        end if

        mouth := mouth mod 45 + 1               % change size of the mouth
        drawfillarc (x, y, 20, 20, mouth + dir, -mouth + dir, yellow)
        delay (10)
        drawfillarc (x, y, 20, 20, mouth + dir, -mouth + dir, white)
        x := x + dx                            % move Pacman's centre,
        y := y + dy                            % the values of dx and dy

    end loop
    return

end loop



pacman.t
 Description:

Download
 Filename:  pacman.t
 Filesize:  4.9 KB
 Downloaded:  115 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Mon Feb 20, 2006 11:34 pm   Post subject: (No subject)

Please don't post titles in ALL CAPS again. It's very aggrevating. And learn to use your tags properly. I appreciate your trying to use them (more than what most people do), but really, they're not that difficult.

First off:
code:

    if whatdotcolour (x, y) not= 0 then
        loop
            randint (px, 0, maxx)
            randint (py, 0, maxy)
            drawfilloval (px, py, r, r, blue)
        end loop
    end if

is an infinite loop. It never exits, so your screen will always get filled with the blue circles once the initial condition is met.
That being said, I'm not sure at all what the meaning of that condition is. From the layout of your screen, it's always going to be true. Which is not good.

For this to work correctly, here's what you'll have to do:
- initially set a position for the 'pill'. I'm guessing this is px and py.
- draw your background, obstacles, character, and pill.
- initiate movement checking (your getch() clauses) and get the character moving.
- compare the character's position to px and py. When they coincide, the pill will be effectively 'eaten', and redraw it elsewhere (by resetting the values of px and py to different values). You will probably be using whatdotcolour() for this, since that's what you've been going with all this time. Personally, I'd prefer a mathematical approach, but something tells me you don't have the time to figure that one out.
You probably won't have to manually clear the blue oval, since the character moving over it will do that for you - makes your life easier.

code:

    drawfillarc (x, y, 20, 20, mouth + dir, -mouth + dir, yellow)
    delay (10)
    drawfillarc (x, y, 20, 20, mouth + dir, -mouth + dir, white)

Why are you clearing the PacMan with the colour 'white' when your background is 'green'?
Also, ever heard of View.Update()? It will make your animation smoother.
This Tut will give you the basics on it.
Isaac




PostPosted: Mon Feb 20, 2006 11:47 pm   Post subject: (No subject)

Here is something you can work with. What I'd suggest you do is just have an condition statement checking if the x,y of the pacman is on top of the dot. When it is, have make it generate a random x and y coordinate and draw it. Make sure that is in your loop, and it should go on forever and ever. Good luck.

code:
setscreen ("graphics:maxx;maxy")
var xtotal, xcount, ytotal, ycount : int := 250
var x1, mouth, y1, xa, ya, button : int := 0
var key : array char of boolean
var right, left, up, down : boolean := false

loop
    Mouse.Where (xa, ya, button)
    Input.KeyDown (key)
    mouth += 1
    if button = 1 then
        if xa >= 50 and xa <= 110 and ya >= 360 and ya <= 395 then
            for m : 1 .. 5
                Draw.FillArc (xtotal + x1, ycount + y1, 15, 15, 30 - m * 6, 300 + m * 12, 77)
                delay (55)
                Draw.FillArc (xtotal + x1, ycount + y1, 15, 15, 0, 360, white)
                Draw.FillArc (xtotal + x1, ycount + y1, 15, 15, 30 - m * 6, 300 + m * 12, 77)
            end for
        end if
    end if
    if right = true then
        Draw.FillArc (xtotal + x1, ycount + y1, 15, 15, 30 - mouth * 6, 300 + mouth * 12, 77)
    elsif right = false and left = true then
        Draw.FillArc (xtotal + x1, ycount + y1, 15, 15, 180 + mouth * 6, 180 - mouth * 5, 77)
    elsif right = false and left = false and down = false and up = true then
        Draw.FillArc (xtotal + x1, ycount + y1, 15, 15, 145 - mouth * 6, 360 + mouth * 12, 77)
    elsif right = false and left = false and down = true and up = false then
        Draw.FillArc (xtotal + x1, ycount + y1, 15, 15, 285 + mouth * 5, 190 + mouth * 12, 77)
    end if
    delay (55)
    if key (KEY_RIGHT_ARROW) and xcount + 15 < maxx then
        Draw.FillArc (xtotal + x1, ycount + y1, 16, 16, 0, 360, white)
        x1 += 5
        xcount += 5
        up := false
        down := false
        right := true
        left := false
    elsif key (KEY_LEFT_ARROW) and xcount - 12 > 5 then
        Draw.FillArc (xtotal + x1, ycount + y1, 16, 16, 0, 360, white)
        x1 -= 5
        xcount -= 5
        up := false
        down := false
        right := false
        left := true
    elsif key (KEY_UP_ARROW) and ycount + 15 < maxy - 90 then
        Draw.FillArc (xtotal + x1, ycount + y1, 16, 16, 0, 360, white)
        y1 += 5
        ycount += 5
        up := true
        down := false
        right := false
        left := false
    elsif key (KEY_DOWN_ARROW) and ycount - 12 > 124 then
        Draw.FillArc (xtotal + x1, ycount + y1, 16, 16, 0, 360, white)
        y1 -= 5
        ycount -= 5
        up := false
        down := true
        right := false
        left := false
    end if
    if mouth = 5 then
        Draw.FillArc (xtotal + x1, ycount + y1, 15, 15, 0, 360, 77)
        mouth := 0
    end if
end loop
chrispminis




PostPosted: Sun Feb 26, 2006 11:55 pm   Post subject: (No subject)

What school are you attending? because I have this exact assignment.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: