Theory
🐱 8. Dodge the stars
Ripley the astronaut has to watch out for falling stars when he’s flying through space. Can you use some loops to help him out?
Step1:
👉 Bring in the Ripley sprite and Centre him on the bottom of the stage.
🌟 Bring in the Star sprite three times to get three different star sprites, or right-click the star icon and choose duplicate. Arrange them in a row across the top of the stage.
Step2:
👉 Go to Ripley’s script editor. 🚀 Start the script with a when flag clicked event block, add a go to x: () y: () motion block to set his start position, and then include a wait (1) seconds control block.
🖱️ Add a forever control block and place a go to (random position) motion block inside it. Instead of choosing random positions, select “mouse-pointer.”
🧪 Experiment by removing the wait (1) seconds control block to see how Ripley behaves without it.
Step3:
👉 Go to the first star’s script editor.
🚀 Start your script with a when flag clicked event block, add a show looks block to make it visible, and then include a go to x: () y: () motion block to give it a starting point.
🌟 To make the star fall, drag it straight down until it’s at the bottom of the screen, updating the motion code blocks with new coordinates. Then add a glide () secs to x: () y: (__) motion block to your script.
Step4:
🌟 To make the star look like it has fallen past Ripley, add a hide looks block.
⏱️ Then, include a wait (__) seconds control block.
🔄 Finally, place all of the code inside a forever control block so that it will constantly repeat. This wait helps create the effect of a new star falling from the top of the screen, ensuring it doesn’t appear to jump back up.
Step5:
🌟 Go to Star2’s script editor. ⏱️ Move the wait (__) seconds control block to the top of the script instead of the bottom.
🔄 This adjustment allows Ripley more time to move out of the way before the star begins to fall, ensuring a more random timing for Star2’s descent.
Step6: Code Complete
🌟 Try following the same strategy for the last star, Star3.
⏱️ Change the wait (__) seconds control block to two seconds for Star3 to have different timing.
🎯 This adjustment ensures that the falling stars feel more random, making Ripley’s dodging more challenging.
Ripley’s Code
Star code
Star2 Code
Star3 Code
🌟 Adjust the waits in your star movements to add more randomness. 🚀 Add more sprites for Ripley to dodge, increasing the challenge.
🏃♂️ Make one of the new sprites shoot across the stage from left to right instead of falling from the top of the screen.
🔄 Loops are like doing things over and over, just like eating popcorn: pick up, eat, chew, swallow, repeat!
🔍 Loops help save time and make code shorter, plus they’re crucial for checking conditions continuously, like scoring when the ball goes into the basket. Get ready to use loops more in the next chapter when we dive into variables!