I'm making a paddle ball game on Scratch (just for fun), and I'm running into a problem with my scoring. If you want to look at the code I already wrote, the link to the game is https://scratch.mit.edu/projects/66541388/ . For some reason, when the game is played the score variable does not actually always change by one. It changes by a different number every time I test it. Any ideas on what the problem is or how to fix it?
Here's the core of the code:
when green flag clicked
set [Score v] to [0]
set x to (0)
set y to (0)
point in direction (pick random (-90) to (90))
forever
if <(y position) < [-146]> then
broadcast [gameOver v]
stop [all v]
end
if <touching [Paddle v]?> then
change [color v] effect by (pick random (1) to (1000))
change [Score v] by (1)
point in direction (pick random (-90) to (90))
end
move (10) steps
if on edge, bounce
end
urnotsam's answer is technically correct, but i'd like to give some reasoning behind it and an alternate solution.
The problem lies in the fact that a penguin is not a square. When you hit the paddle, it turns to a random direction, and moves 10 steps. Now, if it started out facing sideways, and the random direction is also pretty much sideways, it can escape with those 10 steps. Same if both are straight up. But if it starts sideways and ends straight up, it's now further below the line than it had been, and even after moving 10 steps, part of it is still touching the paddle. It seems to me that giving it a head start of another ten or twenty steps should let it escape, and not mess up your scoring.