Presentation is loading. Please wait.

Presentation is loading. Please wait.

August 30 Intro to CS.

Similar presentations


Presentation on theme: "August 30 Intro to CS."— Presentation transcript:

1 August 30 Intro to CS

2 Today’s Objectives More Boolean Broadcast and Ask & Answer
Custom Blocks Layers Work on your project

3 Review: More Boolean (“AND”)
Lincoln Lion = Dana Ave AND grade AND In Intro CS Which one(s) are true? Condition # School on Dana? 9-12? In Intro CS? Lion CS programmer! 1 2 3 4 5 6 7

4 Review: More Boolean (“AND”)
Lincoln Lions = Dana Ave AND grade AND In Intro CS Which one(s) are true? Condition # School on Dana? 9-12 In Intro CS? Lion CS programmer! False 1 True 2 3 4 5 6 7

5 Review: More Boolean (“AND”)
Lincoln Lions = Dana Ave AND grade AND Intro to CS Do you see a pattern in the table? Condition # School on Dana? 9-12? In Intro CS? Lion CS programmer! False 1 True 2 3 4 5 6 7 TRUE

6 More Block use More Boolean Parallelism Broadcast Ask/Answer If/Else
Repeat Forever Broadcast More Boolean Parallelism Broadcast Ask/Answer Ask/Answer

7 SNAP! Broadcast What does this do?
It puts the scripted value into “message” system variable

8 SNAP! Ask and Answer What does this do?
It puts the value typed by the keyboard into “answer” system variable

9 Constructing Boolean expressions
Condition A Condition B Condition C Expression Wednesday Sunday 9-3 cVSFarmersMarketOpen cVSFarmersMarketOpen = (Wednesday AND 9-3) OR (Sunday AND 9-3)

10 Constructing Boolean expressions
Condition A Condition B Condition C Expression Wednesday Sunday 9-3 CVSFarmersMarketOpen floorLamp tableLamp pgePowerPresent ARoomLightOn deadBattery noGas ----- CarWontStart CVSFarmersMarketOpen = (Wednesday AND 9-3) OR (Sunday AND 9-3) ARoomLightOn = (write this on your paper) CarWontStart = (write this on your paper)

11 Constructing Boolean expressions - ANSWER
Condition A Condition B Condition C Expression Wednesday Sunday 9-3 CVSFarmersMarketOpen floorLamp tableLamp pgePowerPresent ARoomLightOn deadBattery noGas ----- CarWontStart CVSFarmersMarketOpen = (Wednesday AND 9-3) OR (Sunday AND 9-3) ARoomLightOn = (floorLamp AND pgePowerPresent) OR ( tableLamp AND pgePowerPresent) = ( floorLamp OR tableLamp) AND pgePowerPresent CarWontStart = deadBattery OR noGas

12 Class Assignment – Write Truth Tables
Wednesday Sunday 9-3 CVSFarmersMarketOpen Fill in with all the rows and combinations Evaluate each combination floorLamp tableLamp pgePowerPresent ARoomLightOn Fill in with all the rows and combinations Evaluate each combination deadBattery noGas CarWontStart Fill in with all the rows and combinations Evaluate each combination

13 Today’s Objectives Review More Boolean Custom Blocks
Stage Scripting and Layers Work on your project

14 Make Block or Right click on empty space in Script Area
this dialog box will appear. or Press “Make Block” button in Variables and this dialog box will appear.

15 Make Block, continued Fill in the name of your block
Choose all Sprites or This Sprite only Default choice is “Command” Click OK

16 Make Block, continued After OK this Block Editor appears
Can write a script in the Editor Can drag a script into the Editor Click OK

17 Make Block, continued Write your code Click OK Done!
Look in Variables for your custom block

18 Make Block (with Reporter)
You can re-edit Block Right Click on the block The yellow menu pops up Select “edit “ and make your changes

19 Make Block (with Reporter)
Right click on empty space in Script Area this dialog box will appear. or Press “Make Block” button in Variables and this dialog box will appear.

20 Choose “Reporter” option
Fill in the desired Name Choose “Reporter” option here Click OK

21 Now make some inputs Click on the “+” on the right
and name your inputs This is the “report” block

22 Now add your code I clicked the “+” sign 4 times
I named each input as shown

23 Done! Sum = num1 + num2 + num3 + num4
“report” the Sum back to the caller

24 How to use the “reporter” block
You now have a custom block which adds 4 numbers and reports the Sum back to the caller/user You can use with any 4 hard coded numbers you want or The custom block can use the values in the variables.

25 Lab: Make a “HeroWalksRight” custom block
Only 7 instructions needed Be sure and include comments Does everything it needs to do!!

26 ANSWER: Make a “HeroWalksRight” custom block

27 Today’s Objectives Review More Boolean Custom Blocks
Stage Scripting and Layers Work on your project

28 Two “Looks” commands – goto front , go back N layers
Front, -2 layers Front, -1 layer Front layer With these 2 commands, you can control where the scenery resides.

