Goal:
Now let’s code where the rocks will reappear on the game screen after it has touched the Shark.
We want the rock to spawn between 100 and 200 units away from “Sharky:”.
We do this because if we don’t, there is a chance that the rocks can spawn inside “Sharky:” and it would be very unfair if that were to happen.
Once the rocks have picked a random spawn point away from the shark, then it will appear once more on the game screen.
Steps:
- Stay on the “Rocks” sprite.
- Underneath the last if statement, from Control place a wait 1 seconds block.
- From Variables place a set to block and change it to newX.
- From Operators, place a pick random block.
- From Operators, place a + (addition) block to each side of the pick random block.
- From Sensing place a distance to block to the left side of each + block.
- On the first + block, set the right side to 100 and on the second + block set the right side to 200.
- Now use your mouse to hover over the set newX block and right click on the mouse. A drop down menu will appear. Click on duplicate. Set the duplicated code underneath the set newX block.
- Change the duplicated set newX code to set newY.
- From Motion, place a go to x/y block.
- From Variables, place a round newX block and a round newY block into the go to x/y block.
- From Looks place a show block.