Scratch parrot shoot game
-
Upload
mrsharma2015 -
Category
Education
-
view
660 -
download
0
Transcript of Scratch parrot shoot game
Scratchan introduction
Year 6
What is Scratch?
With Scratch, you can program your own interactive stories, games, and animations.
It helps you to learn to think creatively, reason systematically, and work collaboratively — essential skills for life in the 21st century.
Scratch is designed especially for ages 8 to 16, but is used by people of all ages. Millions of people are creating Scratch projects in a wide variety of settings, including homes, schools, museums, libraries, and community centres.
Parrot Shooter
This is a nice little game to start off with. You will be taught to make parrots fly on random paths, then shoot them and make them disappear.For good measure you will be shown how to keep the score and set a timer to shoot all the parrots within.
Stage 1
Making the parrot move simply and then "randomly"
Open Scratch and you will see the following window with a brief note on the various functions.
Sprite PreviewSprite Editor
Sprite Selection and Creation
Tool Box
Tool Box is like a bucket of Lego; it
provides single script blocks for building combo
script blocks.
Tool Box
Sprite Editor
Sprite Editor lets you edit a Sprite’s Scripts, Costumes,
and Sounds.
Sprite Preview
Sprite Preview lets you preview a project.
Sprite Selection and Creation
Sprite Selection and Creation lets you select an existing Sprite or create a new Sprite.
As we all know cats do not fly so we need to replace the cat with, in this case, a parrot.Right-click on the cat and press delete.
See cats don’t fly!
It’s merely an optical illusion…
We now need to find our flying parrot so, click on the choose new sprite from file.
Double click on Animals in the new window that opens.
Scroll down until you find parrot1-a.
Click on it and then press the OK button.
As you can see the parrot is a bit too big for our game area (the white space around the parrot) and even Mr Moore could shoot something that big!
Select the Shrink sprite button. Move it onto the parrot and keep on clicking until the parrot is about the right size.
Now we need the parrot to fly around the screen. If we press the green flag then this would normally start our program script but, as we have not written any script yet, nothing will happen.
Make sure that the parrot, Sprite1, in the sprite selection and creation window is selected.
Go to and select the Control tab in the tool box area
then
drag the command to the Sprite editor in the Scripts area.
The next step is to get the parrot to move so, as movement is motion, select the Motion tab and drag the command into the scripts area and attach it underneath the command.
Hopefully you will begin to notice that certain commands will slot nicely into others if they complement each other.Just like a jigsaw puzzle.
Now press the green flag and see what happens to the parrot. Press it again,
Not very sensible to have to keep on pressing the green flag – especially when you are playing the game!
So, the next step is to make the parrot move forever.
In the scripts area uncouple the command from the
Click on the tab
Select the command and
Couple it with
Slot the under forever.
Now run your program by clicking the green flag.
Wow! That was amazing NOT!!!!
Now let’s get the parrot to bounce back should it hit an obstacle (i.e. the wall at the edge of the sprite preview window in this case).
Click on the tab
Towards the bottom select and slot this this just under
Press the green flag.
A bit better but the parrot looks as though it doesn’t know which way up to fly.
Let’s remedy this before we carry on. Stop the program script.
Above the Scripts tab there are three little command buttons just to the left of the parrot. Select the middle button that says only face left-right
Run the program
Before we carry on let us save what we have done so far.
1.Stop the program.2.Go to File and choose Save as from the drop-
down menu3.Click on the Computer tab on the left and
choose letter Y or 4.Choose Year 6, your class, your name and save
the program as Parrot Shoot Game.
Now we need to add some randomness into the game otherwise shooting the parrot would be too simple.
Let us look at some of the possibilities that we now have and choose the best one/s for our game.
Let us see what happens when we, say, change direction by 15 degrees after each 10 steps.
Make sure that the tab is selected.
Find
And slot it under
Run the program.
A bit better but our poor parrot seems to be going in circles. Not surprising as 15 degrees seems to be quite a lot.
Change the 15 degrees to 5 and see what happens.
Slightly better still but eventually the parrot ends up going in a predictable pattern – not good for games lovers!
boring
Now you change the move 10 steps to move 20 steps and see what happens.
Well, the parrot moves faster but, again, the eventual pattern is predictable. So let us now add some randomness into our parrot’s movements.
Randomness in computer programming uses the operators function. So, choose the green operators tab just below the control tab you have been using up to now.
About a quarter of the way down the list you will see the instruction.
Drag one of these into the box that says ‘20’ in the
Change the numbers 1 to 10 to 10 to 30
Do the same as before but this time for the command. Do not change the values 1 to 10 but leave them as they are.
Run the program.
Tea break (teachers only). Time to save your work and ask any questions about anything you do not understand.
Stage 2
Lots more parrots, a background and a target.
Having only one parrot in the game to shoot wouldn’t be very exciting so we are going to add some more.
The easiest way to do this is to right click on our parrot and choose the duplicate command from the menu.
Do this so that there are (say) 5 parrots on the screen. Move them about so they are not on top of each other.
Now, besides copying the graphic – Sprite 1 to Sprite 5
you will also notice that if you click on each of the sprites it has also copied the code. This re-use of code in computer programming is very import and useful.
Now run your program.
Lovely background! It’s not very often that you see parrots flying around the Arctic or Antarctic so we now need to choose a suitable background image.
The background aspect of our game is called the Stage.
Click on and you will see in the Scripts area that there is no code but, at the top, are three tabs click on Backgrounds
Underneath the Backgrounds tab you will see that you could, if you so wanted, Paint your own background, Import one that has been saved previously or even import one from your Camera.
Today we are going to import one that has already been saved.So, click on the Import tab.
Now choose the Nature folder and then select the Lake background.
Now we are going to need a target (cross-hair) with which to shoot our parrots. We could import one but instead we are going to paint our own.
Firstly - click on the Paint new sprite icon
Select the Ellipse tool.
Select Red as the main colour of your target.
As with most paint programs, to get a perfect circle you just hold down the key on your keyboard and draw at the same time.
Now we need to draw the cross-hair on our target by using the Line tool and choosing Black.
It should now look like this …
When you are happy with your target and crosshair click the OK button.
If your target is a little on the large size then shrink it down.
The next step is to get the target to move around the screen. There are many ways to do this but to make it simple at this stage we are going to use the mouse pointer.
In the Scripts area of the target drag in a command, go to the tab and then drag the instruction underneath it.
After the words go to there is a black down arrow. Select this and choose mouse-pointer at the top.
As soon as you have run the program you will notice that the target moves to the mouse-pointer only once and then stops.
Why do you think that is the case and what command do you think we need to use to resolve the dilemma?
Well, who suggested we use the Forever command?
Well done if anyone did. Now do it and run the program.
Coffee break (teachers only). Time to save your work and ask any questions about anything you do not understand.
Stage 3
Making the parrots disappear when shot and then bringing them back to play again.
Now we come to the actual shooting aspect of the game. The basic idea now is that when you shoot the parrot it disappears.
We will think about, later on, what to do when all the parrots have disappeared.
The first thing we need to decide on is what key to use on the keyboard to shoot the parrot to keep things simple we will use the …
Click on the first parrot, Sprite1Select the tabFind the command and place it somewhere underneath your previous script
We now need to think carefully about what we want our program to do. Simply, we want the parrot to disappear (hide) when the spacebar is pressed and the parrot is touching the target.
So, our code should recognise that when the space bar is pressed,
if the parrot is touching the target, then it disappears (hides).
Select the tab andDrag the command onto
Now select the tab andDrag the top command, , into the space after the if command
Now we need to decide what the if command refers to. Simply, if the first parrot (sprite1) is touching the target (sprite 6 in this case) then that parrot will disappear (hide).
So after touching we need to choose Sprite 6 from the drop-down list.
The final part of this line of code is to tell the parrot to disappear (hide) if it is touching the target when the spacebar is pressed.
Select the tab and drag the instruction into the blank space under the if command.
Run the program and try it out.
Well, we have sorted out what happens to the Sprite1 parrot but we need to do the same for the other 4. Luckily we are able to use the same coding for Sprite1 for the other 4 Sprites (parrots).
Make sure Sprite1 is selected…
Now follow these instructions VERY carefully!
In the Scripts section of Sprite1, click on the
instruction and DRAG it on top of Sprite 2.
Sprite 2 should have a GREY GLOW about it when you let go of the commands you want to copy.
Do exactly the same for the rest of the parrots
Check to make sure that the same lines of code have been copied across to all the parrots by selecting each of them in the Sprites window.
Run the program and play the game.
Some of you may have noticed that even when you have shot all the parrots they are still flying in the background
Look here to see each of their movements.
We haven’t killed the parrots – we’ve just hidden them.
So, how do we get the parrots back again once they have been hidden?
Simple.
Select the first parrot (Sprite1) and from thetab drag in another command.
From the drop-down menu arrow after space choose the letter a.
Now we want to show the parrots once the letter a is clicked on the keyboard so go to thetab and join the piece of code to
Now copy the new code to the other 4 parrots and run the game using the a key to get them all back.
Bathroom break (teachers only). Time to save your work and ask any questions about anything you do not understand.
Stage 4
Setting up the scoring system.
When designing any game it needs to decided at the outset what the scoring system is to be.
For our game we are going to say that …
• Every time you press the spacebar you lose 1 point
• Every time you hit a parrot you get 10 points
• Maximum score 50
The first thing we need to do is to create what is called a variable.
Make sure that Sprite1 is selected.
Then click on the tab.
You will see underneath the variable section there are only two options…
Click on Make a variable and give it the name score
Leave the For all sprites button selected as this variable will apply to all parrots
Hopefully, those of you who are looking carefully will have noticed that a score board has appeared in your play area.
Earlier on we said that every time you press the spacebar then you lose 1 point. So, we need to modify the code structure …
As soon as the player presses the space key we want 1 point to be deducted so we need to split the code when space key pressed and if touching Sprite6
If you are limited for space between each
block of code then move them down the screen
like that to the right.split code
Under drag a block
For the mathematicians amongst you, you will notice that we are adding 1 each time we press the spacebar rather than taking 1 away. So, change the 1 to -1.
The next part is similar to the above. If you remember we said earlier on that Every time you hit a parrot you get 10 points so we need to change if touching sprite 6 code as well.
Under the hide piece of code we now need to add the same piece of code as previously but this time adding 10 each time. It should now look like this once the code blocks have been joined back together again …
This part is intentionally to show you what happens when you do not do your initial planning correctly.
This is just the same as what happens in planning a Science investigation or a design and technology activity.
Bad planning means EXTRA work! Coding is no different and can add many hours of time to computer programming if the project is not minutely planned from the outset.
The code we have just amended now needs to be copied into that of the other 4 parrots. BUT, we already have the old code still in each of them.
So you will have to go to Sprites2, 3, 4 & 5 and delete the old code by dragging it to the window on the left.
drag out old code
Now you need to copy the new code from Sprite1 into the other 4 parrot sprites.
drag new code
Now play the game. What do you notice about the score every time we press the space bar?
Hopefully you will have noticed that the score doesn’t drop by 1 but by 5! This is because we have the same command for each of the 5 parrots which means if we press the space bar we lose 5 x 1 off our score.
To remedy this change the to -0.2 each time and do this for all parrots
Nearly there!
Now some of you will have noticed that when you restarted the game it carried on where you left off!
The next step is to return the scoreboard to zero when a new game is started.
Make sure that the first parrot is selected (Sprite1)
Split the and code blocks
and drag in the variable to fill the space
between them. Reassemble into one block.
Finally some of you will again have noticed that every time you make a hit the score only goes up by 9 and not 10 as programmed. This is because you do gain 10 but also lose 1 for using the space bar!
To make the game fair change the
to
Do the same for all 5 parrots.
Now play the game.
Game too fast for you?
Look at the coding and see which of the code blocks you could change to slow the parrots down.
Answer on next slide for those who are unable to work it out.
Exercise break (teachers only). Time to save your work and ask any questions about anything you do not understand.
Stage 5
Making it tough with a timer. Can you work out how to get the "game over" message up?
Last bit! This time we want to make the game even trickier still.
We are going to make it so that the game finishes after 20 seconds!
This means that you only have 20 seconds to gain a score of 50 or more!
To get the game to finish after 20 seconds we need to use a timer. There is a timer under the Sensing tab but this is not suitable for our game. This timer just keeps on running from 1 onwards.
We need a timer that will count down from 20 to zero and then stop the game.
The first thing we need to decide on is where to put the timer. In this case it is more convenient to put it with the background (stage).
So, click on the stage icon where you will find no scripts at the moment.
We are now going to use another variable so click on the tab and choose .
When the dialogue window opens name the new variable clock then press OK.
You will now see the clock appear under the scoreboard in the players window.
If you do not want to have the clock shown then deselect the clock option in the variables panel on the left.
Alternatively, drag the clock to the right-hand side of the players window (or wherever else you want it)
Coding for the clock.
What we want to happen when the game starts is to set the clock to 20 so that it will countdown until zero.
Drag in the command under the
tab and then, under the tab
drag in and change the zero to 20.
Now, as we have not thought through this aspect of the coding in detail, we are going to follow our instincts to what has to be done next (not the right way to do it but hopefully we will learn by our mistakes next time).
We want the clock to count down 20 times until it reaches zero.
To do this we will now add in the command from the tab and change the repeat value to 20
Under the repeat 20 instruction we want to add the command found under the tab.
As we are counting down we need to change the variable to -1
Now run your program and watch the clock. Did you see how fast it went? It counted down really fast. What we forgot to do was to tell the clock to wait 1 second after each repeat command.
So, go to the tab and insert the line of code. Where do you think it goes? Have a go.
If you put the instruction under the line of code you will notice that the clock immediately takes 1 off. What you need to do is put the instruction just before the line of code.
Run your program.
This is the final stretch of coding for the Shoot the Parrot game.
If you remember a few slides back we wanted the game to stop when the clock reached zero.
If you run the game watch the clock and see what happens when the clock reaches zero.
This should only take you 20 seconds – I wonder why…
As you will have noticed, nothing happened. The game just carried on. What we want to do now is to sort out some code so that when the clock reaches zero the game stops.
This is very simple. Go to the tab and insert the command at the very end.
So you have it. Your very own Parrot Shoot Game.