Game Lab Challenge: Lesson 27 Error

Hey all,

Second pair of eyes needed here. This project:

to win: Collect all pac pellets:
If you get all pac pellets, the winner screen appears and the rectangles are displaced.

This does NOT happen for the loser circumstance (Pac touches dig)

The maze remains.
We know that the maze is rectangles and the winner/loser screens are sprites. I’ve wrestled with this group on this issue…, and I know I’m missing something simple.



It looks like a cool game. I think I have figured out what is going on… First of all, the mazeOff function will just draw a new maze off the screen, but the maze on the screen is not moved because it is a set of rectangles and not a sprite, so drawing the new maze off the screen is probably not doing what you want it to do and it really doesn’t need to be done.

What IS happening, though is that your winner function is designed to display the winner screen when appropriate, but if the winning conditions aren’t met, the maze is drawn (mazeOn). So, when you lose, it’s not winning, so the maze is drawn, again and again.

When you do lose, you unhide the loser screen, but after it’s drawn, the winner clause still kicks in and the maze is drawn on top. The solution is to add a “drawSprites” block inside the loser clause, so the sprites are drawn with the loser sprite on top

Hopefully this makes sense. The order of drawing inside the draw loop can get a little confusing and does definitely make a difference.

Hope this helps!


1 Like

Hello @mcmastersha,

In regards @mwood has provided a decent solution to your original problem, however, might i suggest just combining the win and loss functions together?
logically speaking looking at something like that is somewhat disorienting, and separating conditions which all end in the same result (player can no longer play) by doing this you can easily see why you have this problem

Below is some suggestion code for improvement you can do what you like with it

function gameover() {
  if(score >= 20) {
  } else if (dig.isTouching(pac)) {
    loser.visible = true;
  } else if (!loser.visible){

also with this method I’ve made your mazeOff function completely redundant as it was not needed in the first place hope this helps!


This is why I come to this forum! I tell my students, “we” are a “we” for a reason! Multiple brains and eyes! I appreciate the insight :slight_smile: Thanks so much!

1 Like