Sprite Only Moving Randomly in one direction - Help With Project Lesson 25

My student is having a problem with his code for Lesson 25, level 13 C. His sprites just move up and down (He did set them to move randomly). They will not move in any other direction. We have tried setting sprite.x to various values but they either disappear or continue to move up and down only. His crown can collide with the sprites and the score will increase. Can anyone offer assistance as to why his sprites will not move across the runway area?

Link to the project or level: Game Lab - Code.org


Good morning! I think I have located the source of the problem. Each time the set.enemy functions are run, they reset the sprites to x=0.

If you think about when that SHOULD occur, it is when the enemies are pushed into the water and at the very beginning of the game.

Your student does have code to address both of those occurrences, but he also has code inside the draw loop (lines 32 & 33), that automatically resets the enemies every time through the loop. Does that need to be there?

Also, once he fixes this, he may find another issue that the enemies are displaced before they get to the player sprite. This is because the player sprite has a lot of blank space around it in the animation tab. Your student may want to crop all of the extra space around the player to prevent this from happening. There is a crop button on the bottom right of the window that will help with that.

Good luck!


Thanks, Mike! Once he took the set.enemy functions out of the draw loop on lines 32 & 33, he was able to fix the rest of the program. He is a happy young man today!

Thanks again,