Programminghandout

Page 1

th

NQT Day 14 Feb 2013 Creative Programming: Early Years to Key Stage 2 and beyond


IoE NQT Day – 14th February 2013

Create a simple racing game with: ‘Scratch’ programming software 1. Open the ‘Scratch’ software. At home you can download the software free from the Scratch website http://scratch.mit.edu which also has a great support section with free guides/tutorials. 2. The default ‘Sprite’ or character is the cat. You can paint your own Sprite or choose a ‘new sprite from file’. For this simple racing game paint your own racing car ‘Sprite’. 3. In the same way you can create the ‘Stage’ or background and paint a racing track. Make it simple with enough space for two cars to race and a starting line. 4. Once you have drawn a car it is time to program it. We will focus on Control and Motion. Motion (dark blue): Click on each motion individually and drag it to the ‘Script’ to program your car to move forward or to turn. For example: ‘when space bar is pressed move 1 steps’. One ‘step’ is a very small movement on your stage and you can edit this. Control (Yellow): Control determines how the sprite starts a sequence of motions. In this example pressing the green flag will start the sprite moving. You can assign any keyboard key as a ‘control’ key as well. Control also programs for how long something will happen for example ‘forever’ or ‘move 1 step’. When your race is finished you can drag your Sprite to a different place on the stage and start again (or write a program to get the car back to the starting line – see final block of script on the right of this page). Looks (Purple): If the car goes off the track and is ‘touching colour,’ it can change its look to another costume in this case costume 2 (which is the same car/costume edited with red flames added to look as if the car has crashed). 5. Once you have programmed one car you can then ‘duplicate’ the car (complete with its program) and amend the programmed controls so two people can use one computer keyboard to race. TIPS:   

To remove any of your program blocks drag them back to the left hand side menu. If your Sprite disappears off the ‘Stage’ right mouse click on the mini picture below the stage and click on ‘Show’. To adjust the size of the ‘Sprite’ Select the shrink or grow icons and click on the Sprite to change.

Thank you to Rob Easton for showing me how to make this racing game. There are more of his excellent Scratch video tutorials: http://www.teach-ict.com/programming/scratch/scratch_home.htm

© IT Services, Institute of Education, University of London, October/2011


Scratch: Geometry and art – a few useful things to know 1. You can program your sprite to draw using the green ‘pen’ blocks. You can program a ‘clear’ command too – very handy… There is a good link here with programmable toys such as beebots.

2. Creating shapes using the ‘move steps’ and ‘turn degrees’ block can consolidate mathematical concepts very well. Square

Equilateral triangle

Circle

Can you make a hexagon?

3. If you introduce the ‘repeat’ command, you can have all sides of a shape drawn in one go eg a ‘repeat 3’ can be used to create a triangle.

4. Once you’ve made your shape, you can start developing patterns by adding ‘change x’, ‘change y’ and ‘turn degrees’ blocks to the program.

© IT Services, Institute of Education, University of London, January/2013


Create a simple animation with: ‘Scratch’ programming software 1. Import or paint at least two ‘Sprites’ for your animation.

2. Use a knock knock joke for a simple dialogue between the two characters. 3. ‘Glide’ in Motion allows your character to move to a specific place using x and y co-ordinates. 4. Use ‘Wait’ in Control to control the pace and ‘Say’ in Looks to create some written dialogue which will appear in speech bubbles. You can also record your own dialogue using a microphone using ‘Play sound’ in Sound. 5. ‘Broadcast’ in Control allows the other character to ‘receive’ the dialogue. By using a combination of ‘Broadcast’ and ‘When I receive’ the dialogue can develop. 6. ‘Switch to costume’ in Looks allows you to change the way the characters look and their expression (after hearing the joke). Some of the characters in the Scratch clipart have pre-created ‘Costumes’ to make this a lot easier.

© IT Services, Institute of Education, University of London, Jan/2013


Level

1

Whack-a-Witch

Introduction: This project is like the game Whack-a-Mole. You get points for hitting the witches that appear on the screen. The aim is to get as many points as possible in 30 seconds!

Activity Checklist – Follow these INSTRUCTIONS one by one

Test Your Project – Click on the green flag to TEST your code

Save Your Project – Click on this to SAVE your work

1


Level

1

Whack-a-Witch

STEP 1: Create a flying witch Keep track of your progess by ticking off the boxes below:

