Tag Archive for: Scratch

We describe our top 5 favorite tools to learn computer science for kids in grades K-8.

  1. Code.org – code.org
  2. Tynker – tynker.com
  3. Scratch Jr – Downloadable app for iOS, Android, and ChromeOS – scratchjr.org
  4. Scratch – scratch.mit.edu
  5. Microsoft MakeCode – arcade.makecode.com

Watch the video and leave comments or questions . Please don’t forget to subscribe or like the video if it is fun and educational!

Create a Turkey Hide Game in Scratch

Learn coding while you create a fun turkey hide game in Scratch.

Follow along with me and make your own version of the game. It’s holiday-themed fun!

Credit to Maytal at Create Code Load for the inspiration!

Watch the video and leave comments, questions, or share your own creations! Please don’t forget to subscribe or like if the video is fun and educational!

 

What is Scratch

Scratch is a great block-based coding program used to help beginner coders learn the basics in programming, computer science, and computational thinking. We like to use it in the classroom because it helps students grow and learn without complex scripting.

Watch on YouTube.

We don’t know what programming languages will look like in the future. It’s most important to us students understand the concepts first. Once they understand how programming works, like when to use an ‘if statement’, then they’re better equipped to learn any coding language.

We also believe problem solving and learning computational thinking as the frame work will lead students to become better learners and future employees.

Intro to Animation Using Scratch 3rd-6th Grade

I guide 3rd-6th graders in an exercise on animation in Scratch. Scratch is a great online tool to learn the foundations of computer science and coding in a fun way. Follow along to learn how to animate your sprites. This 24-minute video was presented as a livestream on YouTube on March 25, 2020.

Watch full video.

Alien Attack - TechWise Academy

In Part 1: Create Your Own ‘Alien Attack’ Game on Scratch, we covered how to set up your game with all the necessary players, sprites, and variables for our new game. This next part of the series covers how to move around Player1 and shoot a laser across the screen.

This part of the tutorial assumes you’ve completed Part 1 and you know how to move blocks into your workspace and connect commands. If you’re new to Scratch or this game, I recommend you start in Part 1 in the link above.

Moving Player1 on Screen

We want to move Player1 around to shoot and dodge the aliens. This is done through Events when certain keys are pressed. These are some of the simpler commands and actions for this game. Once you get one, you’ll get the rest in no time.

Select the Player1 sprite (your spaceship) for these movement controls.

Alien Attack Player 1 MovementWe will show you the first command and challenge you to do the next steps.

When Up Arrow Key is Pressed

  1. Go to Events and drag when space key pressed to your workspace
  2. Go to Motion and drag change y by 10 below your new event block
  3. Change space to up arrow to read when up arrow key pressed

Your final block should read when up arrow key pressed – change y by 10.

Changing Y

Imagine Y as up and down. A positive number means you’re going up, and a negative number means you’re going down. So changing by 10 will move you up, and changing Y by -10 will move you down. Try this in your remaining movements.

Challenge: Set up your blocks so Player1 moves down when you press the down arrow. Extra Credit: What if you do the same for pressing w and s for the traditional wasd keyboard commands for PC games?

Make Your Laser Move

We want the laser to move across the screen. There are no aliens to shoot yet, but we want to make sure the laser moves across the screen when we press a button (more on that next).

Select the Laser sprite for this next block. At this point, your Scripts tab should be empty.

Setup: Hide the Laser at Start of Game

We only want the Laser sprite to appear when we press a button. At the start of the game, we will hide the Laser at Player1. 

  1. Go to Events and drag when flag clicked to our workspace
  2. Go to Motion and drag go to mouse-pointer below your new event block
  3. Change mouse-pointer to Player1
  4. Go to Looks and drag hide below your last block

Cloning: One Sprite, Many Lasers

We don’t know how many times Player1 will shoot a laser. Scratch gives us the ability to create clones which makes copies of the sprite for the game. When Player1 presses a button, we want a clone of the laser to be created and shoot across the screen. The next block is about creating clones.

Alien Attack: Laser Sprite Movement

Click to enlarge

Select the Laser sprite for this next block.

  1. Go to Control and drag the when I start as a clone block to your workspace
  2. Go to Motion and drag go to mouse-pointer below your new event block
  3. Change mouse-pointer to Player1
  4. Go to Motion and drag set x to 0 below your last block
  5. Change the value of x from 0 to -160
  6. Go to Looks and drag show below your last block

We’re not finished! This will only make your laser appear. We need it to move across the screen.

Complete the following steps in the same block:

  1. Go to Control and drag repeat until below your last block (this is a loop – very important!)
  2. Go to Sensing and drag touching ? within your repeat until block (see picture)
  3. Change value of touching to edge
  4. Go to Motion and drag change x by 10 and place inside the repeat until loop
  5. Go to Control and drag delete this clone to the very end of our blocks

Now our laser will clone, move across the screen, and delete the clone when it touches the edge of the screen. This is a good programming practice to delete or remove sprites/objects when we’re done with them when your code gets more complex.

Shooting Lasers with Player1

We’re almost done! We want to shoot lasers when we press the space bar. The laser knows what to do when we call the clone, but the game doesn’t know when to make the clone. That’s what we’ll do here.

Alien Attack Player1 Shoots LaserSelect the Player1 sprite (your spaceship) for these controls.

  1. Go to Events and drag when space key pressed to your workspace (start a new block set)
  2. Go to Control and drag create clone of myself under your last block
  3. Change myself to laser to read create clone of laser

Now you’re able to shoot lasers! Start your game by pressing the green flag and watch what happens.

What happened? You’re able to spam the lasers by holding the space key. What we want to do is make the game wait just a little bit to make it a little harder.

  1. Go to Control and drag wait 1 secs below the when space key pressed block
  2. Change 1 to 0.1 secs

Your new control should be placed between your space key and clone block. This forces the game to wait a little bit. You can make this longer.

Challenge: Play a sound when you create the clone. Where would you add it?

Click the green flag above your game and move around and shoot lasers. Good ol’ fashioned gaming!

In this series:

See the Full Game

Alien Attack - TechWise Academy

In May, we introduced Alien Attack, a game we created to highlight many of the lessons we learned through the first three levels of our instructional courses. In this series, we’re going to walk through how to create the game from start to finish. Our hope is you’ll be able to take the lessons learned from creating this game and add to this game on your own or use them to create your own game.

To follow this tutorial start a brand new Scratch project. This first part only starts with the setup of the game, and you’re encouraged to check the full game at the end of the article for reference.

Setup: Backdrop and Sprites

Alien Attack: Sprites and Backdrop

Click to enlarge.

We wanted the player to drive a rocket in space and fight giant alien octopuses for this game. We needed to set a backdrop and create the necessary sprites and objects.

Stage/Backdrop

For the Stage, go to Choose backdrop from library. Select “space” from the “Space” category.

Sprites

Delete the original sprite. Then select Choose new sprite from library for each of our new sprites.

We have 3 distinct sprites or objects in this game:

  • Player1 – that’s you!
  • Laser
  • Octopus

Spaceship

  1. Select “Spaceship” from the “Space” theme.
  2. Go to Costumes at the top of your screen, and rotate the spaceship to face right and center it.
  3. Adjust the size to your liking. We made it a little smaller to fit our game.
  4. Rename the sprite to Player1.

Laser

  1. Select “Paddle” from the “Things” category.
  2. Go to Costumes at the top of your screen, and adjust the size to be a little smaller than your spaceship.
  3. The “Paddle” is green by default. We changed ours to red by using the color tools.
  4. Rename the sprite and costume to Laser.

Octopus

  1. For your enemy, select “Octopus” from the “Animals” category.
  2. Go to Costumes at the top of your screen, and adjust the size to your liking.
  3. Flip it horizontally. For simplicity, you only need to do this on the first costume called “octopus-a.” We do this so the octopus aliens will be facing your spaceship.
  4. Make sure the sprite is named Octopus for this game.

Setup: Variables

We’re going to need a lot of variables in this game. There are a lot of moving parts, and we want the game to get harder as it goes along. See the list of variables below along with why we need them.

New to variables? You can learn more about variables in our other tutorial.

Create all variables in the Data portion of your scripts. Make sure each variable has the For all sprites button checked.

  • BaseSpeed – this is the basic speed of our octopus aliens
  • HP – this is Player1’s health
  • Level – this is your current level to track your progress
  • MaxSpeed – this is the maximum speed we want our octopus aliens to travel
  • MaxTimer – this is the maximum amount of time in between each octopus alien’s spawn
  • MinSpeed – this is the minimum speed we want our octopus alients to travel
  • MinTimer – this is the minimum amount of time in between each octopus alien’s spawn
  • Player_Y_Position – this keeps track of Player1’s current y position (more on this later)
  • Score – this is Player1’s score
  • Seeker_X_Activate – later in the game we make our octopus aliens movement more difficult so this is important later

