Discuss Scratch

IORDANISL
Scratcher
2 posts

Scratch game pacman

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

Last edited by IORDANISL (March 25, 2024 23:17:09)

GUYWHOLOVESCODE
Scratcher
100+ posts

Scratch game pacman

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.

For the love of everything, please snip quotes down to only the part you're responding to, it's painful to read excessively nested quotes.
Hey, I'm actually active in the forums again! Woo!
If a post is too long for you to read, link it on my profile and I'll do my best to paraphrase.
I have a pretty “3D” project
Scratch-Minion
Scratcher
1000+ posts

Scratch game pacman

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.
IORDANISL
Scratcher
2 posts

Scratch game pacman

Scratch-Minion wrote:

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.

Thank you. This has solved the touching issue with 2 keys at the same time. I did a couple of tests and passing the blue line never occurred even in stage 2

Last edited by IORDANISL (April 4, 2024 18:44:58)

Powered by DjangoBB