pset 0: scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · stage where all...

21
pset 0: Scratch Zamyla Chan | [email protected]

Upload: others

Post on 12-Oct-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

pset 0: Scratch

Zamyla Chan | [email protected]

Page 2: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

Scratch

Page 3: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

Toolbox

  Sprites & costumes

  Stage & backgrounds

  Conditions

  Loops

  Variables

  Broadcasting events

  Threads

Page 4: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

Sprites

  Every object is a sprite.

 Two cats ⇒ two sprites

  Sprites have:

 Scripts (how the sprite ‘behaves’)

 Costumes (what the sprite looks like)

Page 5: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

Stage

  Where all sprites are placed

  The stage can also have scripts

 Useful when scripts aren’t specific to an actual sprite

  Instead of costumes, has backgrounds.

Page 6: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

Creating Scripts; Entry Point

  Begin the program with pressing the green flag.

Page 7: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

Statements

  Where the action is

Page 8: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

Booleans, Conditions

  Ask a true/false question…

  …And do something based on the answer.

Page 9: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

Loops

  Used to repeat statements

 Continuously

 For a set number of times

 Until a certain condition is true

Page 10: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

Avoid this:

Page 11: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

Much better!

Page 12: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

Variables

  Contain values

 In Scratch: Numbers and words

Page 13: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

Variables: Scope

  Global (stage + all sprites)

  Local (one sprite only)

  Who needs to use the variable?

Page 14: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

Events

  How the sprite behaves when…

Page 15: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

Broadcasting events

  Allows sprites to communicate

  Signal an event:

  Handle an event:

Page 16: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

Threads

  Simultaneous processes

Page 17: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

Example: Hungry Shark

Page 18: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

HungryShark 0

  Shark moves off screen

  Chomp action

  Fish movement

Page 19: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

HungryShark 1

  Chomp, revisited

  Score updates

Page 20: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

HungryShark 2

  Eating a poisonfish makes the shark sick

  Game over feature

Page 21: pset 0: Scratchd2o9nyf4hwsci4.cloudfront.net/2012/fall/psets/0/walkthrough0.pdf · Stage Where all sprites are placed The stage can also have scripts Useful when scripts aren’t

this was walkthrough 0