0% found this document useful (0 votes)
46 views67 pages

Scratch Programming: Units Overview

Uploaded by

pangunpark
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views67 pages

Scratch Programming: Units Overview

Uploaded by

pangunpark
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Programming in Scratch

Part 2

충남대학교 | 박판근
Brief Outline 2

§ Unit 1: Moving blocks, creating scripts, and repeating blocks


§ Unit 2: Drawing with a computer
§ Unit 3: Tempo, variables, and the hat block
§ Unit 4: Coordinates and conditionals
§ Unit 5: Drawing with iteration
§ Unit 6: Broadcast and random numbers
§ Unit 7: Ask and join blocks, Scratch tools
§ Unit 8: Building your own blocks
Set and Change the X and Y Positions 3
Control and Operators 4
X and Y Axes 5
IF Introduction 6
IF Questions (Quiz) 7

§ Will the note 60 play when the following script is run?

§ If the following script is run, what will play?


IF Questions (Quiz) 8

§ Will the note 60 play when the following script is run? (Yes)

§ If the following script is run, what will play? (note 60)


Using If with Variables (Quiz) 9

§ What is the value of X after double clicking on the script below?

§ What is the value of X after double clicking on the script below?


Using If with Variables (Quiz) 10

§ What is the value of X after double clicking on the script below? (10)

§ What is the value of X after double clicking on the script below? (20)
AND, OR, and NOT (Quiz) 11

§ What is the value of X after double clicking on the script below?

§ What is the value of Y after double clicking on the script below?


AND, OR, and NOT (Quiz) 12

§ What is the value of X after double clicking on the script below? (20)

§ What is the value of Y after double clicking on the script below? (15)
Multiple If Statements and Multiple Variables (Quiz) 13

§ What is the value of "my length" after the script runs?


Multiple If Statements and Multiple Variables (Quiz) 14

§ What is the value of "my length" after the script runs? (3)
Watch out: Concurrency and Race!! 15

§ What does "x" get set to when the green flag is pressed?

§ What will "x" be set to after the green flag has been pressed and both scrip
ts are done? 20!!
Example : Game of Tag 16

§ Make a character move around based upon the keys that you've pressed.
ØMany times we'll want to move the character with the keys (i.e. up, down, left &
right).
Example : Game of Tag 17

§ Rename them by clicking i (info) button on the corner of each sprite's pictu
re in the sprite area.
Multiple Ways of Moving the Sprite with Keys 18
Working with Multiple Sprites 19
Playing a Game of Tag 20
Conditional Blocks and Sensing 21

§ We want the mouse to react if the player controlling the cat touches or "cat
ches" the mouse. We want the following script to make the "Mouse" sprite
say "OH NOs" when it touches the cat.
Keeping Score in a Game of Tag 22
Keeping Score in a Game of Tag 23

§ Now add keeping score to your game of tag. You'll need to use a variable to
keep score.
Introducing Random 24

§ Randomly Appearing Power-ups


Introducing Random 25
Exercise : Game of Tag 26

§ Now that you've incorporated score and power-ups into your game of tag, it is time to add some obs
tacles and extra features! An obstacle is something that blocks the way and makes achieving the goa
l of the game harder.

§ Here are some ideas you can add:


§ If the cat touches the edge, subtract 1 from the variable score
§ If the duck touches the edge, add 1 to the variable score
§ Add some obstacles (we added lava):
Ø If the cat touches an obstacle, subtract 1 from the score
Ø If the duck touches an obstacle add 1 to the score
Ø Add platforms for your sprites to stand on
§ Add portals which make your sprite disappear and reappear somewhere else (Hint: use the hide blo
ck)

§ Hints
Brief Outline 27

§ Unit 1: Moving blocks, creating scripts, and repeating blocks


§ Unit 2: Drawing with a computer
§ Unit 3: Tempo, variables, and the hat block
§ Unit 4: Coordinates and conditionals
§ Unit 5: Drawing with iteration
§ Unit 6: Broadcast and random numbers
§ Unit 7: Ask and join blocks, Scratch tools
§ Unit 8: Building your own blocks
Pen Block 28

§ Iteration
Drawing with Dots 29

§ If you move the character while the pen is down it draws a line. It will dra
w a dot if you put the pen down without moving the character!

§ Hint:
Increasing Dots Using Iteration 30
Increasing Dots Using Iteration 31

§ The following code draws a series of dots.


Multiple Ways to Draw a Star 32

§ In computer science there are usually a lot of different ways to solve each p
roblem! You can draw this star in a lot of different ways. Try to come up wi
th at least two different ways in which you might draw the pieces of this.
Think : Drawing a Spinning Square 33

§ The code below draws the image below.


Using Variables to Draw: Squiral 34
Drawing a Squiral with Iteration (Quiz) 35

§ These two scripts in Scratch draw similar pictures.


§ Script 1

§ Script 2
Drawing a Squiral with Iteration (Quiz) 36

§ These two scripts in Scratch draw similar pictures.


§ Script 1

§ Script 2
Exercise : Drawing a Star 37

§ Have your character draw a star like the one below in Scratch.
§ Hint: Try using Guess and Check!
Brief Outline 38

§ Unit 1: Moving blocks, creating scripts, and repeating blocks


