Pacman Ghosts Movement
Author |
Message |
Draconis
|
Posted: Sun Jun 14, 2009 4:21 pm Post subject: Pacman Ghosts Movement |
|
|
What is it you are trying to achieve?
I am trying to get the ghosts to move by themselves as they are supposed to in Pacman.
What is the problem you are having?
The problem is that I can't get the ghosts to move properly. The ghosts are supposed to move on their without any help and I'm not sure how to implement that.
Describe what you have tried to solve this problem
I tried random integers etc. but I didn't really get anywhere. I made it so that whenever the ghost hit a wall, it would choose another direction, but the ghost is tight with the wall, meaning it's almost always touching a wall while moving. Therefore, it chooses a new direction when it shouldn't...
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
The code is the following, this is not the whole game though, just the part that includes the ghosts.
Turing: |
%Blinky's Movement
if ((whatdotcolor (g1x, g1y + 14) = brightblue or whatdotcolor (g1x + 13, g1y + 14) = brightblue or whatdotcolor (g1x - 13, g1y + 14) = brightblue) or (whatdotcolor (g1x, g1y - 14) = brightblue or whatdotcolor (g1x + 13, g1y - 14) = brightblue or whatdotcolor (g1x - 13, g1y - 14) = brightblue or whatdotcolor (g1x, g1y - 14) = white or whatdotcolor (g1x + 13, g1y - 14) = white or whatdotcolor (g1x - 13, g1y - 14) = white) or (whatdotcolor (g1x + 14, g1y ) = brightblue or whatdotcolor (g1x + 14, g1y + 13) = brightblue or whatdotcolor (g1x + 14, g1y - 13) = brightblue) or (whatdotcolor (g1x - 14, g1y ) = brightblue or whatdotcolor (g1x - 14, g1y + 13) = brightblue or whatdotcolor (g1x - 14, g1y - 13) = brightblue)) then
%the only reason this code should take place is if the ghost hits a wall or is at an intersection
if whatdotcolor (g1x, g1y + 14) not= brightblue and whatdotcolor (g1x + 13, g1y + 14) not= brightblue and whatdotcolor (g1x - 13, g1y + 14) not= brightblue then
up1 := true
end if
if whatdotcolor (g1x, g1y - 14) not= brightblue and whatdotcolor (g1x + 13, g1y - 14) not= brightblue and whatdotcolor (g1x - 13, g1y - 14) not= brightblue and whatdotcolor (g1x, g1y - 14) not= white and whatdotcolor (g1x + 13, g1y - 14) not= white and whatdotcolor (g1x - 13, g1y - 14) not= white then
down1 := true
end if
if whatdotcolor (g1x + 14, g1y ) not= brightblue and whatdotcolor (g1x + 14, g1y + 13) not= brightblue and whatdotcolor (g1x + 14, g1y - 13) not= brightblue then
right1 := true
end if
if whatdotcolor (g1x - 14, g1y ) not= brightblue and whatdotcolor (g1x - 14, g1y + 13) not= brightblue and whatdotcolor (g1x - 14, g1y - 13) not= brightblue then
left1 := true
end if
end if
if ((whatdotcolor (g1x, g1y + 14) = brightblue or whatdotcolor (g1x + 13, g1y + 14) = brightblue or whatdotcolor (g1x - 13, g1y + 14) = brightblue) or (whatdotcolor (g1x, g1y - 14) = brightblue or whatdotcolor (g1x + 13, g1y - 14) = brightblue or whatdotcolor (g1x - 13, g1y - 14) = brightblue or whatdotcolor (g1x, g1y - 14) = white or whatdotcolor (g1x + 13, g1y - 14) = white or whatdotcolor (g1x - 13, g1y - 14) = white) or (whatdotcolor (g1x + 14, g1y ) = brightblue or whatdotcolor (g1x + 14, g1y + 13) = brightblue or whatdotcolor (g1x + 14, g1y - 13) = brightblue) or (whatdotcolor (g1x - 14, g1y ) = brightblue or whatdotcolor (g1x - 14, g1y + 13) = brightblue or whatdotcolor (g1x - 14, g1y - 13) = brightblue)) then
randint (i, 1, 4)
end if
if i = 1 then
if up1 = true and whatdotcolor (g1x, g1y + 14) not= brightblue and whatdotcolor (g1x + 13, g1y + 14) not= brightblue and whatdotcolor (g1x - 13, g1y + 14) not= brightblue then
g1y := g1y + 1
end if
end if
if i = 2 then
if down1 = true and whatdotcolor (g1x, g1y - 14) not= brightblue and whatdotcolor (g1x + 13, g1y - 14) not= brightblue and whatdotcolor (g1x - 13, g1y - 14) not= brightblue and whatdotcolor (g1x, g1y - 14) not= white and whatdotcolor (g1x + 13, g1y - 14) not= white and whatdotcolor (g1x - 13, g1y - 14) not= white then
g1y := g1y - 1
end if
end if
if i = 3 then
if left1 = true and whatdotcolor (g1x - 14, g1y ) not= brightblue and whatdotcolor (g1x - 14, g1y + 13) not= brightblue and whatdotcolor (g1x - 14, g1y - 13) not= brightblue then
g1x := g1x - 1
end if
end if
if i = 4 then
if right1 = true and whatdotcolor (g1x + 14, g1y ) not= brightblue and whatdotcolor (g1x + 14, g1y + 13) not= brightblue and whatdotcolor (g1x + 14, g1y - 13) not= brightblue then
g1x := g1x + 1
end if
end if
%Ghost #1 (Blinky)
Draw.FillOval (g1x, g1y, 13, 13, 40)
%Right Eye
Draw.FillOval (g1x + 5, g1y + 4, 4, 4, white)
Draw.FillOval (g1x + 5, g1y + 4, 2, 2, black)
%Left Eye
Draw.FillOval (g1x - 5, g1y + 4, 4, 4, white)
Draw.FillOval (g1x - 5, g1y + 4, 2, 2, black)
delay (4)
Draw.FillOval (g1x, g1y, 13, 13, black)
|
Please specify what version of Turing you are using
Turing for Windows
4.0.3
Any ideas would be greatly appreciated because it is actually due rather soon, tomorrow actually... thanks a lot for your help! =] |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Montyman77
|
Posted: Sun Jun 14, 2009 5:29 pm Post subject: RE:Pacman Ghosts Movement |
|
|
I'm having the same problem |
|
|
|
|
|
|
|