Computer Science Canada How to Make Pacman continue moving |
Author: | Boiq [ Thu Sep 25, 2008 10:50 am ] |
Post subject: | How to Make Pacman continue moving |
Hey all, i'm currently working on a Pacman program and I ran into a little problem. Here is the current code that someone helped me out with already: View.Set ("offscreenonly") colourback (16) var chars : array char of boolean var x, y : int var pacstate : boolean x := 120 y := 120 pacstate := true loop Input.KeyDown (chars) if chars (KEY_RIGHT_ARROW) then if pacstate = true then drawfilloval (x, y, 20, 20, yellow) x := x + 5 pacstate := false else drawfilloval (x, y, 20, 20, yellow) drawfillarc (x, y, 20, 20, 310, 40, white) x := x + 5 pacstate := true end if elsif chars (KEY_LEFT_ARROW) then if pacstate = true then drawfilloval (x, y, 20, 20, yellow) x := x - 5 pacstate := false else drawfilloval (x, y, 20, 20, yellow) drawfillarc (x, y, 20, 20, 130, 210, white) x := x - 5 pacstate := true end if elsif chars (KEY_DOWN_ARROW) then if pacstate = true then drawfilloval (x, y, 20, 20, yellow) y := y - 5 pacstate := false else drawfilloval (x, y, 20, 20, yellow) drawfillarc (x, y, 20, 20, 230, 310, white) y := y - 5 pacstate := true end if elsif chars (KEY_UP_ARROW) then if pacstate = true then drawfilloval (x, y, 20, 20, yellow) y := y + 5 pacstate := false else drawfilloval (x, y, 20, 20, yellow) drawfillarc (x, y, 20, 20, 70, 120, white) y := y + 5 pacstate := true end if else drawfilloval (x, y, 20, 20, yellow) end if View.UpdateArea (x - 45, y - 45, x + 45, y + 45) drawfilloval (x, y, 45, 45, white) delay (120) end loop The problem is, when you move him in any dirrection you have to hold the arrow key for him to keep moving, while in pacman you are supposed to click the dirrection and he keeps moving that way without holding the key or stopping. How would I be able to make this possible by adding on to the current code that I have above? All help would be appreciated, thanks. |
Author: | S_Grimm [ Thu Sep 25, 2008 11:34 am ] | ||
Post subject: | Re: How to Make Pacman continue moving | ||
just do a velocity statement. assign a variable for each direction (x and y) and a boolean statement for each arrow.
This is very rough, don't copy and paste it into your code. |
Author: | isaiahk9 [ Wed Oct 08, 2008 5:15 pm ] |
Post subject: | RE:How to Make Pacman continue moving |
This may be annoying to the creator of this thread, looking for answers, but there are dozens of help topics and submissions in Turing for Pacman Games. I'm sure other categories could solve your problems alot faster than creating a brand new thread could. |