Once all variables are created, you’re ready to move on!

Setup: Starting the Game

Alien Attack: When starting the gameIn this final setup, we want certain things to happen when the game starts every time.

Before you begin, make sure the Player1 sprite is selected.

Setting Looks, Position, and Data

  1. Go to Events and drag when flag clicked to our workspace on the right
  2. Go to Looks and drag switch costume to spaceship-a to the workspace directly below the flag
  3. Go to Looks and drag switch backdrop to space to the workspace directly below your last block
  4. Go to Motion and drag set y to 0 to our workspace directly below your last block
  5. Go to Motion and drag set x to 0 to our workspace directly below your last block
  6. Change set x to -200 (this sets your spaceship in the same spot at the start of every game)
  7. Go to Data and drag set Score to 0 to the workspace directly below your last block
  8. Go to Data and drag set HP to 0 to the workspace directly below your last block
  9. Go to Data and drag set Level to 0 to the workspace directly below your last block
  10. Go to Data and drag set MinTimer to 0 to the workspace directly below your last block
  11. Go to Data and drag set MaxTimer to 0 to the workspace directly below your last block
  12. Change Score to 0
  13. Change HP to 3
  14. Change Level to 1
  15. Change MinTimer to 1
  16. Change MaxTimer to 3

Go to Data and check the boxes next to HP, Level, and Score so they’re visible at all times.

Adding Space Ripple Sound Effect

We added a space ripple sound effect to play each time the game starts to add a little flair to the game.

Make sure Player1 is still selected.

  1. Go to the Sounds tab at the top of your workspace
  2. Click Choose sound from library button (looks like a speaker)
  3. Click the Effects category
  4. Choose space ripple and click OK
  5. Go to Scripts tab at the top of your workspace
  6. Go to Sound and drag play sound space ripple to the workspace directly below your last block

Click the green flag above your game and see all the variables get set and your sound play!

Now we’re ready for part 2!

See the Full Game

Example of using variables in Scratch

We like to use Scratch to help teach the basics in coding through interactive stories, games, and animations. If you’ve attended one of our courses, you’ve probably used it before. We’re going to take a moment to talk about variables and why using them will help improve your work in Scratch and any programming languages.

Using Variables Makes Things Simple

Variables can be just about anything, but in Scratch we typically use variables for numbers or text. Variables can do things like:

  • Allow you to use the same number in many places but only create or change it once
  • Change a number as many times as you want while your program is running
  • Track something that is moving on the screen
  • Say something you want when you need it
  • And more

An Example Using Variables

Imagine your game starting at level 1. Every time you score 5 points we want the game to “level up.” We could take the long way around and do math like 25 / 5 = 5, but that’s a lot of code to think of every possible number we would want to divide by. Variables let us set up things we want to use to make this feature of our game much easier to manage.

Make a variable in ScratchStep 1: Create two variables

Open up your Scratch game and click the Data section. Click Make a Variable. Name it Score. Now repeat and make one named Level.

Step 2: Set up the game

Our game is going to be simple just to show the power of variables so we’re not going to worry about making our sprite (who should be a cat) move. We’re going to make the score go up 1 every second, and at 5 seconds we’re going to level up.

Set your variables once your game startsFirst, we need to start by setting a value for each variable. Let’s begin. You can follow along by using the images.

  1. Go to Events and drag when flag clicked to our workspace on the right
  2. Go to Data and drag set level to 0 to the workspace directly below the flag
  3. Go to Data and drag set level to 0 to the workspace directly below your last block
  4. Change one to Score
  5. Change the Level to 1

Step 3: Changing our first variable

Let's count time! Using a variable to count every secondWe want the score to go up by 1 for each second that passes. This is done really easily.

  1. Go to Control and drag the forever block below your last block
  2. In Control, drag wait 1 secs to inside the new forever block
  3. Go to Data and drag change Level by 1 to after the new wait block
  4. We don’t want the Level to go up yet; change Level to Score

Hit your Green Flag or GO button to watch your score go up every second. Congrats! You’re counting time!

