Unit 3, Lesson 14: Movement Help

I want to get the program to have the smiley face to fall down the screen once it is triggered by the shake count. Right now, the smiley is triggered by the shake count, the smiley moves down the screen just fine. I want it to go back up once it hits a certain spot (y=350). I can’t seem to figure out how to do this.

I want the smiley face to go back up when it hits the bottom of the screen.

Nothing happens. Each time I try to send the smiley back up it gets stuck at the bottom or the smiley starts to move up at the beginning.

I have also tried this: https://studio.code.org/projects/gamelab/plXna1ye1pslvbuIrzPm7zdq672SvM_ppaiQgyq0gyY and it just keeps getting stuck at the bottom.



You’re on the right track! The problem you run into is because when the smiley.y is above 0, it moves down, but once you get to 350, you want to have it start subtracting (move up), so it moves to 348, but then it’s above 0, so it jumps back to 350 and then it moves down to 348, etc. This makes it appear to not move at all) as it moves between 348 & 350 on the screen.

What I might suggest is to add a variable. (I called mine “direction”). I give it a starting value of “down”.

Then I run the code as you have, but I add a few more conditional blocks. I only let it add to smiley.y IF the direction is “down”. Once it hits 350, I change the direction to “up”. This will stop it from moving. Then I have another conditional that says if direction==“down”, have smiley.y subtract 2.

This creates a “switch” so the two codes don’t fight each other.

Give it a shot and if you can’t quite figure out the order of the codes/blocks, let us know and we can help you get a little closer to what you are looking for.

Hope this gets you on the right path.