Activity Checklist 1. Start a new scratch project. 2. Remove the cat sprite and replace the background with the nature/woods background. 3. Use the new sprite from file button to add a new witch sprite to the project (use the fantasy/witch1 costume). Now we want to make our witch move 4. Add a Variable for this sprite only called speed . On the Stage, the stage monitor for this variable should say “Sprite1 speed”. If it just says “speed”, delete the variable and create it again, for this sprite only. Uncheck the box next to the speed block in the Variables palette so it does not show on the Stage. The speed variable will control how fast the witch moves. We use a variable so that we can change how fast the witch moves as the game progresses. 5. We want the witch to start moving when the game starts, so make a script like this:

Test Your Project

Click the green flag and see what your witch does. Why does she get stuck on the edge of the screen?

2


Level

1

Whack-a-Witch Keep track of your progess by ticking off the boxes below:

6. To stop the witch getting stuck we need to make her go back the other way when she touches the edge of the screen. Below your move speed steps block add an if on edge, bounce block.

7. To stop the witch flipping upside down, click on the only face left-right button in the Sprite Summary area:

Test Your Project

Click the green flag. Does the witch move from side to side across the screen?

SAVE YOUR PROJECT

Things to try • Try changing the value of the speed variable to make her fly faster or slower. • How would you make the witch get faster the longer she flies? (This is a tricky one, so don’t worry if you can’t see how to do it. You’ll get more clues as you work through the project.)

3


Level

1

Whack-a-Witch

STEP 2: Make the witch appear & vanish randomly Keep track of your progess by ticking off the boxes below:

Activity Checklist To make the game more fun, we want the witch to appear and vanish randomly. We’ll do that with another script that runs at the same time as the one that moves the witch. This new script needs to hide the witch for a random time, then show her for a random time, and repeat that forever (or until the game finishes). Create this script for the witch:

Test Your Project

Click the green flag. Does the witch move from side to side across the screen and vanish and appear again randomly?

SAVE YOUR PROJECT

Things to try • Try changing the range of the random numbers. What happens if you pick very big numbers or very small numbers? (Does this give you any more clues for how to make the witch speed up the longer the game is played?)

4


Level

1

Whack-a-Witch

STEP 3: Make the witch disappear when she’s clicked Keep track of your progess by ticking off the boxes below:

Activity Checklist To turn this into a game, we need to give the player something to do. They need to click on the witch to make her disappear. When the witch is clicked, we want her to disappear and play a sound. 1. In the Sounds tab, import the sound electronic/fairydust. 2. Add this script to the witch:

Test Your Project

Click the green flag. Does the witch disappear and play the sound when you click it?

SAVE YOUR PROJECT

Things to try • Ask your volunteer if you can record your own sound to play.

5


Level

1

Whack-a-Witch

STEP 4: Add a score and timer Keep track of your progess by ticking off the boxes below:

Activity Checklist We’ve got a witch, but now we want to make a game! We want to score points every time we click on the witch but we also want to have a time limit on the game. We can use a variable for the score and the timer. 1. Create a new Variable for all sprites called score, and alter the script for the witch to increase this variable by one when she is clicked.

2. Switch to the Stage and create a new variable (this time just for the stage) called timer. Add a new script that occurs when the green flag is clicked to set timer to 30 and reset the score to 0. Then use a repeat until block to wait a second and then reduce timer by one. This should repeat until timer is 0, at which point use stop all to stop the game.

Test Your Project

SAVE YOUR PROJECT

Things to try • How might you make the witch speed up as the game goes on?

6


Level

1

Whack-a-Witch Keep track of your progess by ticking off the boxes below:

Well done you’ve finished the basic game. There are more things you can do to your game though. Have a go at this challenge!

Challenge: Add more witches If one witch is good, more must be better! Let’s have three witches flying around. • Duplicate the witch by right-clicking it in the sprite list. • For each witch adjust the size of the sprite so the witches are different sizes. • For each witch change the speed variable so that they fly at different speeds. • Move the witches around the canvas so that they are not all together.

Test Your Project

Click the green flag. Do you have three witches that move from side to side across the screen, randomly appear and disappear, and disappear when you click on them?

SAVE YOUR PROJECT

7


Level

1

Whack-a-Witch Keep track of your progess by ticking off the boxes below:

Things to try • How many witches is a good number for the game? • Can you make the witches look different? You could either edit their costumes, or use some blocks from the Looks palette to change them. • Can you make the witches be worth different points? How about making the fastest (and smallest) witch worth 10 points?

Well done you’ve finished, now you can enjoy the game! Don’t forget you can share your game with all your friends and family by clicking on Share on the menu bar!

© 2012 Code Club. This work is licensed under a Creative Commons Attribution-Non Commercial-NoDerivs 3.0 Unported License.

8


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.