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

Username:   Password: 
 RegisterRegister   
 How to Make Pacman continue moving
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Boiq




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
S_Grimm




PostPosted: 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.
Turing:

xvelocity := 1 %direction variable for x
procedure input
if Input.Keydown = RIGHT ARROW KEY then
moveright := true %boolean variable
end if

%more code for down left and up keys
%
%

end input


procedure movement
if moveright = true and moveleft = false then
pacmanx := pacmanx + xvelocity
elsif moveright = false and moveleft = true then
pacmanx := pacmanx - xvelocity
end if
end movement


This is very rough, don't copy and paste it into your code.
isaiahk9




PostPosted: 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.
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  [ 3 Posts ]
Jump to:   


Style:  
Search: