SFML community forums

General => SFML projects => Topic started by: Dubmosphere on July 03, 2014, 05:27:43 pm

Title: Pacman with SFML
Post by: Dubmosphere on July 03, 2014, 05:27:43 pm
Hello, I'm really new to SFML and I don't know if it's the best idea to start game programming with pacman :D The only thing left is the AI for the ghosts but I don't really know how to realize that... So maybe I start AI programming with tic-tac-toe or so... If somebody of you has an Idea how to realize an AI for Pacman-ghosts (it doesn't care if the behavior of the ghosts (blinky, pinky, inky and clyde) is different), please tell me :) I'd really appreciate it because if I have that, my first game is (almost) done...

I realized that the ghosts and pacman use more than one tile, in my version they only use one tile... Is it even possible to realize an AI for the ghosts that way (maybe somebody of you knows that)?

You can compile the code on windows and linux, on mac it isn't tested

Sorry for my bad english I'm Swiss

Edit:
New Download Link
http://download.lima-city.de/hazeler/Pacman.rar (http://download.lima-city.de/hazeler/Pacman.rar)

Edit:
I still haven't done an AI, but I have some ideas how to do it. I learned alot about OOP last week and I really begin to understand the whole objectorientation rather than just watching tutorials without all of the technical terms... Books for ever :D
Title: Re: Pacman with SFML
Post by: JuDelCo on July 03, 2014, 05:32:25 pm
I tried it but it seems to be a bit buggy  :-\

(http://i.imgur.com/IggPoS7.gif)

You can see my version i made months ago here

http://en.sfml-dev.org/forums/index.php?topic=12939
Title: Re: Pacman with SFML
Post by: Dubmosphere on July 03, 2014, 05:34:05 pm
I tried it but it seems to be a bit buggy  :-\

(http://i.imgur.com/IggPoS7.gif)

You can see my version i made months ago here

http://en.sfml-dev.org/forums/index.php?topic=12939

ooh I have to recompile the windows version... I've changed the Spritesheet^^
Title: AW: Pacman with SFML
Post by: eXpl0it3r on July 03, 2014, 05:52:56 pm
Oh look another Swiss person! :D

There are full blown articles on the internet that describe how the AI of each ghost works. Implementing it is a different thing though. With same Finite State Machines it should still be fairly easy.
Title: Re: AW: Pacman with SFML
Post by: Dubmosphere on July 03, 2014, 11:06:28 pm
Oh look another Swiss person! :D

There are full blown articles on the internet that describe how the AI of each ghost works. Implementing it is a different thing though. With same Finite State Machines it should still be fairly easy.

I know there are many articles about the bahavior of the ghosts but the point is I have no plan how to realize that in code^^... I'll try to implement clyde first because he moves randomly^^ I have absolutely no idea how to implement the other ones maybe I should try to do some simpler games first^^
Title: Re: Pacman with SFML
Post by: JuDelCo on July 03, 2014, 11:13:47 pm
The first you need is a pathfinding function/method, then you can start making the AI
Title: Re: Pacman with SFML
Post by: FRex on July 03, 2014, 11:34:17 pm
The ghosts have a set target they want to reach and at every intersection they choose to enter tile that is closer in straight line to target, it's very dumb pathing and can even lead to wrong results:
http://home.comcast.net/~jpittman2/pacman/pacmandossier.html#CH3_Intersections

I have a somewhat badly written pacman that implements that from over a year ago:
https://github.com/FRex/Man/blob/master/src/PacEngine.cpp#L377
Title: Re: Pacman with SFML
Post by: JuDelCo on July 03, 2014, 11:46:09 pm
I dont recommend you to see my code, because my ghosts behaviours are a bit more advanced/complex, but ill put the line where is the code, just in case other person needs it

https://github.com/JuDelCo/SFML2-Game/blob/master/Game/pacman/PacmanController.cpp#L267
Title: Re: Pacman with SFML
Post by: Dubmosphere on July 03, 2014, 11:48:33 pm
The first you need is a pathfinding function/method, then you can start making the AI

I'll take a look on the sourcecode of your pacman... i think it's really cool and is really similar to the original :D it's really interesting how you've done that :)
Title: Re: Pacman with SFML
Post by: Nexus on July 03, 2014, 11:53:40 pm
A quick search for "pacman ai" yields also this:
http://gameinternals.com/post/2072558330/understanding-pac-man-ghost-behavior

Don't hesitate to research further, it's crucial to progress as a game developer :)
Title: Re: Pacman with SFML
Post by: Hapax on July 04, 2014, 12:52:03 am
I made a Pacman-style game as my first game and I used the information found in The Pacman Dossier, which is where information that Nexus linked to originally came from (it's listed in its sources).

I'd recommend starting with Blinky as that ghost takes the simplest route and is easiest to understand. Then, the technique used to make the ghost find its way to where it wants to go can be used for the other ghosts too.

You can visualise the map as a single-width path with double-width walls, rather than a double-width path. This helped me immensely.

I think it it's the only game that I made (complete) so I'd be happy to discuss the innards of it, but I didn't exactly implement everything perfectly (I had no "ghost home") so don't expect too much from me  ;D I spent most of my time with the game adding features to learn more about things, especially SFML, which is why I added a music player and volume controls, language files, etc.. Also, my code is terrible in it; the main() function is about 1700 lines long  :-[
Title: Re: Pacman with SFML
Post by: Dubmosphere on July 06, 2014, 03:55:17 am
I made a Pacman-style game as my first game and I used the information found in The Pacman Dossier, which is where information that Nexus linked to originally came from (it's listed in its sources).

I'd recommend starting with Blinky as that ghost takes the simplest route and is easiest to understand. Then, the technique used to make the ghost find its way to where it wants to go can be used for the other ghosts too.

You can visualise the map as a single-width path with double-width walls, rather than a double-width path. This helped me immensely.

I think it it's the only game that I made (complete) so I'd be happy to discuss the innards of it, but I didn't exactly implement everything perfectly (I had no "ghost home") so don't expect too much from me  ;D I spent most of my time with the game adding features to learn more about things, especially SFML, which is why I added a music player and volume controls, language files, etc.. Also, my code is terrible in it; the main() function is about 1700 lines long  :-[

What do you mean with single-width-paths? Sorry if it's a dumb question but I don't really understand... Do you mean the width of the "ways"?
Title: Re: Pacman with SFML
Post by: Hapax on July 07, 2014, 12:50:50 am
What do you mean with single-width-paths? Sorry if it's a dumb question but I don't really understand... Do you mean the width of the "ways"?
No need to quote the entire post; just quote the part you want to talk about (remove the rest) ;)

You said that your Pacman and ghosts were only the width of a single tile. In your map, you had paths/ways/allowed-tiles as single-width tiles. I was saying that I found that keeping the path/way as single-width, making the walls double-width (that's in the map but actually draw them only filling half of those tiles), and increasing the draw-size of Pacman and the ghosts, even though they are still following the map where the path has is only one tile-width.

I found that it worked for me and I think that it was a bit of a milestone of realisation  8)