New course! Every coder should learn Generative AI!
Try a free lesson0
Hm...
I made 31.2 code repo and I don't think everything is going like it should going. (The red ball is getting stuck when I'm to fast clicking on jump button) https://code.sololearn.com/WE7dBLPmRskU/?ref=app
2 Answers
+ 1
I think the problem comes from these two sections together:
if (y >= 350 || y < 100) {
direction *= -1;
}
function() {
count += 1;
y -= 25;
}
If you tap "Jump" when the ball is close to the top, y can get < 95. So direction gets reversed. The next move - 5 pixels down - can't get y over 100, so direction gets reversed again. And so on, so the ball can't move.
One solution would be, instead of reversing, setting the direction - when hit the top, set direction down, and vice-versa.
0
Oooooookaaay... 😕 I don't understand much 🙃