§ Unit 2: Drawing with a computer
§ Unit 3: Tempo, variables, and the hat block
§ Unit 4: Coordinates and conditionals
§ Unit 5: Drawing with iteration
§ Unit 6: Broadcast and random numbers
§ Unit 7: Ask and join blocks, Scratch tools
§ Unit 8: Building your own blocks
Introduction to Broadcast 39
Introduction to Broadcast 40

§ A short scratch play


Cat's Scripts:

Duck's Scripts:
Introduction to Broadcast 41
Broadcast vs. Broadcast and Wait (Quiz) 42

§ How many times will you hear "meow" when you run the script below?

§ How many times will you hear "meow" when you run the script below?

§ Hint:
Broadcast vs. Broadcast and Wait (Quiz) 43

§ How many times will you hear "meow" when you run the script below? (4)

§ How many times will you hear "meow" when you run the script below? (1)
Broadcast vs. Broadcast and Wait (Quiz) 44

§ How many times will you hear the note 60 when you click on the green flag?

§ How many times will you hear the note 60 when you click on the green flag?
Broadcast vs. Broadcast and Wait (Quiz) 45

§ How many times will you hear the note 60 when you click on the green flag? (12)

§ How many times will you hear the note 60 when you click on the green flag? (3)
Random Numbers 46

§ We can generate a random number in Scratch between any two numbers.


ØFor example, when we use the block below Scratch will randomly pick either 1,
2, 3, 4, 5, 6, 7, 8, 9, or 10.

§ Random Cat
ØWe can use the blocks below to make a character move around the screen rando
mly!
Exercise : Make a character move Randomly 47

§ Make your character move around randomly but still stay within 100 pixels
in the x and y direction of the center of the screen (0,0).
ØIf they are below y = -100 point they shouldn't go any lower.
ØIf they are above y = 100 they shouldn't go any higher.
ØIf they are to the left of x = -100 they shouldn't go any farther left.
ØIf they are to the right of x = 100 they shouldn't go any farther right.
§ These pieces might be helpful:
Example : Rock, Paper, Scissors 48
Exercise : Rock, Paper, Scissors 49

§ Before we get our cat and duck to pick rock, paper, or scissors we need to
have both the characters pick a random number from 1 to 3, when the gree
n flag is pressed.
ØMake the cat and duck pick DIFFERENT random numbers, and then say the nu
mbers they picked.

§ Hint
ØIf you want the cat and duck to say either 1, 2, or 3, what do you think you shou
ld set "cat choice" and "duck choice" to?
ØYour stage should look something like this:
Brief Outline 50

§ Unit 1: Moving blocks, creating scripts, and repeating blocks


§ Unit 2: Drawing with a computer
§ Unit 3: Tempo, variables, and the hat block
§ Unit 4: Coordinates and conditionals
§ Unit 5: Drawing with iteration
§ Unit 6: Broadcast and random numbers
§ Unit 7: Ask and join blocks, Scratch tools
§ Unit 8: Building your own blocks
Ask and Join Blocks 51
Ask and Join Blocks 52
Ask and Join Blocks 53
Save as a Copy and Backpack 54
Example : Helicopter with Gravity 55
Example : Helicopter with Gravity 56

§ When you're done with the project, the helicopter will be able to fly to the
right and the left and land on a platform. It will also be affected by gravity.
ØOpen up a new sprite by clicking on the

ØIn the Sprite Library, under the "Transportation" category double click on the "
Helicopter".
Example : Helicopter with Gravity 57

§ Click on the "costumes" tab.

§ In the editing panel, click the "Flip Left-Right" button so that the new costu
me is now facing the other direction.
Example : Helicopter with Gravity 58

§ Now you should have 2 costumes for your helicopter like the picture below.
Example : Helicopter with Gravity 59

§ In this this step we will make the helicopter stop on platforms, but we won
't make gravity re-start after the helicopter is off the platform. In the next s
tep we will make gravity re-start.

§ Make sure you add the dots to both costumes!!

§ You also need to have ONE platform sprite (make a new sprite using the "P
aint New Sprite" button shown below). The platform should look somethin
g like below (it can be any color). You should only have ONE for now.
Example : Helicopter with Gravity 60

§ You should already have the scripts to move the helicopter left and right an
d up. Now add this Script to your helicopter.
Brief Outline 61

§ Unit 1: Moving blocks, creating scripts, and repeating blocks


§ Unit 2: Drawing with a computer
§ Unit 3: Tempo, variables, and the hat block
§ Unit 4: Coordinates and conditionals
§ Unit 5: Drawing with iteration
§ Unit 6: Broadcast and random numbers
§ Unit 7: Ask and join blocks, Scratch tools
§ Unit 8: Building your own blocks
Making New Blocks 62
Making New Blocks (Quiz) 63

§ What will be the size of the square drawn when you click the green flag in t
he following script?

§ What will the sprite say when the green flag is clicked?
Making New Blocks (Quiz) 64

§ What will be the size of the square drawn when you click the green flag in t
he following script? (50)

§ What will the sprite say when the green flag is clicked? (programming)
Exercise : Draw Lots of Squares 65

§ In this step you are NOT making a new block. Using a variable and your ne
w draw-square block

§ Try to make a script that draws the picture below.


Example : Games with Multiple Levels 66
Exercise : Multiple Room 67

§ Try to make a script that move between rooms.

You might also like