In.  This presentation will only make sense if you view it in presentation mode (hit F5). If you don’t do that there will be multiple slides that are.

Slides:



Advertisements
Similar presentations
Sprite-visual object (actor on the stage) Scripts- Tells actors (sprites) what to do.
Advertisements

Create a Simple Game in Scratch
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Create a Simple Game in Scratch
Mission Technology Introduction to Scratch! June 2007.
Making Decisions in Python Sec 9-10 Web Design. Objectives The student will: Understand how to make a decision in Python Understand the structure of an.
Python Programming Language
Variables Conditionals Loops The concept of Iteration Two types of loops: While For When do we use them? Iteration in the context of computer graphics.
CS0007: Introduction to Computer Programming
Final Project Web Design. Final Project Your robot will be placed in a room with the red cone. Your robot will need to find the cone in the room and run.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Intro to Programming Algebra-Geometry. Computer Programming? What is programming? The process of writing, testing, and maintaining the source code of.
Code Club Session 3 Shark Eats Fish. Picture of finished product here.
Programming Concept #2 Iteration. Is just a fancy way of saying that you would like something to repeat more than one time. It is used in any modern programming.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
Scratch Programming Session 6 of 10 If-then-else statements interactions Final projects specifications.
1 Chapter 7 Linear Programming Models Continued – file 7c.
Scratch Understanding some programming techniques using Scratch Resetting, Parallelism and Events.
ONE STEP EQUATIONS.
Making a Flappy Birds Game A INTRODUCTION TO MAKING A FLAPPY BIRDS TYPE GAME.
INTRODUCTION TO SCRATCH. About Me Resources Scratch Website Learn Scratch Washington-Lee Computer.
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
Games and Simulations O-O Programming in Java The Walker School
Simplifying Rational Expressions – Part I
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
The Scratch Calculator You are all going to be real computer programmers!!!
INTRODUCTION TO THE SCRATCH PROGRAMMING ENVIRONMENT.
Summer Computing Workshop. Session 4 Loops  At the heart of their functionality, loops enable blocks of code to be executed more than once  Loops represent.
Tutorial for Arrays and Lists By Ruthie Tucker. Description This presentation will cover the basics of using Arrays and Lists in an Alice world This presentation.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
CATCH SCRATCH! Programming from Scratch. Remember Scratch?
Introduction to Scratch!
1 COP 3538 Data Structures with OOP Chapter 8 - Part 2 Binary Trees.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Summer Computing Workshop. Session 2 Input in Scratch  Multi-Character input - This is used when the user is prompted to enter a number or word.  Problems.
Introducing Scratch the Cat
Moving Around in Scratch The Basics… -You do want to have Scratch open as you will be creating a program. -Follow the instructions and if you have questions.
Background – World Wide  Two main systems of measurement  Metric System  Based on the number 10  U.S. Customary System  Based on halving or doubling.
Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch Paul Tennent
Game Maker – Getting Started What is Game Maker?.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech June 2008.
Solving Linear Equations. Example 1 It’s obvious what the answer is. However, we need to start with the basics and work our way up because we need to.
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
CRE Programming Club - Class 2 Robert Eckstein and Robert Heard.
Tutorial for Arrays and Lists. Description This presentation will cover the basics of using Arrays and Lists in an Alice world It uses a set of chickens.
Lesson 2: Reading a program. Remember: from yesterday We learned about… Precise language is needed to program Actors and Classes Methods – step by step.
5.04 Apply Decision Making Structures
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
CRE Programming Club - Class 4 Robert Eckstein and Robert Heard.
How to create a basic game in Scratch. The Scratch Stage The Scratch stage is 480 pixels wide and 360 pixels high x increasesx decreases.
THE “COLLEGES I AM THINKING ABOUT” LIST IN YOUR FAMILY CONNECTIONS ACCOUNT.
Logical Operators.  Quiz  Let's look at the schedule  Logical Operators 2.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
Intro CS – Loops, making animations & films Lesson Plan 3.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
School of Computer Science Space School 2015 Programming a Lunar Lander Game.
DAY 4. MAKING SOMETHING ‘JUMP’ Simple! Move it a certain amount ‘up’ Glide back to your original spot.
Create a Halloween Computer Game in Scratch
Intro CS – Screens and Variables
Scratch for Interactivity
Complex Conditionals Human languages are ambiguous
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Relational Operators.
Review of Previous Lesson
Creating a Simple Game in Scratch
Presentation transcript:

