Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Rafael

Ok Guys,

I'm throwing the towel here and screaming for help in the community.

I always wanted to build a pacman game. So i couldnt think on a better way to start learning impacjs with the game.

Thing is that it's more complicated than I thought. All the logics behind it it's actually an art to build it lol.

Well.. I'm opening this thread to see if i can gather as much information about it as I can and hopefully help some other people out. I will try to post everything that I learn and hopefully also some code that will help other ppl like I'm getting help.

Well... First question is about the "food" (dots) entities. In my case I call them "pills".

I've added all of them through the weltmeister because of the spacing I kinda needed to customize it to fit it nicely. Problem is that the performance is not really well, and I only have started built it.
I'm afraid it will get too lagged and I will loose too much of perfomance once it's done.

This is the screenshot of how it look like and you can also see the number of the lag in the bottom.
http://devel.rafaelfaria.net/pacmanscreenshot.jpg

Any suggestions of the best way to place the "food" or in my case the "pills" in the map?!

1 decade ago by alexandre

You've got over 100 pills, i.e., entities. Lag is unavoidable. Instead, use a background map ("pillsMap"): at every game update, check position of pacman & translate into pills map coords, check tile value at that position: if a 1, add to score and set tile value to 0. Pill is gone. Score went up.

1 decade ago by alexandre

PacMan seems easy but it's not (AI + A* = ARGH). Avoider type games would be IMO the best way to get acquainted with Impact.

1 decade ago by Rafael

Alexandre,

Yeah. I realize it's not easy but I also very keen to learn it and i'm pretty sure it will be a good education not just on impact but also in math, logic and so on!

Thanks for the advice. Just to check if I undestand. In the weltmeister I will create a layer called PillsMap, and use the pill as the tile. For every update of the game i will check the backgroundMap/position against the pacman and see if it's 1, change to 0 add score. Is that it?

ta.

1 decade ago by alexandre

correct.

1 decade ago by clok

Great advice from alexandre there.

I do want to point out that there are optimization options for having many entities (~500) that I have discovered working on my game.

For one, I have found that the backgroundMap is quite exhausting on the renderer since it will draw each tile in the map every frame unless you determine it to be prerendered. If it is prerendered, it is not dynamic. So, to get around this, I removed the backgroundMap from my game.

Now, this means that PiSpace has not background image in the classical sense, but this did allow me to render fully interactive particle effects at higher speeds. The "game" isn't perfect by any means and I am considering other ways to improve the performance, but it did help.

Another side effect is that I do not use Weltmeister to build my levels. I build each entity once per game and place them in the location I want to build my level. This was done because I am using Box2D and wanted to have some special features added to my game.

Back to PacMan, what alexandre is suggesting is the best way to approach the problem using the ImpactJS built in framework and tools. Consider building a prerendered background map for the paths (the walls and channels for PacMan and Ghost) and entities for pills and characters. Impact should have no issue handling all these entities. I have actually achieved over a 1000 entities on screen at once with little issue.

If you haven't seen this before, I think you will really appreciate The Pac-Man Dossier. Pretty incredible.

Here is a demo of PiSpace with my optimizations I mentioned above. Press 'j' to add more pucks and 'k' to kill them. I have seen it run smoothly with quite a bit of action on screen. Feel free to ask for more ideas if you like. I think I have rambled on long enough.

Cheers!

1 decade ago by Krisjet

Check out the Pac-Man Dossier, it is definitely the ultimate Pac-Man source. A* was mentioned earlier in the thread, but the ghost AI is a lot simpler than that. Basically what a ghost does at each intersection is check whether his distance to Pac-Man is shorter in the Y-direction or the X-direction. This is measured as though there was no maze at all, just the pure distance between the coordinates.

The ghost will always leave the intersection in the direction that has the shortest distance to Pac-Man, as measured above. So, if Pac-Man is two tiles above him, and four tiles to the right, he will attempt to go up. If something is preventing him from going up (if there is no exit 'up' or he came from that direction) he will fall back to left, then to down, then to the right.

I think this is correct, but check the dossier nonetheless :)

I was working on a Pac-Man game earlier this year, and it's an incredibly fascinating game. Extra points if you remember to code in the overflow errors for ghost pathing :)

1 decade ago by Jerczu

http://nervman.cdgn.co.uk

1 decade ago by StuartTresadern

I always remember this :). but I can not remember the talk it was from, just keep the clips to remind me, basically its from the dossier above.

Pac-Man console had less memory than a 10-year-old cell phone. Problem to solve for the ghosts: What is the shortest distance between two moving objects in a maze? Solution: don’t model the ghost; model the maze. Intelligence was built into the maze itself. Each cell had state. Invented “Pac-Man smell”. A cell he just moved off of had “maximum smell – 1″, and it decayed quickly. Ghosts just had to smell Pac-Man. The ghosts wander randomly until they pick up the scent, and then they move into the cell with higher smell. So they will never cut him off at the pass (on purpose)… but it was a very simple and memory-efficient solution.

1 decade ago by Arantor

I never looked into how Pac-Man ever did it, but my approximation in the past when I've done similar is simply to say 'if the player is right of the ghost, and the ghost can go right, go right' with a randomness factor attached, so that the ghosts will sometimes go off and do other things but are reasonably likely to go after the player if possible.

1 decade ago by StuartTresadern

Maybe of some use : http://impactjs.com/forums/code/tile-value-plugin

1 decade ago by Jerczu

Use A* plugin from pointofimpactjs.com but set a cycle to find player's position otherwise it will eat a lot of performance if you do it per tick.

1 decade ago by gnx

Read the above mentioned Pacman dossier.
Pacman contains no A* and you should really only need 5 entities (pacman and the ghosts).

It is not a simple game to make though.

1 decade ago by fugufish

yep A* is proven

1 decade ago by Jerczu

@gnx pacman is actually very easy to make what's complicated is the algorithms that build the maps and populate paths with edible dots. But very much doable.

1 decade ago by gnx

Quote from Jerczu
@gnx pacman is actually very easy to make what's complicated is the algorithms that build the maps and populate paths with edible dots. But very much doable.


What I meant was the underlying logic in the way the ghost behave is more subtle than it appears, and there are lots of "wrong ways" of doing Pacman.

1 decade ago by Jerczu

Agreed, I found A* to be perfect for the job.
Page 1 of 1
« first « previous next › last »