Step 4: Level up!

Adding an if block to our script to change level if score reaches 5Every time the Score reaches 5 we want the Level variable to go up. Essentially we’re leveling up. We’ll reset the score in this case to make it very easy to track and watch.

  1. Go to Control and drag the If…then… block after your change Score by 1 block
  2. Go to Operators and drag the equals operator into the If…then… block
  3. Go to Data and drag the Score variable (looks like a circle) to the first empty box in your new equals operator
  4. In the remaining empty box in your equals operator, type 5 (Bonus: if you make this a variable of it’s own!)
  5. Go to Data and drag change Level by 1 inside your If…then… block

Last step: Reset the score

What are we missing here? We are only leveling up if we reach a Score of 5. We need to set the Score back to 0 to start the count over.

  1. Go to Data and drag set Level to 0 to after your change Level by 1 block
  2. Change your new set Level block to set Score to 0

Hit your Green Flag or GO button to watch your score go up every second and your level adjust every time your score reaches 5. Congrats! You now have a way to use variables to track numbers, or data, and have an interaction happen.

Double Bonus: This program will run forever if you let it. How would we cap this at 10 levels?

Example of using variables in Scratch

Bonus Knowledge About Variables

Variables make a developer’s life much easier when doing complex functions and actions. It’s best practice to use variables wherever possible. This way your program becomes more flexible if you want to make little tweaks here and there. Where else could you use variables in this example we provided? Please feel free to share your projects in the comments below.

Use our Variables Example project to get started.

Scratch is a powerful tool that allows your student to fully explore programming logic.  Where other tools guide you along the way, Scratch gives creative freedom.  We typically use this tool during the second half of our sessions to reinforce concepts and to see what the kids come up with.

This short tutorial will demonstrate how to randomly animate a sprite.  It can be used to create enemies, obstacles, or just background graphics for your Scratch experience.

What is a Sprite?

First off, a ‘sprite’ is Scratch’s terminology for any object in which you can apply programming logic. They are located in the bottom middle portion of your Scratch interface.  Typically students really enjoy adding new sprites as it allows them to choose their own characters and objects.

ScratchTip1

For this example, we’ve created a dog sprite that our cat will need to avoid.   The dog will randomly move around the screen making it difficult for our cat to reach the ball.

Step 1: Move the Dog

Since the dog will move as soon as we start we want to use the ‘when clicked’ event from our control blocks.  This tells us that when we click the flag above our animation, execute the code immediately under this block.  Drag the ‘when clicked’ block to your workspace on the right.

ScratchTip2

Step 2: Move the Dog “Forever”

Now we want to tell the code that the dog should move forever.  We don’t want him to stop until we stop the game.  Drag the ‘forever’ block from the ‘Control’ section immediately under ‘when clicked’ in your workspace.  It should look like:

ScratchTip3

What do we want the dog to do forever?  Move around, right?  There’s a really cool block in the ‘Motion’ section called glide.  It allows you to specify how many seconds and to where your sprite should glide.  Drag the glide block inside the forever block in your workspace.

ScratchTip4

Step 3: Animate

That’s great but we’re not quite finished yet.  Why doesn’t this achieve our goal?  Well, we’re telling our sprite to glide for 1 second to a specific x,y location.  Once they get there they’ll just stay (at -94x, 40y in this example).  We want to make the movements completely random in this example.

Under ‘Operators’ you’ll find a ‘pick random 1 to 10’ block.  You can use this to create the desired effect.  We’ll need three random generators: 1) number of seconds; 2) x coordinate; and 3) y coordinate.

Number of seconds is easy.  We’ll use the default 1 to 10 numbers in the random generator.  Drag this block into the white area around the number ‘1’ in the glide block in our workspace.  It should look like:

ScratchTip5

For the x- and y-coordinates, we’ll have to modify the numbers in the random generator.  Our x-axis in Scratch runs from -240 to 240.  That’s what we’ll put in and then drag into the x: area of the glide statement.  Our y-axis runs from -180 to 180.  Use the same process for it.  Your finished workspace should look like:

ScratchTip6

You can click the start flag at the top and your sprite should be randomly moving around the screen at different speeds.

Try it Out

The full example can be viewed online here:  https://scratch.mit.edu/projects/84587392/

Click ‘See Inside’ to see all of the code.

Have fun!