Introduction to Computer Programming - Project 2 Intro to Digital Technology.

Slides:



Advertisements
Similar presentations
Create a Simple Game in Scratch
Advertisements

Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
SCRATCH Lesson Two – Interactive Concepts Using Sensing, Operators, and Variables.
Create a Simple Game in Scratch
Scratch for Storytelling Dr. Ben Schafer Department of Computer Science University of Northern Iowa.
Harry Potter Scratch Game
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
A Christmas Scratch game
Code Club Session 3 Shark Eats Fish. Picture of finished product here.
Write Your First Computer Game!. Coding: Programming Languages Just like you can speak Chinese to someone who understands Chinese to tell them what to.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
Session 5 of 10 Review + Multiple Sprites
1 An introduction to programming concepts with Scratch.
Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech June 2011.
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
Fish Chomp. The screen where you can see what happens when you play your game is called the STAGE. The SCRIPT BANK is where the types of instructions.
Scratch the Cat. Object Oriented Programing Writing computer programs Based on Objects Instead of Actions Based on Data Instead of Logic.
INTRODUCTION TO THE SCRATCH PROGRAMMING ENVIRONMENT.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
An Introduction to Textual Programming
Making a Timer in Alice.
Code Club Session 2 Dance Party. What will we learn ?  How to change the background  How to create animations  How to make objects talk to each other.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Section 3 Calculations National 4/5 Scratch Course.
Section 2 Variables National 4/5 Scratch Course. What you should know after this lesson What a variable is Where variables are stored How to get data.
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.
Summer Computing Workshop. Introduction  Boolean Expressions – In programming, a Boolean expression is an expression that is either true or false. In.
2015 CSE/EGR Summer Camps 1 Computer Science Concepts 1. What is an algorithm? 2. Binary information coding 3. Programming concepts via Scratch Designed.
1 Understand how to use Scratch to: – Animate a sprite – Add sound to your script – Use the forever command to create a loop Lesson 2: Learning Objectives.
Fish Chomp. The screen where you can see what happens when you play your game is called the STAGE. The SCRIPT BANK is where the types of instructions.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech June 2008.
Making a Sprite Dance Barb Ericson Georgia Tech June 2011.
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
Computer Programming Modeling a Passive Solar Home.
Variables and Random Numbers Computer App Session 4.
Using MIT Scratch for Programming and Control Exercise 1 Creating movement Year 11 DTG 2012.
Open a new Flash File Action Script 2.0. Create a button like you did last lesson and name it Click to Play.
Cloning in Scratch Computer App Session 6. Cloning in Scratch Learning Objectives: I will clone sprites in Scratch to create copies of an existing sprite.
Introduction to Computer Programming - Project 1 Intro to Digital Technology.
Scratch for Interactivity Dr. Ben Schafer Department of Computer Science University of Northern Iowa.
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.
Computer Programming Modeling a Passive Solar Home.
Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Introducing Scratch Learning resources for the implementation of the scenario
Objective of the lesson Use Blockly to make a dice for Snakes and Ladders All of you will: – Make an image which displays when you press a button Most.
Functions / Blocks.
Create a Halloween Computer Game in Scratch
Broadcasting (Adding a new level)
Scratch for Interactivity
Madlib-Input, Strings, and Lists in Scratch
What is it?! •Scratch is a programming language that allows you to create interactive stories, music, animations, art, games, and more!
Scratch Unit Overview We are going to look at computer programming and how to create your very own computer game The piece of software we will be using.
Spanish Mad libs with Scratch
ECS 9/7/17.
Introduction to Object-Oriented Programming
Scratch Programming Intro
Go to =>
Welcome to SCRATCH.
Introduction to TouchDevelop
Scratch for Storytelling
Go to =>
Go to =>
Variables & getting info from the user
Game Over Module 4 Lesson 2.
Creating a Simple Game in Scratch
Presentation transcript:

Introduction to Computer Programming - Project 2 Intro to Digital Technology

Costumes A great feature of Scratch is that sprites can have multiple costumes. A sprite’s costume is the image that shows when the sprite (object) is on the screen. Some have only one, but if it has more than one, you can also use programs to change the sprite’s costume. Use the ‘Costumes’ tab to see a sprite’s costumes.

Costumes If you check, you’ll see that the cat sprite has 2 costumes, so let’s change it. Get 4 ‘next costume’ and 4 ‘say something for two seconds’ blocks and lock them together alternating between each one (next costume, say, next costume, say, etc.) and run your program. You’ll find out on the next slide why you had to also use the ‘say’ blocks.

Control A program will run as fast as the computer can run it. Sometimes this is too fast, and you might need a delay between steps. Lock 4 more ‘next costume’ blocks in a separate program and run it. Do you see any changes? It’s running so fast you don’t see each change. That’s why you put the ‘say for 2 secs’ blocks in there before – to make it pause between each change so you could see it. There’s a better way…

Control To make your program pause, you need to use a block from another category – Control. These blocks control a lot of things about how and when your programs run. For now, we’re only interested in the ‘wait # secs’ block, which makes the program stop for the specified time. Drag one of these into the program you just created in between each ‘next costume’ block. Run it and see what happens. Change the wait value and see the effect. You can use decimal values if you need fractions of seconds.