29 Layers, continued - SNAP! will put your Sprites somewhere. Don’t know where. You must tell SNAP! which layer each Sprite belongs to. Procedure – Step 1. Each Sprite must be told goto front in order to start from a known layer. Step 2. Each Sprite is now commanded to the proper layer with go back N layers. In this way a mountain can be behind a tree, the tree can be behind Mario and Mario and the gremlin can occupy the front layer.

30 Stage scripting Click on Stage icon Scripts just like for Sprites
Broadcast messages

31 Stage scripting Click on Stage icon Scripts just like for Sprites
Broadcast messages This runs Mario Sprite only which is useful for debug

32 Today’s Objectives Review More Boolean Custom Blocks Layers
Work on your project

33 Initialization Logic for the Hero Sprite (“Program is repeatable and initializes state correctly.”)
Code is executed BEFORE Game starts Set the desired layer Set desired position Set the desired size Set the desired costume

34 Rest In Peace (R.I.P.) – Game over Logic (“Program is repeatable and initializes state correctly.”)
Starts when the game starts forever checking if <Mario and Gremlin touching> Game Over!

35 Open Lab: Work on your Project
Where should I start? Start with the project spec. There are least two scenery sprites (example: a tree and a mountain) Scenery sprites are layered with Mario (example: appropriate layering blocks are in your program) Scenery sprites move based on Mario’s movement Scenery sprites move at different speeds (e.g. the mountain far away moves slower than the nearby tree – just like when you look out a car window) Scenery sprites roll over when the fall of the stage

36 Reminders Read Chapter 1 Quiz next week Test on Friday, Sept 4
on computer processing, abstraction Boolean operations, and SNAP!

37 Looking ahead … Monday Tues / Weds Thurs/Fri TODAY 8/25-26 8/27-28
BACK TO SCHOOL NIGHT 8/31 TEST #1 9/1-2 QUIZ #1 9/4 LABOR DAY – NO SCHOOL 9/8-9 PROJECT #1 DUE 9/11 PROJECT #1 6pm

38 Design first – small manageable sections
Mario Initialize : costume, position Right Arrow : costume, move right, costume change, move right, etc (check for Right Edge & wrap) Left Arrow : costume, move left , costume change , move left , etc (check for Left Edge & wrap) Up Arrow : move up, wait, move down R.I.P. : Mario and Gremlin are touching

39 Design first – small manageable sections
Tree Initialize: position Right Arrow: point left , move left, check for left edge (wrap or bounce) Left Arrow: point right, move right, check for right edge (wrap or bounce)

40 Lab Exercise: Design Gremlin and Mountain on paper – 10 min
All possible inputs are shown - but may not be relevant to the Sprite What happens on RIP (Rest In Peace – the hero dies) Mountain Initialize: yy Right Arrow: yy Left Arrow: yy Up Arrow: yy RIP: yy Gremlin Initialize: yy Right Arrow: yy

41 What does it mean? Same as going to MacDonalds…
Front counter where you give your order Different orders - different input

42 What does it mean? Ann : Cheeseburger Water No (false)
Fries? Ann : Cheeseburger Water No (false) Jim : Fish Coffee No (false) You : Big Mac Coke Yes (true)

43 Creating Broadcast messages
Step 1. Create a message by choosing “new”. Step 2. SNAP! Opens a dialog box where you invent the name of your Message Step 3. Click “OK”

44 Parallelism ( also called threads)
These are 5 different streams of instructions/code also called threads. Program Counter can’t be in 5 different places at the same time!! SNAP executes a few instructions in one stream and then moves to the next. 1 GHz = 1,000,000,000 instructions in 1 second Makes it appear that each stream/thread is executed simultaneously.

45 Advanced Blocks – using inputs
We will write code together as a class From the rubric, it says the Hero… “ Must be able to walk anywhere - left, right, up or down” “Make Block” with inputs You can write 6 or 7 lines of code and use it for Gremlin, Tree and Mountain. Why not Mario?

46 Lab Exercise: Make Block, continued
Name your block - “FancyWalk” Choose all Sprites, or , This Sprite only Click OK

47 Lab Exercise: Make Block, continued
Block Editor appears with the name of the block Click on the “+” sign Type the name of your input LeftOrRight Click OK

48 Lab Exercise: Make Block, continued
You now have a Block with an input Click on the “+” sign again

49 Lab Exercise: Make Block, continued
Type the name of your 2nd input: UpOrDown Click OK

50 Lab Exercise: Make Block, continued
Your Custom Block now has 2 inputs Now add the script

51 Lab Exercise: Make Block, continued
After you have constructed your script … Drag the input names as shown in the figure Now let’s run SNAP, initialize and see it work!!

52 Test Review SNAP! Broadcast Ask/Answer Variables System Global Local
Layers Costumes Terminology Sprite, Script, Stage, Scripting Area, Blocks, Tabs Custom Blocks

53 Test Review Computer Architecture Parallelism Boolean Logic
Main Memory Program Memory ALU Variables Program Counter Parallelism Definition Boolean Logic AND, OR, NOT Truth Tables


Download ppt "August 30 Intro to CS."

Similar presentations


Ads by Google