Russell Spitzer’s Blog
Project Walk-through for the Scratch Class Taught at The Made. A simple character moves around eating floating objects. Gravity can be controlled to either draw or repel nearby objects.
Gravity Chomper is a game where you play as a small gravity beast. As it spins happily through a cloud of foods help it eat its favorites (apples, basketballs) while avoiding the foods it hates (bananas).
- 60 Second Time Limit
- Pressing A increases its gravity and D causes it to repel!
- Use the arrow keys to navigate
Step 0 Remove the Cat
We won’t be using the cat in this project so the first thing to do is to delete him. Right Click on the Scratch Cat and select Delete from the drop-down menu.
Step 1 Creating a Gravity Beast
Step 1.1 Choose Draw a new Sprite
In the Sprites Panel click on the icon that looks like a paintbrush next to the words “New Sprite”. This Creates a new Sprite which you will be able to paint.
Step 1.2 Draw your Gravity Beast!
You are free to draw your beast however you like but it helps to have a small and circular shaped creature so it will be easy to control while it spins.
Step 1.3 Rename the Sprite
In the Sprite Panel you now have Sprite1. This is not a very descriptive name so lets rename it. Click on the Blue I in the upper left portion of your Sprite’s picture. Then type in a new name like “Gravitica”
Step 2 Player Controls for Gravitica
Click on Gravitica and then on the Scripts on the top of the middle of the screen.
Step 2.1 When Green Flag Clicked
The player is allowed to control Gravitica for 60 seconds until the game is over. This means we need to have a loop checking for the player’s button presses for 60 Seconds.
Grab a block from the Events Category. This block is the start of your application. Everytime you click on the Green Flag this triggers the start of the game and all the blocks under the block will go into action.
Step 2.2 Event Loop
Underneath the block place a block from the Events category. All of the blocks we place within this C shaped block will be executed until the block we place in the <> is true.
Step 2.3 Event Loop Condition (60 Seconds)
Since the <> is a hexgon we need a hexagon block to fit inside it. We can find hexagon blocks in the Operators category. Choose operators and grab a block. The  is a place where we can either type in our own number or place a block. We want the condition to be false until the block from Sensing is greater than 60
Step 2.4 Controls
Each of our player controls will be an block from the Control category checking whether a key has been pressed using the block from the Sensing Category.
Create an if block and place the block inside it. Then Right Click on the if Block and duplicate it 4 times.
Scratch uses the same coordinate system that you are probably used to from school. In this systems the vertical (down-up) position of an object is determined by and the horizontal (left-right) is controlled by .
For upwards movement we need to increase y. Change the of the first if statement into sensing the up arrow by clicking on the small black triangle next to the word space. Add a block from the motion category to the if statement. Set the value inside to 5.
For downwards movement we need to decrease y. Change the second if statement to the down arrow and add a block from the Motion category. Set the value to -5
For leftwards movement we need to decrease x. Change the third if statement to the down arrow and add a
block from the Motion category. Set the value to -5
For rightwards movement we need to decrease x. Change the fourth if statement to the down arrow and add a
block from the Motion category. Set the value to 5
Step 2 End Move the if blocks into the Event Loop and Test it out
The code should now look like this
Press the green flag and make sure you can move your character with the arrow buttons on the keyboard. After 60 seconds the character should stop moving.
- Can you change the player speed?
- Can you change the time limit?
- Can you make the player say the time left?
Step 3 Apple Swarm
Step 3.1 Grab the apple sprite from the Sprite Library
Click on the little alien next to New sprite and select the apple from the library. Click on the Apple picture in the Sprites Panel and start adding scripts to the APPLE
Step 3.2 Make the apple a good size
Step 3.3 Create lots of apple clones
Step 3.4 Create direction for this sprite only
Step 3.5 Create our clone movement instructions
Step 3.6 Hide the apple
Step 3.6 Test it out
At this point when you press the green flag there should be a swarm of apples going across the screen.
- Can you make the swarm move faster and slower?
- Can you give each apple a different speed?
- Can you make apples come from both sides of the screen?
Step 4 Gravity
** Click on the Stage To the Left of the Sprites Panel and above “New Backdrop” **
Step 4.1 Create Gravity variable for Everyone
Step 4.2 Create Gravity controls and bounds
** Click on the Apple Sprite in the Sprite Panel **
Step 4.4 Have Apples effected by gravity
Step 4.5 Test it out
At this point the apples should go towards the player when you press A and aways when you press S.
- Can you put a max limit on gravity strength?
- Can you make it so that objects that are very far away are not effected by gravity as much?
- Can you make the strength of the gravity effect the movement speed of the player?
Step 5 Points
Step 5.0 Add variables for things being eaten
** Click on the Stage To the Left of the Sprites Panel and above “New Backdrop” **
Reset them all to 0 on Green Flag Clicked
Step 5.1 Make Apples disappear on being Eaten
Step 5.2 Add Bananas
Make a new sprite using the Banana from the sprite library. Copy all the code from the apple by dragging it onto the picture of the Banana on the Sprite Pane. It will look like nothing happened until you click on the Banana and switch to it’s scripts tab.
Step 5.3 Modify Banana Code
Step 5.4 Add Basketballs
Make a new sprite using the Basket Ball from the sprite library. Copy all the code from the apple by dragging it onto the picture of the Banana on the Sprite Pane. It will look like nothing happened until you click on the Banana and switch to it’s scripts tab.Russell Spitzer’s Blog Project Walk-through for the Scratch Class Taught at The Made. A simple character moves around eating floating objects. Gravity can be controlled to either draw or repel
Scratch Basics Episode 9: Coding Costume Changes
Grade 1 – Grade 12
About the Author
Becky is an educator and the Lead Digital Skills teacher at the Lindsay Pinnguaq Makerspace. She is passionate about developing an intrinsic motivation for learning within every student she meets. Becky graduated from the University of the Pacific with a Bachelors of Arts in Liberal Studies with a Major in Human Development and Special Education, and a Masters of Arts Degree in Curriculum and Instruction. Prior to beginning her role as an educator for Pinnguaq, she taught grades sixth through eighth in a Montessori school structure. She also spent five years teaching a range of grades from preschool to eighth grade in Bangkok.
Scratch is a basic coding language that uses a ‘building block’ style coding to create animated stories, interactive games, simulations, and beautiful artwork. In using Scratch, learners will be introduced to basic coding concepts and develop their computational thinking skills while bringing their own ideas to life. In this series, the basics of Scratch will be introduced to provide learners with the foundational skills required to begin creating in Scratch.
Scratch makes it easy for learners who are just starting out by organizing the types of code you can use into categories. The code blocks are grouped by the following categories: Motion, Looks, Sound, Events, Controls, Sensing, Operators, Variables and My Blocks. These code blocks can be pieced together in the Code Area like placing jigsaw puzzle pieces together. Both the Code Area and the Stage are visible at the same time which allows learners to run code, test, debug and view their creations.
According to the Scratch Wiki, Scratch’s coordinate system uses 2 coordinates, “X position” and “Y position”, to determine the location of a sprite on the stage. The “X position” value determines the horizontal location of the sprite and the “Y position” value determines the vertical location or height. Every Scratch project whether it be a game, story or animation will always have the x,y grid behind the stage to determine where sprites are located.
In this episode, learners will explore:
- Coding their sprite to change costumes
The following vocabulary definitions are from the Scratch Wiki.
- Scratch 3.0 Online or Desktop
This episode will take you through the steps of animating your sprite by changing its costumes using code.
Add Your Sprite and Background
- Choose a Backdrop for your project and a Sprite that you want to code to change costumes. If you need help with how to choose a Sprite, see Scratch Basics Episode 2 for more information.
Make sure you choose a sprite that has more than one costume. A costume is another picture of the same sprite that is just slightly different. Some of the sprites in the Scratch library only have one costume, while others have many. To see if a sprite has more than one costume, go to the sprites library and hover over it with your mouse so that a blue outline appears around it. The sprite will flip through its different costumes if it has more than one.
Check out your sprite’s different costumes by clicking on the Costumes tab just above the Block Palette to the left of your Code Area. You’ll see that the different costumes are named and categorized by letters. As you can see below, my dragon sprite has three different costumes: dragon-a, dragon-b, and dragon-c. Each costume is slightly different.
Dragon-a is the default costume that will automatically appear in the Sprites Pane and on your Stage.
Dragon- b is slightly different with bent legs and an elongated neck to look like it is flying.
Dragon-c is breathing fire.
Code Your Sprite to Change Costumes
- We are going to animate our Sprite by changing its costumes. I’m going to animate the Dragon sprite to breathe fire. Start by adding a “when this sprite clicked” Events block into your Code Area.
- Drag a “switch costume to…” block from the purple Looks category in the Block Palette and snap it underneath the “when this sprite clicked” block in the Code Area.
- Click the drop-down menu on the “switch costume to…” block and choose the costume that you would like your sprite to switch to. I’m going to choose costume dragon-c because I would like it to breathe fire!
- Click on the Controls category in the Blocks Palette. These blocks control your scripts, like how many times your code will run or make blocks in your script wait a few seconds before running. Click and drag a “wait 1 seconds” block onto your Code Area and snap it underneath the “switch costume to…” block.
To change the amount of wait time before the sprite changes from one costume to the next, you can change the number inside the white input bubble by clicking on it. For this episode, I have set the seconds to 0.3. This will make the costumes switch quickly and look more seamless than if I had the wait time for one second.
- Add another “switch costume to…” block from the Looks category underneath the “wait 1 seconds” block.
- Click on the drop-down menu on the “switch costume to…” block and choose a different costume than the one in your first Looks block. I’m changing the costume to dragon-a.
- Now you will want to add one more wait block underneath the second “switch costume to…” block. Make sure you change the input number on this block to match the first wait block. As you can see below, both of my wait blocks have the number input of 0.3.
- Now you are ready to test your code! Click on your sprite and watch it switch between costumes. You’ve animated a sprite! Play around with choosing different costumes and different inputs to see how the animation of your sprite changes. What happens if you put a large number in the wait block? What happens if you put in a smaller number?
In this episode you learned basic Scratch concepts such as how to animate a sprite by coding costume changes. What will you create now that you have learned a few Scratch Basics? If you’d like to learn more about animating in scratch, check out Mix & Match Challenge # 1: Animate by Mary from pinnguaq.
We want to see the awesome things you’re creating! Take a photo or video and share your work with us by emailing [email protected] or tagging @pinnguaq on Facebook, Twitter, or Instagram. Don’t forget to include the hashtag #LearnWithPinnguaq! You can also upload your project to the Pinnguaq Studio.
You might also like
Using the Backpack in Scratch
Grade 1 – Grade 12
In this short tutorial, you will learn how to use Scratch’s “Backpack” feature to move code and sprites between projects.
Working with vector graphics art in Scratch
Grade 7 – Grade 12
In this tutorial, you will learn about the differences between vector graphics and raster graphics (also called bitmap graphics or pixel graphics) and how they are used in Scratch as well as how to use Inkscape to make vector-based art for use in Scratch.
Scratch Basics Episode 10: Coding Backdrop Changes
Grade 1 – Adult
In this series, the basics of Scratch will be introduced to provide learners with the foundational skills required to begin creating in Scratch.In this series, the basics of Scratch will be introduced to provide learners with the foundational skills required to begin creating in Scratch. ]]>