as you come in…

14
As you come in… DOWNLOADS FOR TODAY: http://ce21sandiego.org/2013 CarGameTeacherStarter.a2w Online student textbook (at bottom of each page below) Module 9.4 SpaceShipGame.a2w

Upload: wenda

Post on 22-Feb-2016

25 views

Category:

Documents


0 download

DESCRIPTION

As you come in…. DOWNLOADS FOR TODAY : http://ce21sandiego.org/2013 CarGameTeacherStarter.a2w Online student textbook (at bottom of each page below ) Module 9.4 SpaceShipGame.a2w . Today’s plan. Functions - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: As you come in…

As you come in… DOWNLOADS FOR TODAY:

http://ce21sandiego.org/2013 CarGameTeacherStarter.a2w

Online student textbook (at bottom of each page below) Module 9.4 SpaceShipGame.a2w

Page 2: As you come in…

Today’s plan Functions

Compound boolean expressions and if statements – can solve same problem multiple ways Or – car magnet And – space ship take off

Methods and Parameters

Page 3: As you come in…

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 4: As you come in…

Examples you know (but can’t see/edit the code for) Object functions

Some calculate numbers Distance To Height

Some calculate boolean values Is within X of

Y Is above

Page 5: As you come in…

Examples you know (but can’t see/edit the code for) World functions

Some calculate numbers Random

number Some calculate

boolean values Both a and b Either a or b or

both a == b a > b

Page 6: As you come in…

Compound Boolean Expressions – ORCar Driving Game (watch video 9.2)

Modify: Car should only turn to head towards MAGNETS One of the 4 magnets

Download from ce21sandiego.org/2013 CarGameTeacherStater.a2w

Let’s create a function to hide away complex boolean expression

Page 7: As you come in…

Create function: isMagnetReturns: boolean value Create new World function

Choose returns boolean Call it isMagnet (we often use “is” for boolean

returning functions – Yes or No, true or false) Drag boolean expression in if to clipboard Go to isMagnet function definition replace

“true” with expression from clipboard BACK in my first method

Drag complex expression to trash Replace (default) true with new isMagnet

function (look under World, functions – it’s at top)

Page 8: As you come in…

Compound Boolean Expressions – ORCar Driving Game (watch video 9.2)

In online text – used to show Two ways you could make this if…

Compound boolean expression

Page 9: As you come in…

Compound Boolean Expressions – ORCar Driving Game

Two ways if…

Page 10: As you come in…

Compound Boolean Expressions – ORCar Driving Game

Two ways if… nested if

Page 11: As you come in…

Compound Boolean Expressions – ANDSpaceship takes off

Space ship only takes off if all spheres are blue

Download from online textbook module 9.4 SpaceShipGame.a2w (bottom of page)

Click on World object Methods – edit Flip Switch

Build this if statement When true – make dropShip object move up

30 meters

Page 12: As you come in…

Compound Boolean Expressions – ANDSpaceship takes off

Two ways if…

Page 13: As you come in…

Compound Boolean Expressions – ANDSpaceship takes off

Two ways if…

Page 14: As you come in…

Coming Up… Week 7: Methods, parameters, and

events Week 8: Lists