Unit 3 Lesson 18 Flyer Game - Coin & Obstacle collision problem

I am still having trouble with my coin appearing behind or inside the obstacle collision zone when it resets to a Random sprite.x and sprite.y position after it is touched OR when I rest the program.

I have looked at the example solution and copied what is going on.
I have moved around the order that the coin and obstacle are drawn.
I have tried setting my obstacle collide to circle and rectangle.
My coin is set to circle.
I have used the sprite.isTouching() AND the sprite.collide() but nothing seems to work. Any ideas?

Here is my link: https://studio.code.org/projects/gamelab/UoP8kaisiigHFYPUIEcrhslqHFPhRt7qvZAaQqkEWR0.

Any help is appreciated.

Hi!

Nice work on using the debug property to help understand what is going on.

Another thing that might help is to use a console log statement to see what the value of coin.collide(obstacle) right before line 82, where it’s used in an if statement. When you do that, you’ll notice that nothing is being printed, because the line is never running. A closer look shows that the if statement before this one was never closed, so the part of the program that runs collide and moves the coin to a random place when it happens will ONLY be run when the character is already touching the coin.

One thing that also helped me with noticing these unmatched curly braces it is that the code is indented properly (nice!). A quick skim showed me that it doesn’t make a lot of sense for that closing curly brace to be on line 88, then another one on line 91.

You might also, in trying to debug the code, switch to block mode, at which point it might be more obvious that the second if statement is nested inside the first one, and will ONLY be checked if the first condition is true.

Regards,
Elizabeth

1 Like

Hi Elizabeth!

Thanks (again) for your time and advice. You are an awesome “teacher” teacher :).

Maureen

2 Likes