Pac man ghost ai

For questions about using Classic.

Post » Wed Jan 21, 2009 2:20 pm

You're correct. This fixes the first problem: Your character will no longer continue in the same direction. But the second problem still remains. Try doing something like David did in the cap posted on this thread.

Now that I think about it if you can fix the second problem you'll probably fix the first problem anyway. So you may not need the code I gave you anyway.

I'm actually having basically the same problem with a Pacman style game right now. But I'm planning to use either Ball movement or grid movement. I suppose I should post about it in a new thread though.

edit: Here is the new thread.
B
3
S
2
G
4
Posts: 271
Reputation: 2,017

Post » Wed Jan 21, 2009 3:21 pm

Hi Stantor , i think the problem is that when ghost collide the old value is erased.What we need is to store the old value somewhere before contact and then compare it within the random expression.But i ve no idea how to do that.In python you can store and keep a value as a list ,a tuple or dictionnary.

Could be nice if Ashley can give us a hand.

Regards

I ve seen you Pac man Wip and yes you need grid control.I ll have a look .
B
1
G
3
Posts: 9
Reputation: 843

Post » Wed Jan 21, 2009 4:45 pm

I have cooked up a quick example of basic ghost movement. May be not the most clever way to do it, but it works.

I didn't really care to comment it, after all it's just 28 events. But if you need further explainations don't hestitate to ask.
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Wed Jan 21, 2009 5:23 pm

Hi think it s genious :idea: !! but yes ! please explain it !! could be so cool for the community !!

thanks a lot

ps: do you have any idea how to fix the floor(random(4))*90 expression ?

THX
B
1
G
3
Posts: 9
Reputation: 843

Post » Wed Jan 21, 2009 6:03 pm

There's nothing wrong with that expression. It will just give you one of four different directions.
But the way you're using it won't work for what you intend to do. Since the direction you get can very well be the very same direction you just had and therefore the ghost will move into the walls. (I don't think you need the "floor" in there btw)

I'm basically using a loop in my example that checks all four sides of the ghost and will only allow directions which aren't blocked by any walls.

Okay I will comment my cap. Just give me a little time.
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Wed Jan 21, 2009 8:57 pm

Okay I put some comments in there and I was able to optimize it a little at least. Uses 4 events less now. Here it is.

If you're fairly new to Construct you still may have problems to immediately understand what's going on in there. Just give it a little time, toy around with it maybe...

Any more questions feel free to ask.
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Thu Jan 22, 2009 11:40 am

Thank you Pixel,

You did very well but to be honest this is beyond my skills! it seems you got the logic and a bit of Math knowledge ! which i don t have.Everybody need to know that the guys from Namco who did this game where absolutly genious.Pac man is not a simple game , it need a foxy approach.I like the idea to check wether or not there is a wall or not in any direction and that the ghost do not systematicaly engage in a free space but in a random way(i can t find the process of this randomness).i think from there it could be possible to make a kind a chazing mode.I m 3d artist and not a coder , i just know a bit of python.I m going to decrypt this code line by line until i understand the way you came to this.

questions:why you did not use the grid object ?
Do you think with more tools in construct it could be simpler ? if yes which kind of tools
do you think there is another way to accomplish this ?

Thank you from the community for your remarquable help and kindness. :wink:

M.
B
1
G
3
Posts: 9
Reputation: 843

Post » Thu Jan 22, 2009 8:46 pm

I don't think the grid behavior works too well for a Pac-Man game, since the sprite would only be able to move from grid space to grid space. That would be especially annoying if you were using it for the player sprite itself.

I'm pretty sure there are many other ways to do the same thing, it's just the one that came to my mind. If somebody had a very simple solution I'd like to see that too.

Anyway, I found one bug in my latest example. Has to do with the starting position of ghosts which can create infinite loops right on startup (my first example didn't have that bug). I've fixed this and added the ability for ghosts to handle a dead end (to turn around, this would have caused a infinite loop in both older examples).

Also I've turned it into something a little different. Right now you can only draw your level, place ghosts and then run it to see what happens. I know it's far from a complete Pac-Man game yet. But I believe this could be really cool with features like being able to load different tile/sprite sets and save/load created levels of course. I'm currently thinking about turning this into a little side project of mine.

No source for this sry, but maybe it's still interesting: DOWNLOAD

[quote:22wev2cc]I m going to decrypt this code line by line until i understand the way you came to this.[/quote:22wev2cc]

That's a very good attitude right there. Once you get the hang of it you'll come up with your own (better?) solution. :D
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Previous

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests