School Logo
  Home       Parents       News       Pupils' Work       MA&T Programme
   

You are here MA&T Scratch Shark Attack!

Shark Attack!

First script for the Shark

We start by creating a variable called 'score'. We then set the score to zero.

As the shark is too big we set the size to 40%.

We then set the shark sprite to point towards the 'mouse-pointer' (it will follow wherever the user moves the mouse) if the distance away is greater than 5 - this prevents the shark from flickering when it sits on the mouse as it won't be trying to move towards it.

 

 

First script for the yellowfish

 

Again this sprite is too big so we set the size this time to 20%

To give the appearance of swimming around we tell the yellowfish to randomly turn from between -10 and +10 degrees and to move 3 steps.

We also include the line 'if on edge, bounce' to prevent the yellowfish from disappearing.

 

 

Second script for the yellowfish

We now write a script that when the yellowfish touches the shark it will play the sound 'pop' and change the score by 1.

We will later tell the yellowfish to hide so it appears that the shark has eaten it. We place this script into the forever loop as shown in the diagram below:

   
Third script for the yellowfish

 

This script hides the yellowfish and then it will either come in on the left hand side or the right hand side.

If it picks 1 it will come in at x:-240 and at a random spot up or down or if it picks 2 it will come in at +240 at a random spot up or down.

You add this script into the rest of the script already written as displayed in the diagram below:

   
Fourth script for the yellowfish

We now want to get the shark to open and close its mouth when it eats the yellowfish.
We do this by using a 'Broadcast' command. This is a way of communicating between sprites. It sends information to the 'When I receive' command - telling it to do something.
Place the 'broadcast' command into the script as shown in the diagram below:

   
Second script for the shark

Now we include a 'when I receive' command in the script for the shark. The shark will open and close it's moujt 3 times - done by switching costumes
We can now just duplicate the 'yellowfish' sprite and all the copies will behave the same way.
We now change one of the 'yellowfish' and replace it with a 'redfish' - by changing it's costume. (Then delete the original costume) - it will still hold the same script - so we will change some small parts of it next. We change the 'broadcast' to 'sahrktouchingredfish' and then write a script for the shark to listen to the broadcast.
We have included the instruction to 'play sound' & to change the shark costume for effect.