Scratch Tutorial - Basic Pong

10
scratch tutorial pong a resource provided free of charge from education.instanttechinfo.com

Transcript of Scratch Tutorial - Basic Pong

Page 1: Scratch Tutorial - Basic Pong

scratch tutorial

pong

a resource provided free of charge fromeducation.instanttechinfo.com

Page 2: Scratch Tutorial - Basic Pong

tech tutorials for educationeducation.instanttechinfo.com

INSTANTTECH INFO

scratch tutorial - pong page 2

1. open scratch 2. delete the cat (right click on it, then press delete)

3. create a paddle sprite a. click ‘choose a sprite from library’ b. select ‘button 2’ from the ‘things’ category c. press ‘ok’

4. create a ball sprite a. click ‘choose a sprite from library’ b. select ‘ball’ from the ‘things category’ c. press ok

the stage so far

this tutorial will teach you how to create a basic game of ‘one player pong’. the aim of the game is to make sure that the ball doesn’t collide with the red line at the bottom of the screen. this is done by hitting the ball with a paddle (controlled by your mouse).

Page 3: Scratch Tutorial - Basic Pong

tech tutorials for educationeducation.instanttechinfo.com

INSTANTTECH INFO

scratch tutorial - pong page 3

5. adding motion to the ball a. click ‘make a new variable’ in the ‘data’ group (scripts pane) call it ‘speed’ and choose ‘for all sprites’ b. currently, we want the speed to increase at the same rate as the score. add the following scripts to the ball:

c. add the following scripts to the ball to actually make it move:

this script points the ball in a random direction when it touches the paddle

this script points the ball in a random direction at the beginning, and tells it to bounce when it

hits the edge

can’t find the blocks listed above? download ‘the basics of scratch’ booklet from http://education.instanttechinfo.com/tutorials/gamedesignbasics.html for a description of each block group, which will hopefully help

the speed starts off at one, which is very slow. hence why we added the ‘+ 5’

Page 4: Scratch Tutorial - Basic Pong

tech tutorials for educationeducation.instanttechinfo.com

INSTANTTECH INFO

scratch tutorial - pong page 4

6. controlling the paddle using the mouse a. click the paddle on the stage b. drag a ‘when green flag clicked’ block from the ‘events’ group into the scripts area to initiate the blocks c. then attach the following code:

this script moves the paddle left and right by tracking the location of the mouse

7. establishing a boundary a. click ‘paint new sprite’ b. click the line tool and draw a long red line:

select a thickness similar to the

following

the line must be the length of the

stage

the aim of the game is to not hit the bottom of the screen - therefore a boundary sprite needs to be added. when the ball touches the boundary, a ‘stop’ block will activate

Page 5: Scratch Tutorial - Basic Pong

tech tutorials for educationeducation.instanttechinfo.com

INSTANTTECH INFO

scratch tutorial - pong page 5

d. add the following script to the ball:

this script stops the game when the ball hits the red line

challenge: what if the background was red? can you think of a more effective sensing

block to use? (answer at end)

note that when the game stops, the ball and paddle remain in their positions. we want them to reset to their starting positions when the user presses the green flag. 8. resetting the stage at the beginning a. add the following script to the ball:

the ball will start in the direct centre of the stage

b. add the following script to the paddle:

c. position the line underneath the paddle on the stage, ensuring that it stretches across the entire stage

Page 6: Scratch Tutorial - Basic Pong

tech tutorials for educationeducation.instanttechinfo.com

INSTANTTECH INFO

scratch tutorial - pong page 6

additional challenges

1. keeping track of the player’s score our score will increase by 1 every second. the longer the player is in the game, the higher their score.

2. changing the ball costume when it hits the top of the stage this just makes the game a little bit more interesting!

4. power ups - this may include additional points, speed increases/decreases or paddle size adjustments. power-ups would be obtained if the ball hits them on the stage.

3. try adding multiple levels (levels may increase based on the player’s score) levels may have obstacles or power-ups (see below) or multiple balls hint: you may need to use ‘broadcast’ and ‘when I receive message’ blocks, as well as multiple stages note: you will need to adjust the speed accordingly, otherwise the levels may become too fast!

these challenges have been designed to test your scratch skills. please use your problem solving skills before looking at the answers on the following page!

example of power ups positioned on the stage. activated when the ball hits them.

Page 7: Scratch Tutorial - Basic Pong

tech tutorials for educationeducation.instanttechinfo.com

INSTANTTECH INFO

scratch tutorial - pong page 7

additional challenges: solutions

there may be multiple solutions to the challenges, here are our examples

1. keeping track of the player’s score our score will increase by 1 every second. the longer the player is in the game, the higher their score.

2. changing the ball costume when it hits the top of the stage when the ball moves up past y=155, then the costume will change

Page 8: Scratch Tutorial - Basic Pong

tech tutorials for educationeducation.instanttechinfo.com

INSTANTTECH INFO

scratch tutorial - pong page 8

3. an additional level (two balls) when the player reaches a score of 30 a. add an additional backdrop (paint new backdrop) and paint it a colour b. duplicate the ball sprite (right click) c. add the following script to the stage:

d. add the following script to the duplicated ball:

you need to add a ‘hide’ block underneath a ‘green flag clicked’ block otherwise the duplicated ball won’t be hidden at first

Page 9: Scratch Tutorial - Basic Pong

tech tutorials for educationeducation.instanttechinfo.com

INSTANTTECH INFO

scratch tutorial - pong page 9

4. speed decrease power ups a. create a new sprite (we used the stop sign) b. add the following script to the power up:

this is one method of creating a constantly moving power up - your way might be better!

c. replace the speed script on the balls, with the following script:

Page 10: Scratch Tutorial - Basic Pong

tech tutorials for educationeducation.instanttechinfo.com

INSTANTTECH INFO

scratch tutorial - pong page 10

play our basic pong game online:https://scratch.mit.edu/projects/84577886/

remix and improve ours!