Moving a sprite all over a screen

I have a student who is working game lab. He has a sprite (basketball hoop) that moves up and down on the Y axis for the first screen. When he moves to the second screen, the sprite (basketball hoop) should move up and down and side to side. What is missing/are we doing wrong?
Link to the project or level: Game Lab - Code.org
What I expect to happen: The basketball hoop moves up and down one side of the screen on the first background. On the second background, it should move up and down and side to side.
What actually happens: It moves correctly in the first background. On the second background, the sprite moves across the screen to the left and then just stops and shakes in the top left side of the screen.
What I’ve tried: We tried messing with the x and y velocities.

Hi @stephanie.hodgson,

Fun game:) There are a few issues.

  • The hoop.velocityY has multiple instructions that are conflicting. If the score is > 10, the hoop.velocityY stays at 2 but the movement() function says it should adjust to -2 when hoop.Y is greater than 350. Since score will always stay >10 - it is conflicting instructions. I do not think you need any of the hoop.velocityY instructions in the background1() function.
  • The same goes for the hoop.velocityX instructions in the background1() function since the score from that point on will ALWAYS be >10. You do not need hoop.velocityX = -2 on line 54.
  • So, how do you get the hoop to begin moving in the x direction? When the score reaches >=10 in the background1() function, you assign the variable level to 2. You should use this! In the movement() function, add a conditional statement that says hoop.velocityX should only exist if level==2. You can do that with a nested if or as:
    if (hoop.x >=320 && level==2) {
    hoop.velocityX = -2;
    }
    if (hoop.x <50 && level==2) {
    hoop.velocityX = 2;
    The and blocks are in the math section: image

Hope that helps.
~Michelle

Thank you so much!
That worked!
Stephanie