Strings & Numbers Strings are combinations of letters, numbers, symbols, etc. They’re treated like characters (even the numbers), and the computer cannot do math with them. In Scratch, if you enter something into a rectangle input box, it will be treated as a string. Make your sprite say 2+2 and see what it says. 2+2

Strings & Numbers Numbers include only numbers and valid numeric symbols (+, -, etc.). The computer CAN do math with numbers. In Scratch, numbers are entered into rounded input boxes. In fact, Scratch prevents you from entering non-numeric values into these boxes. Find a block with one of these rounded input boxes and try to enter a letter into it.

Calculations To do mathematical calculations in Scratch, you have to use another category of blocks - Operators. These allow you to do basic math, compare values, and perform other types of calculations. The operator blocks can be dropped into any input box (rectangle or rounded) on any block, and Scratch will first calculate the result then use it in whatever action the block does. Drop an add (+) operator into a ‘say…’ block, put a ‘2’ in each of the input boxes, then see what the cat says. 4

Calculations You can ‘nest’ operators (put one inside the other) to create complex calculations. Programming languages follow the order of operations (PEMDAS) when doing math. Scratch does this by the way you nest your operators. As you nest them, it puts them on higher layers. The layers are computed top to bottom. Start with an + operator and put a multiply (*) one in the second box. Put 2s in all boxes, put the whole thing in a ‘say...’ and see what you get. Reverse it and try again. 6? 8?

Random Numbers One thing practically all programming languages can do is generate a random number, an unpredictable value from a specified range. This is useful for games, simulations, etc. In Scratch, this is done using an operator called ‘pick random x to y’, where x and y specify the range of numbers from which to choose (they default to 1 and 10). Drag a ‘say’ block into the scripts area, then drop a ‘pick random’ block into its input area. Run it several times and see what you get. ? ? ?

Variables A computer has a memory and can remember stuff. To get a computer to remember stuff, you use variables. A variable is a name you specify for a location in the computer’s memory where it can store a piece of information. Many languages are picky about what you can name a variable – no spaces or special characters, can’t start with a number, etc. Luckily for us, Scratch isn’t that picky about what you call one.

Variables To use a variable in Scratch, you have to create it first in the Variables category. You can then use it to hold on to any information you want. For example, suppose you’re writing a game and you want to a way to keep score. Click the ‘make a variable’ button and create a variable called ‘score’. We want this variable to be visible by all sprites (a ‘global’ variable), so make sure ‘For all sprites’ is checked. Click OK.

Variables Once you create a variable, it shows up in the Variables category. There are also blocks there to set the variable to a value and to change a variable’s value. When you want to use the variable in any other way, you’ll need to drag and drop it in the input area of other blocks. Notice that it is also displayed on the stage. If you don’t want it displayed, uncheck the checkbox next to the variable name in the Variables category.

Variables Clear out your scripts area, then drag a block to set ‘score’ to 1. Drag 3 ‘change’ blocks and attach them to the ‘set’ block. Make sure the change blocks are changing the score variable, and change the values to something between 1 and 100. Insert a ‘say’ block after each variable block to say the value of the score variable. You’ll have to drag the variable into the say block for it to work.

More Controls What if you wanted a group of blocks to run more than once? Maybe run forever? In a program, running a set of commands multiple times is called a loop. Some of the control blocks can do just that. Look in the Control category and find the ‘forever’ and ‘repeat 10’ blocks. Notice that they’re shaped sorta like a ‘C’. This allows you to put other blocks inside the ‘C’, and it will expand to hold them as you insert the blocks.

More Controls The ‘forever’ block will run the blocks inside it over and over until you click on it again to stop. This is known as an endless loop. In most cases, it’s not a good thing. Notice there’s no tab at the bottom of it. You can’t attach blocks below it, because once you’re in the loop, you can’t get out. The ‘repeat 10’ block will run them the number of times specified in the input box – it defaults to 10, but you can change it.

More Controls Clear your scripts area and drag a block to set the score to zero. Attach a ‘repeat 10’ block below it (not around it) and change the repeat value to any number Attach a block inside the repeat block to change the score by 1. Attach a block to the bottom of the repeat block to say the score. Run it and see what happens.

Programming Project 2 Now it’s your turn once again: 1.Prior to creating the script, create 2 variables, one to store a delay value, one for ‘loop control’. Then create a script to do the remaining steps. 2.Set the loop control to a random number between 5 and Position the sprite at X:-125, Y:0. 4.Add a repeat loop block and insert the loop control variable into the loop count. 5.Put the following in the repeat loop: 1.Say a message of your choice (just use the plain ‘say’ block). 2.Switch to the next costume. 3.Set the delay value to a random number between 1 and 5. 4.Divide the delay value by 10 (hint – set it to itself divided by 10). 5.Insert a wait block and use the delay variable for the value. 6.Move 10 steps. Save this in your Intro to Programming folder using this file name: Project 2