macek/google_pacman

Ghosts stay blue permanently on restart

Closed this issue · 2 comments

If you get a game over, then click Insert Coin to start a new game, the ghosts will stay blue permanently once you've collected a power pill. This has a few side effects too, such as this: Ghosts will no longer change modes for the rest of that level. This means if you race to a power pill right at the start, the ghosts will be in permanent scatter mode for the rest of the level (although as soon as Elroy 1 is activated, Blinky starts chasing).

Sometimes the effect carries over to the next few levels, but it seems randomish (usually lets you do it up to level 5 or 6, then stops working). This is obviously a bug in the original Google code, so if fixed it should probably be saved as a different version. Can anyone please look through the code of pacman10-hp.3.js and tell me what causes this bug? It seems to trigger every time you do a restart, but not on the first play. Is there a variable that's erroneously set or something when you get a game over, or when you start a new game (not the first game)? I'd love to know what causes it! Thanks, this is really interesting.

I've fixed this with a little bit of effort and small code addition. This bug is present in google's official version, but is in no way tied to "when" you have the gameover.

The fright mode is calculated upon level creation by multiplying a fixed number set in the levels by a fixed number which represent a time value. So the first level will have 6 * 90 as default fright time, plus other additions that are made later.

What happens here is that upon restarting the original level value is no longer 6, but 6 * 90, so at first restart becomes 6 * 90 * 90, at third restart 6 * 90 * 90 * 90 and so on. So if you die at first level and the second time hit the second, first fright would last 6 * 90 * 90, while second would last 5 * 90, and this is why "apparently" it got fixed after a bit of levels.

The fix consists in a modification of the NewLevel function, adding a check line, like this:

if ((g.levels.frightTime > 0) && (g.levels.frightTime <= 6))
  g.levels.frightTime = Math.round(g.levels.frightTime * D);

Issue fixed :)

@Varstahl, I'll add this into the repo. Thanks for your detailed explanation.