Here's the code:
Using the function is pretty straightforward -- we simply call it, passing in as parameters the x, y and image variables for the bug and the melon. The function returns a true/false result, and we use that in an if statement (remembering to use an extra set of parentheses).
If the two images are found to be touching, we add one to the score.
Recall that in Scratch, we had to hide the sprite otherwise the score would rocket upward as the melon passed through the bug? Well, it's the same here. A simple way to hide is to move into a non-visible part of the canvas, so we set its x-position to a negative value -- we move it as far off screen as it is wide: we set it's x-position to it's negative width.
|