in

 This presentation will only make sense if you view it in presentation mode (hit F5). If you don’t do that there will be multiple slides that are incomprehensible.  When you are done you will have a Scratch program that has code to demonstrate the programming concept ‘Conditional Statements’.  The easiest way to move back and forth between this presentation and Scratch is to use alt-tab.

 Conditional statements are a useful and POWERFUL concept in computer programming.  Conditional statements are what allow the computer to ‘think’.  They do this by comparing and analyzing data.  The computer will make a decision about what to do based on the condition of the data.

 Computers do REALLY well with simple comparisons.  Conditional statements work by evaluating a condition to see if it is TRUE or FALSE.  If the condition is TRUE one set of actions can be performed.  If the condition is FALSE a different set of actions can be performed.  Lets see what that looks like in action…

1) Lets say that you needed to write a program to perform two different actions based on whether or not it was raining. 2) The condition that will be tested is a simple one. 3) IS IT RAINING? 4) There are only two possible outcomes to this condition. 5) It can be either: TRUE or FALSE. 6)This program would be written so that if it was raining you will bring your umbrella with you. 7)If it is not raining you will go to the beach. 8)The computer can perform two separate actions based on one simple question. 9)That’s a very simple explanation of how Conditional Statements allow the computer to think. Is it raining?

 You will create a program that will have a Sprite move 10 steps to the right any time it is located on the left hand side of the screen.  Things to note:  The movement will be triggered by the space key  The starting location of the sprite should be X -200, Y 130  If the sprite is located on the right hand side of the screen then nothing should happen when the space key is pressed  DO NOT DO THIS ON YOUR OWN! Simply keep going through this presentation and you will be walked through this one step at a time.

 Make sure Scratch is open.  Choose ‘File/New’ to get a new Scratch file.  The file name for this assignment will be ‘Conditional Statements Intro’

 This program would be impossible to complete without conditional statements.  Conditional statements will allow the computer to ‘think’ and to determine a course of action based on the sprites current location on the screen.  Lets take a look at how to make this work…

 The ‘If’ statement is a conditional statement  In Scratch it looks like this…

 For an IF statement to work it needs to have something to compare.  Our example will look at the position of our sprite on the screen.  It will then evaluate whether or not the sprite is located on the right half of the screen.  If we are on the right half of the screen nothing should happen.  If we are on the left half we should move 10 steps to the right.

Here is a quick review of how the Scratch screen is arranged. The Scratch stage is 480 pixels wide and 360 pixels high ,0 at the center of the stage Moving right increases the x value Moving left decreases the x value X Y Moving up increases the y value Moving down decreases the y value X Scratch will always show you the X and Y position of your Sprites. Y

 Remember how we said that the IF statement needed something to compare?  The first block has nothing to compare…  Go ahead and make yours look like the second block.  I will explain exactly what that means on the next slide.

 X position will tell the computer what the CURRENT x position of your sprite is.  0 represents the middle of the screen both vertically (up and down) and horizontally (side to side).  This statement will compare the X position of your Sprite to see if it is less than 0.  If your sprite is on the left hand side of the screen it will perform whatever actions you place inside of this block.  It will do that because the condition you are testing is TRUE.

 So now that we have the comparison figured out we need to figure out what we want the sprite to do when x position is < 0.  We want it to move 10 steps to the right.  In order to do that we simply insert one line of code inside the if block.  Go ahead and add that code into the block.

 The trigger is the space key.  The condition will only be tested when the space key is pressed.  Remember that the condition being tested only returns one of two values. It is either TRUE or it is FALSE.

 Go ahead and test your code.  What happens?  Is it what you expected?  Look at the x position of your sprite every time you hit ‘space’  Is it changing?  What happens when X is greater than 0?

 If statements test a single condition.  If that condition is true whatever code is inside the if block will be executed.  If that condition is false NOTHING will happen.

 If / else statements test a single condition.  If that condition is true whatever code is inside the top portion will be executed.  If that condition is false whatever code is in the bottom or ‘else’ portion will execute.

Additional Specs  Trigger is the ‘m’ key  Action:  If your sprite is on the left hand side of the screen it should move ten steps to the right.  If it is on the right side of the screen it should say ‘Stop trying to make me move. I am already on the right side.’ for 2 seconds. Hint 1 Hint 2

o The two blocks of code to the left do the exact same thing. o However, one block is BETTER than the other. o Can you figure out which block is better AND what makes it better?

o In the top block only 1 comparison is needed. o The bottom block uses 2 comparisons to accomplish the same thing. o Therefore you can say that the first block is more efficient because the computer only has to do 1 comparison. o It is VERY important as a programmer to write efficient code