Lesson 27 - Complex Movement Problem

My student is trying to get a complex movement in by making the shark accelerate so that it is moving faster than the other sprites but it doesn’t seem to be working.

Hi @dcraig,

I played the game and it was fun!! Perhaps you and your student figured it out? The shark does speed up when score is greater than 10 as coded. The shark starts at velocityx of -5 and then goes to -9 and the food velocityx goes from -5 to -8 I believe). I did modify and changed the Shark VelocityX to -15 and this did make it much more obvious that the shark was faster than the food. Hope this helped.


Thank you. He must have been playing around with it after I posted the question.

Is there a way to make the shark accelerate over time just not at a constant speed?

Good Morning, @dcraig,

You have to use velocityX if you’re going horizontally or velocityY if you’re going vertically.


@pluto is correct. velocityX and/or velocityY does make the Shark progressively accelerate but in your students code, the shark’s speed is constantly being reset back to -5.

One reason is that the first if statement (that sets the shark’s velocityX to -5) is always evaluating to true because the score is always >=0. A way to fix this is to set the first if statement to Score >=0 && Score <10. This way, when the score exceeds 10, only the FasterShark() will run.

Another reason is that in the 2nd if statement, there are 2 functions (FasterShark() and SpriteMovement2()) that impact the shark’s speed so I would remove the shark’s speed from SpriteMovement2() and any other function or condition impacting the shark’s speed.

Hope that helps,

1 Like