Presentation is loading. Please wait.

Presentation is loading. Please wait.

Code Club Session 3 Shark Eats Fish. Picture of finished product here.

Similar presentations


Presentation on theme: "Code Club Session 3 Shark Eats Fish. Picture of finished product here."— Presentation transcript:

1 Code Club Session 3 Shark Eats Fish

2 Picture of finished product here

3 What will we learn ?  How to move a sprite  What is an “if” statement and what the “not” operator does  How we can use co-ordinates  How to make one sprite react to another sprite  How to use variables

4 First create a new project  Click “File”, then click “New”  Now save the new project  Click “File”, then click “Save As”  Click “X:”, click “OK”  Click “Computer Club” – you may have to scroll down, click “OK”.  Click “Shark Eats Fish”, click “OK”  Finally type your name in the “New Filename” box and put the words “Shark Eats Fish” afterwards.  For example “Mr Steele – Shark Eats Fish”

5 Backgrounds  Click the stage icon in scratch, it is the white box on the bottom right of the screen.  Now click the “Backgrounds” tab.  Click “Import”, select “Nature” click “OK”  Scroll down till you find the picture “underwater”  Select this one and click ok.  Now delete the white background, click the “x”

6  We are now going add 3 costumes for our shark  Click “Sprite1” the cat. Take this opportunity to rename it “Shark”  Now click “Costumes” then click “Import”  Select “Animals”, click “OK”  Scroll down and select the image “shark1-a”  Repeat the process selecting “shark1-b” and “shark1-c”  Delete the cat costumes if you still have them. Costumes

7  We are now going to select some sounds  Click “Stage”, then click the “Sounds” tab  We are going to keep the “pop” sound that should already be there but add 2 new sounds.  Click “Import”, select “Effects”, then click “Bubbles” and click “OK”  Click “Import” again, this time select “Rattle” and click “OK”  Now we need to make our sprite smaller.  Click the shark sprite  Then click the “Shrink Sprite” icon, once you have click then click the shark to make it smaller.  Don’t make it too small.  Click “File” then click “Save” Final setup

8  We are going to make the shark follow the mouse pointer.  Click the “Shark” sprite, select “Scripts”  From the control menu pull down add the following commands.  Try this now – what happens ? Moving the shark

9  Next add the command “Move 2 steps” into the “Forever” loop.  What do you think will happen ? Moving the shark  As you can see the shark looks like it is swimming upside down !  To fix this click the “only face left-right” icon  Try again

10 Fixing bugs  What happens when the shark catches the mouse pointer ?  We call this a bug. The program is doing something we don’t want it to, so we will fix it.

11 The “If” statement  We are going to use something call an “if” statement. We use this lots in computing.  We say. If (condition is true) { Do something }

12 If statement continued  Our “if” statement looks like this.  To fix our bug we want to only move “if” the shark is “not” touching the mouse pointer. If (shark is not touching mouse pointer) { Move 3 spaces }  Important: The “not” keyword reverses our logic. If we use this operator then we change a condition from true to false, or from false to true.

13 If statement continued  Change the script to look like this.  Notice that we use the green “not” operator. This has the effect or reversing the condition in blue (touching mouse-pointer).  Try running this again

14  Whenever we start we always want the shark to appear in the same position and have the same costume.  Add the following commands. Setting up the shark  Make sure you choose shark costume 1-b. This will make it look like it is trying to eat our fish !  We position the shark at the co-ordinates 0,0 what does this mean ?

15  Everything on the stage has a pair of co-ordinates  As you move your mouse pointer around the screen you can see the co-ordinates change depending where you are pointing.  0,0 is always the middle of the screen Coordinates

16  Before we forget lets add some sound  Click the stage and add the following commands. Background sound  So now we have our shark that swims, we have a good background and an appropriate sound effect.  Click “Save” again

17  So far we have found out how to make sprite move in the direction we want it to.  First we point it in the correct direction  Then we issue a move command  We fixed a bug and learnt about the “if” command and the “not” operator.  We have also learnt about co-ordinates and how we can use them to move a sprite to a preset location.  We will learn more about co-ordinates as we proceed. Quick Review

18 Adding the fish  We will first add the fish and make it swim across the screen.  We are going to control the fish with an event, this is important because when the fish is eaten we want to be able to make the event fire again.  First add a fish, select “New Sprite From File”  Select, “Animals” the “Fish2”  Make the fish smaller as you did before.

19 Making the fish swim  We will use an event to make the fish start to swim. This will let us call this event again in the future when the fish has been eaten.  Click the “Stage” and add the following event.  Now click “Fish2” and add the following script.  Now click the green flag and see what happens.

20 Let the fish be eaten  We now add logic so that when the shark touches the fish then the fish disappears.  First click “fish2” then change the script so that it reads as shown.  Notice that we hide the fish “if” it is touching the shark. We also broadcast another event “Fish eaten” which we will use in the next slide.

21 Make the fish come back again  When we eat the fish we want to show it again. We can use the “show” command for this.  Notice that we wait 2 seconds.  Then we broadcast the “Fish2 swim” event again.  We then start the logic from the top again, we “show” the fish and move it to a random position.

22 Adding effects  First we will add an effect whenever the fish has been eaten.  Click the “stage” and add the following script.  Try this. What happens ?  Now we will add a shark animation whenever the shark eats the fish. Click the shark and add the following script.  Try this. What happens ?

23 Keeping score  We want to keep score in our game so we need to use a variable for this.  First create a variable. It will be called “score”.  Click “Variables” then click “Make a variable” call it “score”.  Variables are containers that can hold things. We want this container to hold our score.  Next click the stage and update the scripts so that they look like this.  Now, when we start a new game we set the score to 0.  When ever a fish is eaten we increase the score by 1.

24 Setting a time limit  We will use another variable to keep track of the time and to stop the game after the time runs out.  Create another variable, this time call it “countdown”.  Add the following script to the “stage”  This script sets out “countdown” variable to 15.  Then we repeat the value of our variable (15) and wait for 1 second for each time we repeat.  We also take 1 away from the value of countdown. We use the value of -1 which is the same as saying : countdown = countdown – 1  Finally we run “stop all” this stops all the scripts.

25 Final Challenges – Game Over Message  If you have time add a game over screen.  Take a copy of the underwater picture, add the words “Game Over”.  Now make the picture appear when the game is over.  Make sure that the correct picture appears when the game starts again.

26 Final Challenges – Final Score Message  Get the shark to award you a medal at the end of the game based on your score.  Use the say command and “if” statements. If you score between 1 and 5 then say “You got bronze” If you score between 6 and 10 then say “You got silver” If you score higher than 10 then say “You got gold !” If you score 0 say “You need to try harder


Download ppt "Code Club Session 3 Shark Eats Fish. Picture of finished product here."

Similar presentations


Ads by Google