Some guy'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).
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.
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.
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.
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”
Click on Gravitica and then on the Scripts on the top of the middle of the screen.
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.
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.
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
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
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.
Challanges
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
At this point when you press the green flag there should be a swarm of apples going across the screen.
Challenges
** Click on the Stage To the Left of the Sprites Panel and above “New Backdrop” **
** Click on the Apple Sprite in the Sprite Panel **
At this point the apples should go towards the player when you press A and aways when you press S.
Challenges
** Click on the Stage To the Left of the Sprites Panel and above “New Backdrop” **
Reset them all to 0 on Green Flag Clicked
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.
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.