moving around in scratch the basics… -you do want to have scratch open as you will be creating a...

24
Moving Around in Scratch The Basics… want to have Scratch open as you will be creating a program. the instructions and if you have questions grab me and I will help

Upload: dwain-osborne

Post on 02-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 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

Moving Aroundin 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 grab me and I will help you out.

Page 2: 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

The BasicsFile Name

Command Groups

Commands

Page 3: 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

Getting your Specs (specifications)• When you are a programmer you are handed instructions.• Those instructions are often called specs, which just means

the specifications or specifics of the program that you are going to write.

• The specs will explain to you what the program will do.• Well written specs leave little to the imagination. They

should be as specific as possible.• If you read the specs and still have questions about how the

program is supposed to work you should go to the person that wrote the specs and discuss your questions with them.

• It is ALWAYS better to eliminate confusion BEFORE you start to code.

Page 4: 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

Poorly Written Specs• Let’s use some poorly written specs to learn

about the programming process as well as how to move around in Scratch.

Page 5: 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

Your Specs• You will write code to make a sprite move

around the screen following the pattern of a rectangle.

Page 6: 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

First Things First• Change the background to use the xy grid.

Click this button to select the correct background

Page 7: 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

First Things First• It should look like this before you begin.

Page 8: 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

First Things First• Change the file name for this project to

‘Moving Around in Scratch’• Make sure to save your work frequently. Even

though this is stored in the ‘cloud’, which is really just another off site server, you still want to save frequently.

• The cloud just like anything else that involves programming and electricity is NOT PERFECT.

Page 9: 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

Problem #1• The default starting position of Sprite1 is x=0 and

y=0.• That’s probably not where we should start to move

around the screen in a rectangle.• If this was a real world situation you would get with

the person that wrote the specs and ask them for more specific direction about where the sprite should start.

• In this case I am the guy who wrote the specs so I will say the sprite should start in the upper left hand corner. It’s still not very specific but it does give you enough to get the ball rolling.

Page 10: 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

First Try• The starting point for Sprite1 is x -187 Y 115• Which will look like this.

Page 11: 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

Why Specs Are Important• One way to accomplish the task of moving

around the screen in the pattern of a rectangle is accomplished with the code on the next slide.

• Go ahead and put this code in and we will break it down line by line.

Page 12: 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

Is this what we wanted?

The trigger is the ‘Space’ key

When you run this code what happens?Does anything happen?

Well let’s make a few changes and then run the code one more time.

Page 13: 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

A Closer Look

When you run this code you see that you are in fact moving around the screen in the pattern of a rectangle but…

Do you really think this is what the specs want you to do?

Holds here for 1 second before going to the next command.

Page 14: 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

Go To

• The go to command will ‘jump’ you to a specific x and y location on the screen.

• The jump is immediate and you will not see the Sprite move.

• When using a go to the direction that the sprite is pointing DOES NOT MATTER.

Page 15: 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

Second Try• The starting point for Sprite1 is x -187 Y 115• Leave all of the code from the first try

Page 16: 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

Is this what we wanted (part 2)?

The trigger is the ‘a’ key

- When you run this code what happens?

- It looks exactly like the last code so lets slow it down a little bit.

- Make the modifications on the next slide and then run the code again.

.

Page 17: 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

A Closer Look- You have now seen two different ways to

move around the screen in the pattern of a rectangle but in both cases the Sprite moves so fast that we can’t even see it.

- We are forced to use the ‘wait 1 secs’ command to slow the program down.

- That might be something that we want but since the specs aren’t specific enough we just don’t have enough information to know for sure.

- IMPORTANT – Make sure to run the code a few times so that you can get a sense for how SEQUENCE works. The wait command is slowing the computer down so that you can actually watch it execute the commands you have given it in the SEQUENCE that you gave them.

Page 18: 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

Move

• Can move in small increments like 10 steps or large increments like 100 steps.

• Will move in whatever direction the sprite is currently facing.

• If you want to move backwards you can use a negative number and the sprite will move in reverse.

Page 19: 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

One More Time• The starting point for Sprite1 is x -187 Y 115• Leave all of the code from the first & second

attempts

Page 20: 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

Is this what we wanted (part 2)?

The trigger is the ‘b’ key

- When you run this code no wait is required.- When you run this code you can actually see the Sprite moving from

position to position.- This seems more like what we are looking for but again, we just don’t

know because the specs ARE NOT CLEAR.- That means we are guessing and guessing is NEVER good in

programming.

.

Page 21: 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

Glide

• Will move to a specific x and y location on the screen

• Will take however long you specify to get there.

• You can make the Sprite go very slow or very fast.

Page 22: 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

What you Learned

• Specs (or program instructions) need to be specific and leave as little room for confusion as possible.

• In programming there is almost always more than one way to accomplish the same task.

• How to move your sprites using go to, move, and glide.

Page 23: 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

Programming Challenge• If you are finished early please accept this

programming challenge.• In the last example that uses glide you may have

noticed that the only time Sprite1 was facing the correct direction was when he was moving across the screen towards the right.

• See if you can find a way to make him point in the right direction when he is moving to the right or to the left.– Hint: You will need to create a new costume for this.– If you accomplish this task it is worth 5 extra credit points.

Page 24: 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

Extra Challenges• Make your sprite do a 360 degree rotation

each time he/she hits a corner of the rectangle.

• Make your sprite SHRINKS by 30 units each time it hits the bottom right corner

• Make sure it gets resized back to ‘normal’ when it reaches the top left corner (where it started)