To move a sprite use the Motion area.
Practise with the default sprite.
To write the most basic of programs in Scratch you need to use commands from a range of code areas.
Take a Green Flag hat block from the Control section and add commands to set the sprite to the centre of the screen (x=0,y=0) and scale it to 50% (from the Looks area). This sets up the elements of a Scratch program such as sprite size and position - technically known as 'initialisation'.
(Note that a 'hat' block is one that you can't put anything above: it is a starter only. The green flag hat runs its code when the green flag above the graphics/game area is clicked.)
Now add key press controls for left, right, up and down so that the sprite turns and moves when the arrow keys are pressed.
You will need a forever if block under the green flag hat with a condition to detect a particular key press. This will watch out for the condition specified until the program ends. The 'key pressed' condition can be found in the 'Sensing' section.
Inside the Forever if block you add a 'Change x by' or 'Change y by' command from the Motion section (x is across and y is up-down on the screen).
If 'Change x by 5' moves pixels right how do you move 5 pixels left? If 'Change y by 5' moves pixels up how do you move 5 pixels down?
What controls the speed of movement? What is the equivalent on the screen to one step of movement?
Add a command to bounce at the edge using a new green flag hat, a forever block and the 'If on edge bounce' command.
Note that a forever block inside a green flag hat block will do whatever is inside it for the duration of the program. If you leave out 'forever' or 'forever if' your code will only run once and you will get no results.
Once you have a block of code to move in one direction you can duplicate it and amend it for the other directions. Right click the block and choose Duplicate then amend it.
Program blocks run in parallel fashion so you can write as many green hat blocks and have them run simultaneously rather than in sequence. This means you can put a <if on edge bounce> command inside a separate green flag hat and it will perform this action continuously - as long as you set it to run more than once!
Add a second sprite by choosing it from the folders: click on the middle Create sprite button and choose a new sprite.
Make this sprite start on the left side of the screen (x=-240) at a random position and move towards the right side. When it reaches the right side it should disappear and start again on the left.
Use Pick random from the green Operators area to get a value in the range -150 to +150 so the sprite starts at a different point each time.
Note that the Scratch graphics/game area is 480 pixels wide by 360 tall. The centre coordinate is [0,0] and the visible limits are: left x: -240; right x: 240; top y: 180; bottom y: -180. You can use points outside this area (useful in scrolling games).
Use Hide and Show from the Looks section to control the visibility of the sprite.
Use an if block to detect whether the sprite has reached the right hand side. Add a < or > condition to detect the position of the sprite. Note that Scratch tracks the x and y positions of every sprite and these are available in 'x position' and 'y position' under Motion.
Solution (quick peek if you need it).
Now add a third sprite and make this one move in the opposite direction, from right to left (or up-down or down-up if you prefer). Hint: you will have to invert everything in your code for the first sprite.
The Rotate controls: there are three tiny icons in a column under the menu. These set the amount of rotation to none, left-right only and full rotation. Experiment with these to get the effect you want.
Save your finished work so you can use it when developing a better version later. Note that when you save your work you must click on 'Computer' and choose your N drive. Simply saving it will not preserve it for the following week.
Ready to Make 'Pong' now? Instructions at the bottom of this page.
You have implemented your first algorithm. An algorithm is a formula, rather like a recipe, that describes how to solve a problem. Algorithms are found in maths and especially in computer science.
An algorithm to display the even numbers up to 100 would be:
Some algorithms are already implemented in Scratch, for example if on edge bounce. You have implemented the same algorithm four times to control the sprite with key presses:
Add a sprite to a project and make it move across the screen. When it reaches the edge it should reappear on the other side. In this way you could create targets for another sprite to hit and score points.
Steps:
Repeat this code for any number of sprites.
Extension 1
Try reversing the direction of the sprites.
Extension 2
Make a simple game where the main sprite has to dodge the ones moving across the stage. Use the touching ? condition in Sensing to detect a collision between sprites (as usual the program will have check for this condition continually, not just once.)
Develop this by using backgrounds and sprites from a scenario of your choice e.g. The Simpsons. You know what Homer will say if he bumps into something!
Extension 3
Try using the pick random from m to n command from Operators.
Further development: have a third sprite moving from right to left; add a variable to keep a total score; add a point if one of the sprites collides with the main sprite; deduct a point if the other sprite collides; change the background and sprites into a scenario of your own choice.
This simple program introduces all three features of what is called structured programming:
sequence - one instruction after another, as in hide; goto; show
repetition - repeating something over and over, in this case forever with no finishing condition apart from the program stops
control - the if statement checks to see if the sprite has disappeared on the right of the screen
You will meet these three things time and time again in programming: at the most basic level it's all there is!
Algorithms are often represented as a flow chart. The basic symbols include:

Note that as this program loops forever the code never reaches the end box, which is not really needed.
Start a Word document. Add a heading 'Scratch Programs' then save it.
Write a summary of your work under these headings:
Make a one-player game of Pong
Follow the method of problem solving studied earlier.
Specification, definition and description of the problem are really important.
Basic techniques required:
Extension: a two player game: classic Pong.
In this game you move the mouse over a moving target and click to 'kill' it - if you are quick enough! When a kill is made the score is increased. The game should run for a fixed period.
Extension: add a top scores table.
In this game you control an object that moves up and down in the centre of the screen while objects fly towards it from left and right. Some of the objects could reduce your 'lives' while others could increase your score.
Extension: add objects that fly in from different angles.