as you come in… sign in (in back) and pick up badge name card – on computer… log in:...
TRANSCRIPT
![Page 1: As you come in… Sign in (in back) and pick up Badge Name Card – on computer… Log in: Launch/Start Alice Any questions? (of any kind) DOWNLOADS FOR TODAY:](https://reader033.vdocuments.us/reader033/viewer/2022052820/5519e056550346443e8b4f98/html5/thumbnails/1.jpg)
As you come in…
Sign in (in back) and pick up Badge Name Card – on computer…
Log in: Launch/Start Alice
Any questions? (of any kind) DOWNLOADS FOR TODAY:
http://ce21sandiego.org/2013 CylinderStarter.a2w Online student textbook (at bottom of each page
below) Module 9.2 Magnet World with Other Objects.a2w Module 9.4 SpaceShipGame.a2w
![Page 2: As you come in… Sign in (in back) and pick up Badge Name Card – on computer… Log in: Launch/Start Alice Any questions? (of any kind) DOWNLOADS FOR TODAY:](https://reader033.vdocuments.us/reader033/viewer/2022052820/5519e056550346443e8b4f98/html5/thumbnails/2.jpg)
Today’s plan
While loops (penguin race, timer) Create your own function with a
parameter (timer) Compound boolean expressions and
if statements – can solve same problem multiple ways Or – car magnet And – space ship take off
![Page 3: As you come in… Sign in (in back) and pick up Badge Name Card – on computer… Log in: Launch/Start Alice Any questions? (of any kind) DOWNLOADS FOR TODAY:](https://reader033.vdocuments.us/reader033/viewer/2022052820/5519e056550346443e8b4f98/html5/thumbnails/3.jpg)
Hint to getting while loops right
Humans naturally think “until” I’ll keep spending until I run out of money
(balance <= 0) I’ll keep dancing until I fall asleep
Computers use “while” loops – the opposite I’ll keep spending while I still have money
(balance > 0) I’ll keep dancing while I am not asleep While I have a dirty dish, I’ll keep washing
dishes
![Page 4: As you come in… Sign in (in back) and pick up Badge Name Card – on computer… Log in: Launch/Start Alice Any questions? (of any kind) DOWNLOADS FOR TODAY:](https://reader033.vdocuments.us/reader033/viewer/2022052820/5519e056550346443e8b4f98/html5/thumbnails/4.jpg)
Let’s have a race…
A Wind up penguin (he just goes)
While loop with “walk and spin” inside it Jet-pack penguin2 (controlled by <- event)
Moves forward .5 meters Race to a stop sign (within 2 meters) Whenever someone gets within 2 meters
Stop looping (going)
![Page 5: As you come in… Sign in (in back) and pick up Badge Name Card – on computer… Log in: Launch/Start Alice Any questions? (of any kind) DOWNLOADS FOR TODAY:](https://reader033.vdocuments.us/reader033/viewer/2022052820/5519e056550346443e8b4f98/html5/thumbnails/5.jpg)
While loops in Alice tend to be used when…
You have a user controlled (hence, not predictable) event So you don’t know when the user might
Click on an object Type a key, User types a number (pick a number between
1-10, etc. You have (not predictable) actions
controlled by, for example, random numbers E.g. the lunchlady/zombie or fish/shark case
![Page 6: As you come in… Sign in (in back) and pick up Badge Name Card – on computer… Log in: Launch/Start Alice Any questions? (of any kind) DOWNLOADS FOR TODAY:](https://reader033.vdocuments.us/reader033/viewer/2022052820/5519e056550346443e8b4f98/html5/thumbnails/6.jpg)
When should we keep going?e.g. while loop expression true(P1: wind up, P2: jet pack)
Cases A B C DP1, P2 outside T T T TP1 inside, P2 outside T T T FP2 inside, P1 outside T T F FP1, P2 inside T F F F
![Page 7: As you come in… Sign in (in back) and pick up Badge Name Card – on computer… Log in: Launch/Start Alice Any questions? (of any kind) DOWNLOADS FOR TODAY:](https://reader033.vdocuments.us/reader033/viewer/2022052820/5519e056550346443e8b4f98/html5/thumbnails/7.jpg)
Which while loop header (tile) would you use to control the “going”?
![Page 8: As you come in… Sign in (in back) and pick up Badge Name Card – on computer… Log in: Launch/Start Alice Any questions? (of any kind) DOWNLOADS FOR TODAY:](https://reader033.vdocuments.us/reader033/viewer/2022052820/5519e056550346443e8b4f98/html5/thumbnails/8.jpg)
Let’s Build the Code!
Download from http://ce21sandiego.org/2013 Meeting 4: JetPackPenguinTeacherStart.a2w
Plan: Explore object positions Create event that moves jet pack penguin 0.5
meters whenever <space> is pushed. (Test) SIMPLIFY: Create loop that makes windup penguin
move repeatedly (forever), 0.35 meters (at same time as “walks” and windupKey “rolls” 0.25 revolutions)
CORRECT: change loop to have the game end (e.g. windup penguin stops walking) when either penguin “wins” (gets within 2 meters of stop sign)WHILE:_________________________________________
![Page 9: As you come in… Sign in (in back) and pick up Badge Name Card – on computer… Log in: Launch/Start Alice Any questions? (of any kind) DOWNLOADS FOR TODAY:](https://reader033.vdocuments.us/reader033/viewer/2022052820/5519e056550346443e8b4f98/html5/thumbnails/9.jpg)
Game keeps playing while…A. Either penguin is close to the stop signB. Neither penguin is close to the stop sign
What does the other one do?
![Page 10: As you come in… Sign in (in back) and pick up Badge Name Card – on computer… Log in: Launch/Start Alice Any questions? (of any kind) DOWNLOADS FOR TODAY:](https://reader033.vdocuments.us/reader033/viewer/2022052820/5519e056550346443e8b4f98/html5/thumbnails/10.jpg)
Useful tool: “Timer”
Use: to “count down time” in a game 2 “cylinder” objects set on top of each
other Grey is “background” Yellow is in “front”
Yellow moves down a bit each “time step” (loop iteration)
The game is over when the yellow cylinder is Distance to the ground >= cylinder height. (So while not, game is ongoing…)
![Page 11: As you come in… Sign in (in back) and pick up Badge Name Card – on computer… Log in: Launch/Start Alice Any questions? (of any kind) DOWNLOADS FOR TODAY:](https://reader033.vdocuments.us/reader033/viewer/2022052820/5519e056550346443e8b4f98/html5/thumbnails/11.jpg)
Timer Coding Plan
SIMPLIFY: Loop forever (while true) move yellow cylinder down.
COMPLETE: Loop should stop after yellow cylinder
“disappears” – say should take 4 steps Hint: cylinder is 2 meters tall
After loop: have “3-D Text” (originally set to opacity 0) become visible saying “Game Over”
IMPROVE: Regardless cylinder size, calculate how many “steps” before cylinder gone 10 steps? 4 steps?
NEW PROGRAMMING CONCEPT: Functions – perform (complex) calculations
![Page 12: As you come in… Sign in (in back) and pick up Badge Name Card – on computer… Log in: Launch/Start Alice Any questions? (of any kind) DOWNLOADS FOR TODAY:](https://reader033.vdocuments.us/reader033/viewer/2022052820/5519e056550346443e8b4f98/html5/thumbnails/12.jpg)
Compound Boolean Expressions – ORCar Driving Game (watch video 9.2)
Modify: Car should only turn to head towards MAGNETS One of the 4 magnets
Two ways if…
![Page 13: As you come in… Sign in (in back) and pick up Badge Name Card – on computer… Log in: Launch/Start Alice Any questions? (of any kind) DOWNLOADS FOR TODAY:](https://reader033.vdocuments.us/reader033/viewer/2022052820/5519e056550346443e8b4f98/html5/thumbnails/13.jpg)
Compound Boolean Expressions – ORCar Driving Game
Two ways if…
![Page 14: As you come in… Sign in (in back) and pick up Badge Name Card – on computer… Log in: Launch/Start Alice Any questions? (of any kind) DOWNLOADS FOR TODAY:](https://reader033.vdocuments.us/reader033/viewer/2022052820/5519e056550346443e8b4f98/html5/thumbnails/14.jpg)
Compound Boolean Expressions – ORCar Driving Game
Two ways if…
![Page 15: As you come in… Sign in (in back) and pick up Badge Name Card – on computer… Log in: Launch/Start Alice Any questions? (of any kind) DOWNLOADS FOR TODAY:](https://reader033.vdocuments.us/reader033/viewer/2022052820/5519e056550346443e8b4f98/html5/thumbnails/15.jpg)
Compound Boolean Expressions – ANDSpaceship takes off
Space ship only takes off if all spheres are blue
Two ways if…
![Page 16: As you come in… Sign in (in back) and pick up Badge Name Card – on computer… Log in: Launch/Start Alice Any questions? (of any kind) DOWNLOADS FOR TODAY:](https://reader033.vdocuments.us/reader033/viewer/2022052820/5519e056550346443e8b4f98/html5/thumbnails/16.jpg)
Compound Boolean Expressions – ANDSpaceship takes off
Two ways if…
![Page 17: As you come in… Sign in (in back) and pick up Badge Name Card – on computer… Log in: Launch/Start Alice Any questions? (of any kind) DOWNLOADS FOR TODAY:](https://reader033.vdocuments.us/reader033/viewer/2022052820/5519e056550346443e8b4f98/html5/thumbnails/17.jpg)
Compound Boolean Expressions – ANDSpaceship takes off
Two ways if…
![Page 18: As you come in… Sign in (in back) and pick up Badge Name Card – on computer… Log in: Launch/Start Alice Any questions? (of any kind) DOWNLOADS FOR TODAY:](https://reader033.vdocuments.us/reader033/viewer/2022052820/5519e056550346443e8b4f98/html5/thumbnails/18.jpg)
Functions: Calculate a Value and “Return” it.
Hides away complex calculation When program executes that line/tile:
change of control flow! Jump to code/function that does the
calculation It “returns” the calculated value, which
replaces the function call tile Finally, that line/tile is executed
![Page 19: As you come in… Sign in (in back) and pick up Badge Name Card – on computer… Log in: Launch/Start Alice Any questions? (of any kind) DOWNLOADS FOR TODAY:](https://reader033.vdocuments.us/reader033/viewer/2022052820/5519e056550346443e8b4f98/html5/thumbnails/19.jpg)
Examples you know
Return number values: Move forward distanceTo Random
Create our own – which return boolean values isAMagnet areBallsBlue
![Page 20: As you come in… Sign in (in back) and pick up Badge Name Card – on computer… Log in: Launch/Start Alice Any questions? (of any kind) DOWNLOADS FOR TODAY:](https://reader033.vdocuments.us/reader033/viewer/2022052820/5519e056550346443e8b4f98/html5/thumbnails/20.jpg)
Coming Up…
Week 5: Compound Boolean Expressions and if statements and while loops
Week 6: Functions, Mathematical expressions, parameters, methods
Week 7: Functions, parameters, methods and events
Week 8: Lists