Human languages are ambiguous Computer languages must be
Human languages are ambiguous Computer languages must be precise Complex Conditionals CSD Code Studio Level 9 Describe what happens If Game. Mouse. X >0 duck. visible = true; else duck. visible = false;
Identify the parts What’s the Boolean condition? What happens when the condition is true? What happens when the condition is false? If Game. Mouse. X >0 duck. visible = true; else duck. visible = false;
Puzzle 3: Why do the gears always move?
Using ELSE, before you write the statements, figure out what sprites and variables are needed. 4. If the temperature is below freezing, wear a heavy coat, otherwise wear a jacket 5. If the plane is below the horizon make it disappear otherwise it should be visible. 6. If the up arrow key is pressed, the plane moves upward otherwise it moves down
What sprites and variables are needed? 4. If the temperature is below freezing, wear a heavy coat, otherwise wear a jacket What kind of variable is temperature? How do you ask if it is below freezing? What kind of variable is a coat or jacket? How do you change a sprite to look like it’s wearing different clothes?
Some games react to the time of day, season of year, holidays, and other factors. This mini game has the alien put on a coat if the temperature is low. https: //studio. code. org/projects/g amelab/t. GSn. X 4 SATsup. MSQ 996 _B_3 c. NCEKGN 1 Ra. WBc 44 Jc. Ij. O 8
What sprites and variables are needed? 5. If the plane is below the horizon make it disappear otherwise it should be visible. Assume there are 2 sprites: plane and horizon. What property of the sprites are you comparing? How do you make something disappear?
What sprites and variables are needed? 6. If the up arrow key is pressed, the plane moves upward otherwise it moves down What’s the code to ask if the up arrow key is pressed down? How do you move a sprite up? How do you move a sprite down?
Possible answers: Using ELSE 4. If the temperature is below freezing, wear a heavy coat, otherwise wear a jacket 5. If the plane sprite is below the horizon sprite make it disappear otherwise it should be visible. 6. If the up arrow key is pressed, the plane moves upward otherwise it moves down
Puzzle 4: What happens? Read the code screen
These are more Boolean functions in Code. Lab mouse. Did. Move() mouse. Went. Down(side) mouse. Went. Up(side) key. Went. Down(key) key. Went. Up(key) Returns true if the mouse did move Returns true once when the specified mouse button is pressed down Returns true once when the specified mouse button is released Returns true once when the specified key is pressed down if(mouse. Did. Move()) {} Returns true once when the specified key is released if(key. Went. Down("m")) {} if(mouse. Went. Down("left")) {} if(mouse. Went. Up("left")) {} if(key. Went. Down("e")) {}
Puzzle 5: Predict what happens What seems to be the difference between key. Down(), key. Went. Down(), and key. Went. Up()? What do you think the exclamation mark (!) on line 10 does?
Puzzle 7: Dropping balloon Here's a program that drops a balloon down the screen – Program the mouse button to raise the balloon back up while it's clicked. Add an if else statement that checks for mouse. Down Inside the conditional, move the balloon up one pixel if the mouse is down otherwise move the balloon down Pseudocode: If mouse. Down Subtract 1 from balloon. y Else Add 1 to balloon. y
Puzzle 9 Salt shaker mouse. Did. Move PSEUDOCODE: return false if the mouse is still, return true if the mouse has been moving. if mouse. Did. Move rotate the salt sprite randomly to the left or right. Use mouse. Did. Move so that you can "shake" the salt by moving the mouse back and forth. How do you rotate something randomly? Is this an IF or an IF-ELSE?
Work in code studio Stage 9 Human languages are ambiguous Computer languages must be precise
- Slides: 15