I Coded Pacman but it's Procedurally Generated
ฝัง
- เผยแพร่เมื่อ 5 ก.ย. 2024
- In this video I program a clone of Pacman and use it to create procedurally generated maps!
Pathfinding Website: www.redblobgam...
LINKS
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
Support the channel: ko-fi.com/code...
Itch.io: codenoodles.it...
GitHub: github.com/Off...
█▀ █ █ █▄▄ █▀ █▀▀ █▀█ █ █▄▄ █▀▀
▄█ █▄█ █▄█ ▄█ █▄▄ █▀▄ █ █▄█ ██▄
What do you guys think of my avatar?
I think its cool but maybe if it was less realistic it would be more casual.
You are basically a vtuber now(?
honestly, no
Very cool
7:42
Nice! It'd be cool to have a mode where after you eat all of the dots, it generates a new map and you start playing it immediately
it would also be cool to have a CEDX mode where, if you eat all the dots on the left half of the maze, an item appears on the right half, and when you eat that item the left half regenerates into a new shape - and vice versa, of course.
Another thing that would be cool is if each map is infinite, and more ghosts can spawn in based on your distance from the start. Obviously the goal would change from getting all the dots to just surviving as long as possible.
It would also also also be cool if there were bigger dots that once eaten it would make the ghosts fly away from you and flash white and blue and while they’re in that state you can eat them too
@@gregritferdjr They already added that.
@@caldercockatoo2234 you mean like in PAC-Man 256?
About accuracy of Pac-Man's stuff:
*ABOUT GHOSTS*
Names:
Red - Blinky (Shadow, Oikake, Chaser)
Pink - Pinky (Speedy, Machibuse, Ambusher)
Cyan/Light blue - Inky (Bashful, Kimagure, Fickle)
Orange - Clyde (Pokey, Otoboke, Feigned Ignorance)
Target AI: Ghosts calculate the position to the target and take the closest one to go. If the targets have the same distance, they go in this order: Up, Left, Down, Right. The ghosts cannot turn around 180 degrees (it has some exceptions).
*SCATTER MODE*
The corners for each ghost is ordered like this:
Blinky - Top right
Pinky - Top left
Inky - Bottom right
Clyde - Bottom left
Blinky rotates around its corner clockwise-only and Pinky turns around counter-clockwise only. Inky and Clyde can turn around in either direction depending on from what part of the maze they went from.
*CHASE MODE*
Blinky's AI is right, it puts a tile above Pac-Man.
Pinky's AI puts its target tile ahead of Pac-Man (like Blinky), but it gets moved 4 spaces ahead of Pac-Man's direction, thus, Pinky's attacking Pac-Man from the front, while Blinky's chasing Pac-Man's tail.
Inky's AI is the most complex of them all, cuz it's target tile is connected to Blinky's position and a little bit of Pinky's mix. So, the funny ghost target tile is like Pinky's, but it's 2 tiles ahead, and the target tile inverts Blinky's position from that tile, and this is where the target tile of Inky's is.
Clyde has the name off, but the target tile of his is the same as Blinky's unless if it's 8 tiles away of Pac-Man. If Clyde is within the range, it's target tile is placed the same as if it was in Scatter Mode.
*FRIGHTENED MODE*
When entering or exiting Frightened Mode, the ghosts turn around 180 and turn blue. Their AI is picking random direction (see Target AI about turnaround rule). When Pac-Man touches one of them, they give the points in ascending order (200, 400, 800, 1600), and turn into the eyes, then they go inside the Ghost House on high speed (located in the middle of the maze and blocked by the pink door). While they are in the "Eaten" state, they do not turn blue when entering Frightened Mode.
*SOME OTHER INFO*
There are two funky parts in the maze (i'll call them areas) that are located to force ghosts to not turn up and go straight to the path. These areas are located above the Ghost House and the Pac-Man's starting area.
Forgot to mention that when ghosts switch modes between Chase and Scatter, they turn around 180 degrees.
don't each of the ghosts follow slightly different AI's?
And they are rather well documented as well
all the ghosts in the original pac man have a different specific ai follow but since cn doesnt want it to be too much to be the original he made it his own
@@bobobo6relyou can still make it your own without it being painfully basic.
th-cam.com/video/ataGotQ7ir8/w-d-xo.html
@@bobobo6rel His pathing should still work with the classic AI. all he'd have to do is change the pathing target for each ghost. and I don't figure it would take a lot of effort
Really cool. But, I have a suggestion: there still feels like there is a lot of wasted space with the generation algorithm. You might be able to better use the space by using a different approach.
Currently, your algorithm seems to kind of just make paths, and connect them up where they just so happen to connect. I think you could get way better results if you use a method that _focuses_ on how the paths connects and has rules on how those connections occur.
I highly recommend taking a look at the “Wave Function Collapse” algorithm, as it’s one of the most powerful and used methods for randomly-generated environments.
Yeah I wish the ghosts didn't all just chase pacman too, in the game only the red one chases you, the others have their own rules on how they approach you
I would have at least mirrored the map and maybe ensured there's always a path that goes around its perimeter.
@@PhantomOfficial07i KNEW something was wrong with the ghost AI
I'd have simplified the ghost sprites by drawing just their "sheet" parts without the eyes, and rendering the eyes on top of that. After all, the disembodied eyes are already used for after a ghost is eaten and runs back to the spawn room. Plus, the eyes are the only part of the sprite that changes depending on which direction the ghost is facing, so the sheet would just have the animation of the bottom part doing that weird alternating thing. Heck, you could even have all the ghosts share a single sheet texture of pure white that the renderer recolors based on the ghost's identity.
and even better: each grid uses it's seed to randomly determine each ghost's color. to make them distinct you'll like have to make one ghost color random and then base the other colors off of that
there is a video about pacman ghosts that tells you the different ai for each of them. it turns out that all of the ghosts have different pathfinding algorithms that makes it better at surrounding pacman
Retro game mechanics explained :)
Also, regarding different ghost behaviour: there's a great video by Retro Game Mechanics Explained that shows how the ghost AI's aren't _that_ complex. Not easy, mind you, it would still be work. But not too difficult either, specially give you already implemented a pathfinding algorithm the only think you needed to do was give them different objectives.
I love content like this, it’s fascinating but also simple to understand. Hope you Keep em coming!
Thanks!
I wonder if there is a seed that generates the original maze
Wow, that's thought provoking!
I love how your avatar has cinammon and sugar instead of some sauce, because I like my noodles with some sugar and cinammon as well sometimes, that's a very nice and unique way to represent yourself as noodles
Man, despite the fact that this is only your 3rd video, this is great stuff. Keep it up, I enjoy seeng more of what you do! :)
improvement to procedural map generation:
- start with the ghost house where you want it, surrounded by empties
1 randomly select a square with 0 or 1 open sides
- randomly select an unconnected side to connect
- if connecting this side would create four squares all connected together in a square arrangement, (a "quad") go to 1
- remove the wall
- if any square has less than 2 open sides, go to 1
(it's possible to deadlock by creating a map with squares needing more opens that will have to lead to a quad, if that is encountered, just reset and start over)
this will generate a board with no quads and all track accessible, but there are probably isolated tracks, and lots of track without forks.
also the ghost house will be on its own isolated track.
- use your pathing method to identify and label the squares on separate tracks
2 randomly select a square that has an adjacent square that's on a different track
- if removing the separating wall would create a quad, go to 2
- remove the wall
- combine the tracks
- if there are still multiple tracks, go to 2
now all squares are conected on a single track, but there are probably several dead ends and many long runs of unbranching track. if that doesn't bother you, you're done. to open things up, continue:
- count all remaining walls
3 randomly select a square with a wall
- randomly select a wall to remove
- if removing the wall would create a quad, go to 3
- remove the wall
- decrement wall count
- compare the wall count with some function to adjust "open-ness" of the map. if not open enough yet, go to 3
there may still be areas of the map with only one outlet, but it should be much more open I can't think of a quick way to test for areas of track with no outlets.
it's also unnecessary to vary the location of the power pellets or the starting point since there is always track there.
Fun fact: you inspired me to make my own multiplayer snakes game! Keep up the awesome videos, I love 'em!
That's awesome!
it would still be cool to see a multi-player snake game that functions differently from the other games tho
Pac-man is my favorite arcade game next to dig dug. I like to view this as the "Pac-man 2" we never got. Also I like your avatar.
We don’t talk about Ms pack man
@@KingOfTresune oh yeah I forgot about that
Love the code bullet music...great stuff bro
This is a neat project! Can't wait to see what else you'll do!
Very cool to see Pac-Man get some love. I made my own clone of Pac-Man, "Pac-Man Infinite" my senior year of high school in which more and more level-sized chunks would be generated as you progress, connected where the tunnels would be. I wanted to use the same tile graphics as the original Pac-Man and discovered that you only needed to distinguish between in-bounds areas, walls, and out-of-bounds areas. Each tile would check a 3x3 area around itself and compare that to a list of which area configuration pairs to which tile. It was surprisingly easy to get the ghosts to navigate very long levels, too.
That sounds awesome!
Some suggestions to make the game better (If you don't like some of them or you think that not all players would like them, make it so you can enable and disable them in a settings menu):
-Make time freeze for a little bit after you eat a ghost.
-Make vulnerable ghosts flicker when they are about to turn into regular ghosts.
-Add a level editor.
fun fact: each ghost has different ai, blinky (shadow) follows you like a shadow, pinky (speedy) follows the tile in front of you, inky (bashful) is basically pinky but works with blinky, clyde (pokey) when in an 8-tile radius with pac man he turns around.
What next? An Ai to play this version?
Would make a fun screen saver.
Then port it to NES, and then corrupt it...
You should add a level editor to be able to costumize basically everything even lives and maybe the amount of ghosts but there will have to be a limit and maybe you should add time so yea hope you like it
Really great video, plus the explanations you gave were very clear and easy to follow
every copy of pac-man is personalized
Lol
It be cool if there was an update video adding back the 'personalities' of the different ghosts, as was as maybe porting over some of the additions that were added in later packman games, like the 3d games had mazes as mini levels but they had an increasing amount of hazards, the only thing that sucked was they didn't do the ai, where blinky would head directly to you, pinky would head a couple blocks in front of you(and there was a glitch where if you were looking up she's head to the left an equal amount of blocks as up, inky tries to make a triangle with blinky and pinky blocking you in, Clyde would do something random til he got close to you then he'd get scared and run away
rand() is only bad if it is critical for the number to be actually random like in cryptography or if you want specific distribution patterns (rand has no guarantees as to how random it is. Used to be a problem in old compilers but isn't really anymore).
If it isn't you can use it no problem.
Thanks for making this kind of videos because I learn a lot about programming even if I don’t understand everything you say keep doing this kind of videos because I love them
I'm glad you enjoy them!
Does the classic pacman grid generate on any select seed, like seed 0 produces classic?
If you press F1 it uses the classic Pacman grid instead.
My man, I just thought of the binary bit trick for selecting tiles on my own a couple of days ago. Then I found this video. Nice to know I'm not original, ha ha
10/10 video i loved it
this is really cool, now all you need to do is write an ai that can play procedurally generated Pacman
this is very neat
the one thing missing is that each ghost acts differently from each other
i dont know how well it would work with the random generation though
Amazing video
Ok but I have a challenge
Add some more ghosts and I have a few ideas
Lavender/purple: moves as a group of 3 but they can only go left and right
Green: same as purple but they are a group of 4
Glitch: they have random looking textures and go through walls but it takes 3 minutes for them to spawn
Cool idea!
Isn't that just PacMan 256 ghosts? Like from that one infinite randomly generated game?
I would recommend adding a function that looks for corners of the map to place the power pellets, that way you decrease the chances of getting flanked at those parts of the map. Another idea would be a function that creates branches that connect others together to add more maneuverability to pac man's ability to evade ghosts as having a large square path with not power pellets is a huge risk as you can easily be surrounded by the ghosts.
This would be perfect for Wave Function Collapse like in Townscaper... then the mazes would likely feel more Pac-Man-esque!
The one thing I will point out is that Clyde (The Orange Ghost) in the oringal game is usally just wandering around unless pac-man to close by which would put him into pursuit till pacman got far enough away.
Fun fact: 3x3 tile connection systems also exist for more complicated setups!
"and it somehow did" made me laugh hard 🤣
It would be nice if each ghost had its signature unique behaviour so they don’t just become recolours of each other
This is really cool but, wouldn’t it be cooler if every time you clear the map it’ll generate a new one? You could have options for this such as; Autochange upon clearing, ask to change when cleared or don’t autochange.
thanks for the idea, thanks to this video I also create a procedurally generated pacman but in python but with ghost that moove randomly and with an other map generator that create less hole and I think that it is better
you could use that code to make an infinite-sized pac-man maze where the goal is to survive as long as possible
The decision to use a random tile instead of a pre-set tile at a corner for Scatter Mode from the beginning is genius. Accounting right away for the procedural generation, I see?
You should keep working on this. Making each ghost move in a unique way like they do in the game, Adding procedurally generated looping (like the entrance/exits on either side of the original board) and different procedures to generate the board in different pattern shapes would be welcome additions
Awesome 😎👍.
codenoodles: prevents branches from touching other branches
also codenoodles: lets sub-branches do the exact same thing
Ahbeef is doing a retrospective on all of the pacman games and has a pretty interesting color corridinated graph explaining his thoughts on each map in the games. He's up to pack mania, check it out
Also, this reminds me of world biggest pacman, but that was user created levels
Your channel is underrated af
I didn’t realize this was your 3rd vid. good job!
A little inaccurate on ghosts but wouldn't expect you to re-code it after all that work.
Scatter mode means each ghost goes to its corner (Orange "Clyde" to bottom left for example). You probably already know each ghost chases Pacman differently.
As for Ghost movements, if you know which way they are going, they only need to make a decision when they can turn at an intersection. They never turn around 180 degrees unless a power pellet is eaten, or when switching between chase and scatter.
Ghosts always have a target tile unless frightened, which is in the corner during scatter mode. Whichever turn brings them closest to the target tile using a linear line (a^2 + b^2 = c^2) is the one they pick. They prioritize up, then left, then down, then right if distances are equal, iirc - something like that anyway.
TLDR it's a lot harder to simulate pacman then it looks, you did a great job!
CodeBullet would be proud 😂
what if after eating all pellets you have to leave through a gate/the looping end, going out of bounds into the next level seamlessly
you should optimize the ghost sprites with only body and eyes, probs even further with color shifts
I thought the scatter pattern made the ghosts go to their respective corners and then move randomly within it, until the timer runs out
"Wave Function Collapse" is an algorythm which could be usefull to generate more "realistic" pacman maps without some issues you had (except for understanding and implementing it tho)
after looking at many comments i was not the first it seems
Music choice is giving me Code Bullet vibes
A lot of info you showed wasnt quite correct like the scatter mode where they choose "random" positions instead like the original where theyre assigned their own corner (very depressed ghosts indeed) however the main game mechanics arent the main theme in this video. I like that you did in fact change the map so that the map generating program could work, however it also isnt the best as it still generates clumps of dots, i do have an better idea however it would be very difficult to describe it here but ill try.
You can start with a ghost house, thats a good idea you had, however you couldve "spawned entities" right in front of the enterance, they would move in a random direction 2 tiles, wherever they land it generates an "open tile".
Now what it does is that two rows or columns cant be adjacent to one another but 1 tile apart, however we need a bit more restrictions when they choose where to go, if there is an "open tile " next to it dont ever choose that path, then those "entities" could also have a small chance like 10% to spawn another entity only if theres 1 open tile next to them (which is the one they came from) and they couldnt choose the same path, also they have 10% chance to disappear.
However there is a length limit, i would make it global so that new generated entities disappear at the same time as the starting few.
Now when they disappear and there are dead ends you can spawn a different type of entity that connects to the closest open tile in a strait line without going backwards.
Now a few deatils that i got while writing this is make the entity disappear when it has nowhere to go
When you spawn the entities before they start generating make them go in a circle to choose a place (they should move 2 tiles forards of course so that its consistant with the algorithm) once every entity chooses where to go start the algorithm.
Also portals would be cool, just check every 2 tiles if there are open tiles on opposite sides of the map and save it, then when you save all those positions choose he middle one.
Idk why i wrote this but it just popped inside my head outof nowhere, i would appreciate if anyone does make a system like this.
I also hope you understood this or anyone else reading this cuz ive just lost 10 minutes of my life writing this.
And now a reward to you for reading this: you've got a new subscriber, your video was very enjoyable!
Have a cookie too!!! 🍪🍪🍪
This has me thinking about making a maze like Pac-Man rpg that has different items around a dungeon that is made up of a set number of generated levels and a final fantasy or undertale like combat system and navigation to the next room is done by entering the hallways on the edges of the maze and the pellets could be a currency with many different types of ghosts with different movement patterns and combat abilities with like giant ghost bosses
If anyone under the sun would like to make this by all means go ahead that would be awesome
Nice
Nice vid man!
this is really cool, but I would like to see an actually procedurally generated pacman because currently it isn't procedurally generated its randomly generated, procedurally generated is when it is constantly generating new terrain as you move making the map infinite, like in Minecraft, but you would have to make a set number of dots you have to eat to proceed to the next level, you could also just run away from the ghosts into the distance but this wouldn't be a big problem because you can't avoid winning the level and will spawn back in the middle of the map again and the ghosts will get faster than you, rendering this method useless.
This is really interesting
I just wish you actually made the ghost ai how they did in the arcade game rather then just whatever sounded right
During chase mode
The red one paths straight for pacman
The pink one paths 2 spaces ahead of pacman
The blue one is weird, it paths to how far the red one is from the pink ones target doubled relative to pacman, something about trying to corner pacman
The orange one paths straight for pacman, until he gets within an 8 tile radius of him then he goes for the bottom left
During scatter mode
The red one goes to the upper right
The pink one goes to the upper left
The blue one goes to the bottom right
The orange one goes to the bottom left
I wonder how a different approach might have worked where rather than creating random paths, you created random blocks of walls following a set of rules instead.
i always thought the moral of the story was to find out a way to make the chunks smaller and for the branches to spread more and to figure out how to get the weird bleep thing out of your vocal cords so you can say swear words correctly
5:29 it's not almost done, each ghost acts differently
Would love to see a version 2 of this
Second :)) Its gonna be a good vid
This is so creative I love it
I’m sure at least one other person has said this but there is a specific algorithm for each ghost during chase mode that is pretty different from what you used, here is a link to a video I watched that explains it
th-cam.com/video/ataGotQ7ir8/w-d-xo.html
that tile tip was really good
Bro I’m coding right now
I think instead of creating branches, the better way would be to create walls
If I remember correctly, fangames like this are considered fair use as long as you use a different name, unless you monetize them. You could name this game "Puck-Randomizer". Pac-Man's original name was Puck-Man, but people vandalized the machines to replace the P with an F, so they changed the name of the game & its titular character, & the "Puck" in the name I suggested for your game is an homage to Pac-Man's original name, which isn't copyrighted anywhere in the world, except maybe Japan. So yes, you can release this game, as long as you don't make people have to pay to download or play it, and make any & all DLC that you may release in the future free.
If you ever need any music for your games, just let me know.
5:23 - love how you call it a “Super dot”
Woah dude, that concept sounds fun. What software did you use to make this? Unity? Cause it seemed like a fun project to try and learn. Please tell.
I wrote this project in C++ with the graphics library SFML. The UI is made with my own library called Glass.
It would be neat if seed '256', generated a broken map, similar to how the original arcade game's map broke if you surpassed level 255.
Im actually into this stuff but in minecraft command blocks
I made a lot of stuff with command blocks like infinity stones
, peashooter and PVZ etc and weirdly enough , TIME LOOPS
Codebullet vibes be like:
I like your new avatar. You also have good video ideas.
Thanks!
Wish I could code like you
very upset that he did not code the individual ghosts' pathfinding techniques :(
Tbh, i didnt understand over 50% what ya saying in this video but still find its fun somehow
I really really really love the seed function
Good video! I just thought it would be a game that would infinitely generate.
Have you ever thought of using quantum wave function collapse to generate PAC-man mazes? I think it would work more nicely than noise or the branching that you implemented in the video. It would allow for all generated mazes to resemble the original pac-man maze.
Nice work.
You’ll probably not see this, but I’m curious. What c++ game engine are you using?
The next step is turning it into a roguelite
CodeNoodles - You need to develop this further; the maze should be a little more detailed pathwise, you could retrofit the missing PacMan elements (like the fruit), add in stuff from the other games (bouncing fruit, random picking a seed based on Ms. Pac Man multiple mazes, the super prise from PacMan Plus, stuff from PacMan Jr., etc.)
Finally.
The new PAC-MAN 2.
8/10 imperfect ghost AI.
your avatar is making me hungry
You can… you can turn around before reaching a fork…
The ghosts each have unique AI that make the real game play very differently from this
just wondering:
what game engine did you use to make this?
that bleep made my ears hurt
subscribing but keeping notifs off
screamed 'jesus christ i hate you' the second bleep
Shoulda made it so that the levels were randomized after each clear
I’m upset that the Pac-Man animation didn’t have all three frames it usually does