Scratch game pacman

id: 750233

category: Help with Scripts

posts: 3

IORDANISL IORDANISL loading
Hello everyone. I have made a pac-man game for my project and I have noticed that even if i have a code which prevents pac-man from moving past the blue line sometimes it glitches and gets stuck on it. This happens always when i press 2 keys at the same time e.g a+w or up arrow key + right arrow key. At stage 2 this some times happens without pressing 2 keys together. Another thing that I have noticed is that some times if pac-man eats a dot and losses at the same time the counter of dots eaten doesn't change accordingly and the game cannot end as I have put it to end when the dots counter reaches the Dots_number. Any advice? Here is the link to my project:

https://scratch.mit.edu/projects/964844021
This would probably go in the help with scripts forum where people there are used to helping out with this kind of thing. Don't worry about making a new thread, there is a way to move topics between subforums.
Here is an idea what causes the first of the problems that you describe and a possible solution:

The error you described with holding two keys down at once occurs when the first key moves Pacman onto a blue area, then the direction changes for moving with the second key. Moving -6 then moves -6 relative to the second key direction, not the direction of the first key which actually moved onto the blue area.


One solution:

In the Pacman sprite, you could change the code in the 4 custom blocks (My Blocks) like “MoveLeft” as follows:

define MoveLeft
point in direction (-90)
move (5) steps
if <touching color [#0000ff] ?> then
move (-5) steps
end

Then remove the code “move -6 steps” from the end of your forever loop.