Discuss Scratch

hawkfang57
Scratcher
7 posts

pac man ghost movement

hey peeps! hawkfang57 here. so… i'm making a pac man game that uses kingdom hearts characters. i'm so close to being done. i just need to do the heartless/ghosts movement scripts, and I need help doing that. any simple suggestions (not a lot of variables) about how to do it? thanks!

if you want to show me using the scrarchblocks, start it with this block. –>
whenIreceive selected

Last edited by hawkfang57 (Aug. 6, 2015 21:21:23)

BassIsSwaggin
Scratcher
48 posts

pac man ghost movement

https://scratch.mit.edu/projects/72482862/

Last edited by BassIsSwaggin (Aug. 7, 2015 00:41:03)

cvtest
Scratcher
9 posts

pac man ghost movement

Hi hawkfang57.

Pacman game usually is not built on base of Pacman sprite touching walls or not.
If you try a Pacman game from the net, you will see that the Pacman character never touches the walls (nor the AI's) :

See http://i58.tinypic.com/ay4wld.png

When the Pacman (or the AI's) sprite is in a horizontal corridor for instance, it never is closer to the upper wall or closer to the lower wall.
It's just in the middle and stays there.

In fact the characters always follow in invisible grid.
The walls are aligned on that grid as well. The dots and big dots to be eaten also are exactly at the intersections of the lines of the grid.

So, the game is based on characters moving from one intersection of the grid, to the next one (up, down, left or right).
The transition from one intersection to the other (an inteval) is done via a cycle of moves (that you can initially simplify as a Glide, but in more sophisticated versions the sprites's costume is cycling during such an inteval).

Greetz,
Dimitri.

hawkfang57
Scratcher
7 posts

pac man ghost movement

cvtest wrote:

Hi hawkfang57.

Pacman game usually is not built on base of Pacman sprite touching walls or not.
If you try a Pacman game from the net, you will see that the Pacman character never touches the walls (nor the AI's) :

See http://i58.tinypic.com/ay4wld.png

When the Pacman (or the AI's) sprite is in a horizontal corridor for instance, it never is closer to the upper wall or closer to the lower wall.
It's just in the middle and stays there.

In fact the characters always follow in invisible grid.
The walls are aligned on that grid as well. The dots and big dots to be eaten also are exactly at the intersections of the lines of the grid.

So, the game is based on characters moving from one intersection of the grid, to the next one (up, down, left or right).
The transition from one intersection to the other (an inteval) is done via a cycle of moves (that you can initially simplify as a Glide, but in more sophisticated versions the sprites's costume is cycling during such an inteval).

Greetz,
Dimitri.


so, I should try to use glide blocks?
dimitrip
Scratcher
500+ posts

pac man ghost movement

I think you should, yes, because creating a Pacman game where each x and y would be handled unit per unit (like in platformer's), will deceive you.
Glide solution is a first approach for moving from one grid intersection to the other. But when you'll be ready, you could enhance to a detailed approach of the cycle without too many difficulties.
When you will be ready with the grid concept, just think about this question :
If I don't use wall collision to handle moves, how will I enable Pacman or ghosts to go up, down, left or right ?
Greetz.
hawkfang57
Scratcher
7 posts

pac man ghost movement

dimitrip wrote:

I think you should, yes, because creating a Pacman game where each x and y would be handled unit per unit (like in platformer's), will deceive you.
Glide solution is a first approach for moving from one grid intersection to the other. But when you'll be ready, you could enhance to a detailed approach of the cycle without too many difficulties.
When you will be ready with the grid concept, just think about this question :
If I don't use wall collision to handle moves, how will I enable Pacman or ghosts to go up, down, left or right ?
Greetz.

Okay, i get it. so, how could I keep the ghosts from going through the walls and stuff?
dimitrip
Scratcher
500+ posts

pac man ghost movement

The way i did was to use à table to store the walls. You can have a look at my project.
However there might be other ways to do. I think for example about putting special marks at each grid intersection, that tell the character what directions It can take from there.
Greetz,
D.
hawkfang57
Scratcher
7 posts

pac man ghost movement

dimitrip wrote:

The way i did was to use à table to store the walls. You can have a look at my project.
However there might be other ways to do. I think for example about putting special marks at each grid intersection, that tell the character what directions It can take from there.
Greetz,
D.

okay, i'll take a look at your project! thanks for helping!
cs11467
Scratcher
95 posts

pac man ghost movement

Ghost AI, eh?

Well, here's how the AI works:

Blinky always tries to hit you directly.

Pinky tries to stay in front of your face.

Inky wants to go to a spot twice the distance from Blinky to two tiles in front of your face.

Clyde follows you when you're far away but chickens out at close range.
deck26
Scratcher
1000+ posts

pac man ghost movement

Some of my demo might be useful - https://scratch.mit.edu/projects/47150778/

You can still use normal movement rather than glide but each movement wants to be a standard amount usually in a vertical or horizontal direction.
hawkfang57
Scratcher
7 posts

pac man ghost movement

deck26 wrote:

Some of my demo might be useful - https://scratch.mit.edu/projects/47150778/

You can still use normal movement rather than glide but each movement wants to be a standard amount usually in a vertical or horizontal direction.

i looked at the project, but i don't get it. Do you think you could explain it? (like why i need a grid and how i could put the system in a pac man game?)

also could you show me an example using the blocks function? i think that would help me understand.

Last edited by hawkfang57 (Sept. 19, 2015 16:45:05)

deck26
Scratcher
1000+ posts

pac man ghost movement

Sorry, but if you can't follow my demo I'm not sure I can explain it any clearer.
hawkfang57
Scratcher
7 posts

pac man ghost movement

deck26 wrote:

Sorry, but if you can't follow my demo I'm not sure I can explain it any clearer.

it's okay.
leopard34
Scratcher
1 post

pac man ghost movement

Anybody know how to stop ghosts in pacman from crossing over lines when coding it? I am making a paceman game for my school to play in the new year and I can't work out how to stop it.
deck26
Scratcher
1000+ posts

pac man ghost movement

leopard34 wrote:

Anybody know how to stop ghosts in pacman from crossing over lines when coding it? I am making a paceman game for my school to play in the new year and I can't work out how to stop it.
Please create your own new topic rather than necroposting and share what you have so far so the solution can be tailored to suit.

Powered by DjangoBB