Our next game is a Chase game where one character will try to protect itself from another character that is following it.
So our first step is adding in our characters. For this scenario, we choose a diver and a shark with our background as the underwater scene.
Now we need to code our diver to move according to us.
We want the diver to move when we press the direction keys. To do so, we first take a “when space key pressed” Event block and change the key to “down arrow key”. Then we add in a “move 10 steps” as well as a “point in direction 180” Motion block. This will change the direction the diver is pointing down when we press the down arrow key and move the diver 10 steps downwards. We change the direction by clicking the textbox in the “point in direction” block and dragging the arrow to the desired angle.
Similarly, we make the code for the rest of the direction arrows. We keep the number of steps the same but change the direction each time. For the left arrow, the direction should be “-90”, “0” for the up arrow, and “90” for the right arrow.
Now we need to code the shark. The shark needs to keep moving towards the diver. So we first take the “when green flag clicked” block, add a “say ___ for 2 seconds” Looks block to make it more appealing, and set its starting position by using the “go to x:__ y:__” block and setting x to “-175” and y to “145”.
The rest of our code should be continuous so we add a “forever” block, a “move 2 steps” and a “point towards Diver1” block.
Next, we put in the code for what happens if a shark touches a diver. We put in an “if__ then” condition block from Control and input the condition “touching Diver1?”. Once the condition is true, we will make the shark send out a message to diver1 to let it know that it has been caught. We do this by adding the “broadcast message1” Events block. Then we join a “say MUNCH!!” Looks block and a “stop all” Control block. Change it from “all” to “this script”.
And just to make the game more attractive, we are going to have the sound of ocean waves playing forever. We take a new “when green flag clicked” and “forever” block and join a “play sound water until done” from Sound.
For the last part, we have our diver receive the message sent by the shark. We do this by using the “when I receive message1” Event block and the “say AAAAHHHHH” Looks block. You can also add in a Sound block for a scream.
This Post Has 10 Comments
Your article helped me a lot, is there any more related content? Thanks!
Glad to hear it was helpful! For more related content, feel free to reach out at hello@makersmuse.in.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Thank you for your feedback! Please feel free to reach out with your doubts at hello@makersmuse.in, and we’ll be happy to help.
Your article helped me a lot, is there any more related content? Thanks! https://www.binance.com/ro/register?ref=V3MG69RO
Thank you for your kind words! We have more related content available—feel free to reach out at hello@makersmuse.in for more information!
Hello, Neat post. There’s a problem with your site in web explorer, could test this… IE still is the marketplace leader and a big portion of other people will omit your magnificent writing due to this problem.
Thank you for your feedback! We’ll look into this issue—feel free to reach out at hello@makersmuse.in for further assistance.
I truly appreciate this post. I¦ve been looking all over for this! Thank goodness I found it on Bing. You’ve made my day! Thanks again
Thank you so much for your kind words! If you have any questions, feel free to reach out at hello@makersmuse.in.