pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In...

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

Transcript of pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In...

Page 1: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

pset 0: Scratch

Zamyla Chan | [email protected]

Page 2: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

Scratch

Page 3: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

Toolbox

  Sprites & costumes

  Stage & backgrounds

  Conditions

  Loops

  Variables

  Broadcasting events

  Threads

Page 4: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

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: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

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: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

Creating Scripts; Entry Point

  Begin the program with pressing the green flag.

Page 7: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

Statements

  Where the action is

Page 8: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

Booleans, Conditions

  Ask a true/false question…

  …And do something based on the answer.

Page 9: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

Loops

  Used to repeat statements

 Continuously

 For a set number of times

 Until a certain condition is true

Page 10: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

Avoid this:

Page 11: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

Much better!

Page 12: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

Variables

  Contain values

 In Scratch: Numbers and words

Page 13: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

Variables: Scope

  Global (stage + all sprites)

  Local (one sprite only)

  Who needs to use the variable?

Page 14: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

Events

  How the sprite behaves when…

Page 15: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

Broadcasting events

  Allows sprites to communicate

  Signal an event:

  Handle an event:

Page 16: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

Threads

  Simultaneous processes

Page 17: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

Example: Hungry Shark

Page 18: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

HungryShark 0

  Shark moves off screen

  Chomp action

  Fish movement

Page 19: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

HungryShark 1

  Chomp, revisited

  Score updates

Page 20: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

HungryShark 2

  Eating a poisonfish makes the shark sick

  Game over feature

Page 21: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope

this was walkthrough 0