0% found this document useful (0 votes)
207 views3 pages

How To Make Gravity in Scratch 3

This document provides instructions for coding a platformer game in Scratch where the player controls a jumping cat sprite to collect apples and avoid crabs. It describes how to: 1. Add gravity and landing detection so the cat falls and lands on platform sprites instead of the bottom of the stage. 2. Allow walking up gentle slopes but prevent walking up steep slopes acting as walls. 3. Make the cat jump higher or lower depending on how long the jump button is held down, unlike previous games with a fixed jump height.

Uploaded by

sonia maklouf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
207 views3 pages

How To Make Gravity in Scratch 3

This document provides instructions for coding a platformer game in Scratch where the player controls a jumping cat sprite to collect apples and avoid crabs. It describes how to: 1. Add gravity and landing detection so the cat falls and lands on platform sprites instead of the bottom of the stage. 2. Allow walking up gentle slopes but prevent walking up steep slopes acting as walls. 3. Make the cat jump higher or lower depending on how long the jump button is held down, unlike previous games with a fixed jump height.

Uploaded by

sonia maklouf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Continue

How to make gravity in scratch 3

The first Super Mario Bros. game was introduced in 1985 and became Nintendo's largest video game franchise and one of the most influential games of all time. Because the game involves making a character run, jump and jump from platform to platform, this style of play is called platform game (or platform game). In the Scratch game of this chapter, the cat
will play the role of Mario or Luigi. The player can have the cat jump around a single level to collect apples avoiding the crabs that will steal them. The game is timed: the player has only 45 seconds to collect as many apples as possible while trying to avoid the crabs! Before you start coding, look at the final program in . Get ready to schedule a more
complicated game than previous chapters! Let's sketch on paper what the game should look like. The player controls a jumping cat while the apples appear randomly. Crabs walk and jump around the platforms randomly, too. Here's what we'll do in each part: A. Create Gravity, Fall, and Landing B. Handle steep slopes and walls C. Make the cat jump high and
low D. Add ceiling detection E. Use a shock box for the cat sprite F. Add better animation to walk G. Create the H level. Add crab and apple enemies This platformer is the most ambitious in the book, but anyone can code it if they follow the steps in this chapter. Let's code each part one step at a time. If you want to save time, you can start from the skeleton
project file, named platformer-skeleton.sb2, in the ZIP resources file. Go to and download the ZIP file to your computer by right-clicking the link and selecting Save Link As or Save Destination As. Extract all files from the ZIP file. The skeleton project file has all the sprites already loaded, so you only have to drag the code blocks to each sprite. CREATE
GRAVITY, FALLING, AND LANDING In the first part, we'll add gravity, drop and landing code, similar to the basketball game in Chapter 4. The important difference is that in platform game, the cat lands when it touches a ground sprite instead of the bottom of the stage. Coding is a little more difficult, because we want the ground to have hills and finally
platforms! To get started, click the text field at the top left of the scratch editor and rename the project from Untitled to Platformer. Let's use a simple ground shape in the first scripts, just to explore how the code will work. Click on the Paint new sprite next to New Sprite to create a temporary ground sprite while learning about platform code. In the Paint Editor,
use the Brush or Line tool to draw a shape for the floor. You can make lines thicker by using the Line Width slider in the lower-left corner of the Paint Editor. Be sure to draw a smooth slope to the right and steep slope on the left. Open the sprite information area and rename the Ground sprite. Also, rename the Cat Sprite1 sprite. Now that we have a sprite for
the ground, we need the cat to fall and land on it. Select the Cat sprite. In the Orange Data category, click the Create a variable button and create a Variable Only for this sprite named y-speed. Next, add the following code to the Cat sprite: this code performs two actions in its loop forever: it causes the Cat sprite to drop until it touches the Ground ➊ sprite, and
then lifts the Cat sprite if it is deep in the ➋. With these two sections of code, the cat will fall, hit the ground, and then rise if necessary, finally sit on top of the ground sprite. The code that falls ➊ subtracts 2 from the speed variable and then moves the Cat position and sprite by speed and, making the jack fall faster and faster. If you scheduled the basketball
game in Chapter 4, the fall code should be familiar. But repetition until the block is ➋ repeated until the Cat sprite no longer touches the Ground sprite. (If the cat is still in the air and falling, it will not touch the ground, so the code in the loop is ignored.) Within this loop, the speed and is set to 0 so that the Cat stops falling further. The change block and by 1 will
lift the Cat sprite a bit. Repeating until you touch the Ground block continues to lift the sprite until it no longer sinks into the Ground sprite. This is how the cat stays at the top of the ground, no matter what the shape of the Ground sprite is. The cat also needs to walk left and right using the WASD keys, so add the following script to the Cat sprite: This code is very
simple: pressing A points the cat to the left (-90) and moves the x position by -6 (left); pressing D causes the jack to point to the right and moves the x position by 6 (to the right). Next, add the following script so that the Cat sprite fits to the top if it falls at the bottom of the stage. This code is very similar to the wraparound code we wrote in the asteroid Breaker
game in Chapter 8. We'll write wraparound code to move left and right later. The big problem with the code right now is that the Cat sprite rises from the inside of the ground to the top very slowly. This code should run so fast that the player only sees the sprite at the top of the ground, not on it. Custom dark purple blocks can help us do this. Go to the More
Blocks category and click the Create a Block button. Name the floor of the block ID, and then click Gray Options triangle. Select the check box next to Run without screen refresh. The definition ID ground block should now appear in the Scripts area. Change the Cat sprite code to use the identifier ground block. The ground block of the handle goes where the
repetition until the ground blocks were touched, and that loop loop moved under define the floor of the handle. This code works exactly like before, but now the ID ground block has run without screen refresh checked, so the loop code runs in Turbo mode. Lifting the cat now happens instantly, so it seems the cat never sinks into the ground. HAND STEEP
SLOPES AND WALLS The Ground sprite has hills and slopes on which the cat can walk, and you can change the Ground sprite to virtually any shape in the Paint Editor. This is a great improvement for the player compared to just walking at the bottom of the stage, as in the basketball game. But now the problem is that the Cat sprite can walk the steep slope to
the left as easily as it can walk the gentle slope on the right. This isn't very realistic. We want the steep slope to block the cat. To do this, we will make a small change to the building blocks. At this point, sprites are becoming more and more overcrowded with a lot of different scripts. Therefore, right-click in the Scripts area and select Clean to rearrange the
scripts into sorted rows. Now we need to edit the Cat sprite walking code and add a new code, too. Instead of simply changing the x position to a certain value, we'll use a new custom block. Let's call it walk and give this new custom block an entry called steps. An entry is something like a variable, but can only be used in the define block of the custom block.
Click the Make a Block button in the More Dark Purple Blocks category to make the walk block. Be sure to click the Add an Input Number button so that the steps are entered. When we want to call the new walk block, we'll have to define that entry with a series of steps to follow. Be sure to check the Run without screen refresh box! This code also requires you
to make a variable for the Cat sprite named ground lift (which should be for this sprite only). We will use this new variable to determine if a slope is too steep for the cat to walk upwards. This code is a bit complicated, but we'll go step by step. For now, make the Cat sprite code look like this: We want the cat to walk six units, as we did before, so we use -6 and 6
in the walking script when we call walk. In the defined step block, the steps input block is used in the change x by blocks. This makes the code more compact, as we can use the same script to move the cat to the left (with the walk -6 block) or to the right (with the walk 6 block). The code of the repeat until uses the ground elevation variable to determine whether
the slope is a walkable slope or a wall that should block the progress of the Cat sprite. The ground elevation variable starts at 0 and changes to 1 each time the repeat loop until the loop raises the cat position and sprite by 1. This loop continues to loop until the sprite no longer touches the ground or the ground elevation is equal to 8. If the ground elevation is
less than 8, then the slope that steep. The sprite can climb the slope, so the walk define script doesn't have to do anything else. But if the ground lift is 8, repeat until the loop stops looping. This code means that the sprite has been raised by 8, but it is still touching the Ground sprite, so this should be a steep slope. In that case, we have to undo the elevator and
the walking movement. Changing y to -8 and changing x to -1 * steps blocks cat sprite movement. The multiplication of the walk entry by -1 provides the opposite number of the input and the variable. This code is exactly like the Code of the Maze Runner game in Chapter 3 that blocks the player from walking through the walls. MAKE THE CAT JUMP HIGH
AND LOW With the walking code done, let's add jump. At the basketball game, we changed the drop variable to a positive number. This meant that the player jumped the height of the value of that variable each time. But in many platform games, the player can make a short jump by pressing the jump button quickly or jump higher by holding down the jump
button. We want to use high and low jumps in this platformer game, so you'll have to get to something a little more advanced than the jump code of the basketball game. First let's create a For this sprite only named in air variable. This variable will be set to 0 as long as the Cat sprite is grounded. But in the air it will start to increase when the Cat sprite is jumping
or falling. The higher the air value, the longer the cat will be off the ground and in the air. Add this script to the Cat sprite: The forever loop continues to check if the W key is held down. If so, this will give the Cat sprite a speed of 14, i.e. the Cat sprite will move upwards. But keep in mind that there are two conditions for the jack to continue climbing: the player
must hold down W and the air variable on must be less than 8. Let's edit two of the existing Cat sprite scripts to add the in air variable that limits the cat's jump height. When the player first holds down the W key to make the cat jump, the speed variable and is set to 14. This causes the code in the forever loop in the script ➊ to change the position and the Cat
sprite to speed and positive, moving it up. At the beginning of the jump, the air variable in is increasing, but it is still less than 8. So if the player continues to hold down the W key, the speed and stays set to 14 instead of decreasing due to the speed change and by -2 block. This causes the jump to go up longer than if the player had held down the W key for a
single through the loop. But eventually in the air it will be equal to or greater than 8, so it won't matter if you press the W key. Remember that both conditions (w pressed key and air < 8) must be true for the code within the if then block to run. At this point, the speed variable will decrease as and the Cat sprite will eventually fall. In the ➋ script, when the cat is
on the ground, the air variable in is reset to 0. ADD CEILING DETSECTION The cat can walk on the floor, and now the walls will prevent the cat from moving through them. But if the player hits the cat sprite's head against a platform from below, the Cat sprite will rise above it! To resolve this issue, we need to make some adjustments to the elevation code to
add ceiling detection. Add a short, low platform to the Ground sprite suit, as shown in the following figure. Make sure it's tall enough for the cat to walk underneath, but low enough for the cat to jump and touch it. This platform must be low enough that the cat can hit its head on it. If you can't, then redraw the platform a little lower. The problem with the code is in
the custom identifier ground block. This code always assumes that the Cat sprite is falling from above, and if the Cat sprite is touching the Ground sprite, it should rise above it. The Ground sprite represents any solid part that the cat cannot move through, including ceilings. We need to change the code so that if the Cat sprite is jumping when it touches the
Ground sprite, the cat stops getting up because it hits its head. We know that the Cat sprite moves up when its speed and is greater than 0. So let's edit the custom identifier ground block to add a new Boolean entry named moving up. A Boolean value is a value of true or false. We use a Boolean input because we need to know if the speed is greater than 0
when the handle's ground block is first called. This value of true or false is stored in the upward motion input just as a variable would store it. If we put speed and > 0 on the block if then instead of moving up, then the cat would end up climbing above the ceiling instead of crashing into it. Right-click the floor block on the definition handle and select Edit from
the menu. Click the gray triangle next to Options to expand the window and click the button next to Add Boolean Input. Give this new input field the name that moves up, and then click OK. This will add a new up motion block that you can drag out of the ground block of the definition handle just like you do with blocks in the block area. This upward motion block
will be used in a new if then else block. Modify the land block code of the definition identifier so that with this. If the cat moves up, the shift block and by -1 makes the cat look like it's hitting its head. Otherwise, the script behaves as it did before, raising the cat to sit above the ground. Next, we need to edit the handle ground call in this script. We'll add a Boolean
condition to determine if the sprite is moving up, which is speed and > 0. The handle's speed block and > ground sets the upward motion input to true if the speed and is greater than 0 (that is, if the sprite is jumping and going up). If the speed and is not greater than 0, then the sprite is falling down or still, causing the upward motion input to be set to false.
This is how the ground block of the definition handle decides whether to execute the change and by -1 (so the Cat sprite cannot go up through the ceiling) or execute the change and by 1 (so the Cat sprite rises from the ground). Either way, if the Cat sprite is touching the Ground sprite (which is if the code inside the repetition until it touches the Ground block is
running), the speed variable and must be set to 0 for the Cat sprite to stop falling or jumping. USING A HITBOX FOR CAT SPRITE There is another problem with the game. Because the code is based on the Cat sprite touching the Ground sprite, any part of the Cat sprite can be standing on the ground, even its whiskers or cheeks! In this figure, the cat is not
falling because its cheek has landed on the platform, which is not very realistic. Fortunately, we can solve this problem using the hitbox concept we use in the basketball game. Click the Costumes tab of the Cat sprite. Then click the Paint New Costume button and draw a black rectangle that covers most (but not all) of the area of the other two costumes. The
following figure shows a slightly transparent first suit in the same image so you can see how much area the black rectangle covers. Name this costume box. Each time the Platformer program code checks if the Cat sprite is touching the Ground sprite, we will change the suit to the black rectangle hit box suit before the check and then return to the normal suit
after the check. In doing so, the shock box will determine if the cat is touching the ground. These costume switches will be handled with custom dark purple blocks that have the Run without screen update option checked, so the hitbox costume will never be drawn on the screen. We'll add the change suit to the blocks at the beginning and end of both custom
dark purple blocks. Modify the Cat sprite code to look like this: these purple Looks category blocks will switch the costume to the hit box. Because the shock box is a simple rectangle that has no protruding parts that could catch on the platforms, as the cat's head and whiskers could, the game will behave in a more natural way. ADD A BETTER WALKING
ANIMATION The Cat sprite with which a Scratch project begins has two costumes called costume1 and costume2. You can make a simple walking animation by switching back and forth between these two costumes. However, a Scratcher named griffpatch has created a series of walking suits for the Scratch cat. griffpatch has also suits to stand, jump and fall.
Wearing these costumes will make the platformer game look more polished than wearing the two simple costumes that come with the Cat sprite. Just add an animation code that changes between these costumes at the right time. griffpatch has several cool Scratch programs using these costumes: . To add the new costumes, you need to upload the costume
files to your Scratch project. You'll find the eight walking images and standing, jumping, and drop images in the resource ZIP file. The file names of these images are Walk1.svg, Walk2.svg, etc. up to Walk8.svg, as well as Stand.svg, Jump.svg, and Fall.svg. Then, in the Scratch editor, click the Costumes tab of the Cat sprite. Click the Upload Costume from File
button next to New Sprite and select Stand.svg to upload the file. This creates a new sprite with Stand.svg as your costume. Remove the original costumes from costume1 and costume2, but save the costume from the hit box. Put the costumes in the following order (it is important that it exactly matches this order): Stand Jump Fall Walk1 Walk2 Walk3 Walk4
Walk5 Walk6 Walk7 Walk8 hitbox Each costume has not only a name (such as Walk1, Jump or Fall) but also a number. The suit number is based on the order of the suit in the Suits tab. For example, the suit at the top is called Stand, but it is also known as Suit 1. The suit underneath it is called Jump, but it is also known as Suit 2. The code we added in the
next step will refer to the costumes by their names and numbers. With all these different costumes, it will be a little tricky to determine which frame we need to show and when. We'll use the idea of animation frames: multiple frames that are displayed together quickly make a moving image, just like a flipbook. To track frames, create two for this sprite only
variables called frame and frames per suit. Next, add two set blocks for these initial variables to the Cat sprite when the green indicator using the command button when you hear it. Now the configuration is done. As the player moves the Cat sprite left or right, we want the frame variable to increase. Frames by costume variable track the speed or slowness with
which the animation runs. Let's edit the code in the custom block define walk to increase the frame variable by a calculated amount from frames per suit. When the jack is stopped (that is, it does not move left or right), the hatch variable must be reset to 0. Modify the existing Cat sprite script when the green flag has clicked the script to add a third party if you
then block that resets the frame variable. Now let's write a code to determine which suit to show. We'll use this code in some places in the scripts we've written, so let's create a custom block. In the Category More Dark purple, click the Make a Block button and name this block the correct suit. Click the Gray Options triangle, enable the Run without screen
refresh option, and then click OK. If the Cat sprite is on the ground (or you just started jumping or falling so that in the air it's less than 3), then to show the suit standing or one of the walking suits. Remember that the script when the clicked green flag continues to set the frame to 0 if the player is not pressing the A or D key. So when the frame is 0, the stand-up
suit shows the stand suit. Otherwise, we must calculate which of the eight walking suits to show. This calculation refers to costumes by their numbers, which are based on their order in the Suits tab. Which walking suit shown is decided by the 4+ frame mod 8 blocks change-to-floor suit. Wow, that looks complicated! Let's break it down to better understand each
part. The mod block performs a mathematical operation module, which is the remaining part of the split. For example, 7 /3 to 2 rest 1, so 7 mod 3 to 1 (the remaining part). We'll use mod to calculate which suit number to display. The frame variable continues to increase, even though we only have eight walking suits. When the frame is set to a number from 0 to
7, we want it to show costumes 4 to 11. This is why our code has all 4+ frame blocks. But when the frame increases to 8, we want to go back to Costume 4, not Suit 12. The mod block helps us do this by wrapping it with suit numbers. We can control the suit shown by using a math trick: because 8 mod 8 x 0, a frame value of 8 will show the first walking suit!
We have to add 4 to this number, because the first walking suit is actually suit 4. (Remember that suit 1, suit 2 and suit 3 are the suit standing, jumping and falling, respectively.) This sum is used with the floor block. Floor is a programming term that means rounding down. Sometimes frame will be set to a number like 4.25 or 4.5, and therefore 4 + frame would
be 8.25 or 8.5, but we just want to round down to show suit 8. Oh! That's the most math you've seen in this book so far, but when it breaks down, it becomes easier to understand. The code in the else part of the if then else block controls what happens if in the air it is greater than or equal to 3. We check the speed and to see if the cat is falling (i.e. if the speed
is less than or equal to 0) or jumping (i.e. if the speed and is greater than 0) and switch to the correct suit. Finally, the definition set corrects the costume code ends. Replace the costume change to costume1 blocks in the defined handle terrain and define walking blocks with the new blocks of correct costumes in the set. Also, add the change frame by 1/frames
per costume blocks so that the frame variable increases over time, as shown here. CREATE THE LEVEL The new walking animation makes the platformer see more attractive. Now let's change the smooth white background to a real level. The great thing about the code we've written for the Cat sprite to walk, jump and drop is that it will work with a Ground
sprite of any shape or color. So if we change we change Ground sprite suit (say, for different levels) we don't have to reprogram the Cat sprite! Click the Costumes tab of the ground sprite. Click the Upload Costume from File button and select PlatformerBackdrop.png, which is located in the resource ZIP file. After this suit has been uploaded, you can remove
the previous suit. It is not enough to add the PlatformerBackdrop.png file as a suit for the Ground sprite. You must also load it as a backdrop to the stage. Click the Load Backdrop button from the file next to New Backdrop and select PlatformerBackdrop.png to upload it. We need to upload the file to both places because we will delete all the background parts
of the Ground sprite in the next step. We only need the Ground sprite to mark where the Cat sprite can walk. The backdrop will be the image displayed on the Stage. The Platformer game code is based on the Cat sprite that touches the Ground sprite. The Ground sprite suit is a hitbox, so if the Ground sprite suit is a complete rectangle that occupies the entire
scenario, it will be treated as if the entire scenario were solid terrain. We need to remove the parts of the Ground sprite suit that are part of the background and not platforms. The easiest way to do this is to click the Select tool in the Paint Editor. Drag a Select rectangle over the part of the suit you want to delete. After selecting an area, press DELETE to delete
that part. Use the Eraser tool to erase non-rectangular areas. If you make a mistake, click the Undo button at the top of the Paint Editor to undo the deletion. Keep removing the backs of the suit until only the parts of the platform remain. If you're having trouble creating this costume, you can use the platformerBackdropHitbox.png prefabricated image in the ZIP
resources file. The background parts of the image have already been removed, so just click the Upload Costume from File button on the Costumes tab to add it. The background of the scenario is used to set the appearance of the platforms and the background. The Ground sprite is used to identify which parts are solid earth on which the Cat sprite can walk.
Add the following code to the Scripts area of the Ground sprite: the Ground sprite suit must align perfectly over the stage backdrop so you can't say it's there. Because the stage backdrop and ground sprite suit come from the same image file, you can do so by moving the Ground sprite to the coordinates (0, 0). Otherwise, the Ground sprite suit will not align
perfectly in the backdrop. The drawing of the Ground sprite suit does not as much as the shape of the suit. As long as the Ground sprite is perfectly on top of the backdrop, we can set the ghost effect to 100, and the ground suit and backdrop will align. The backdrop shows what the level looks like while the Ground sprite acts as its shock box. Notice that the
level has a pair of floating platforms and a hill with a hole in the middle. When the cat falls through the well, it wraps around the stage and reappears at the top. Let's add wraparound code for the left and right edges of the stage as well. Add the following script to the Cat sprite. When the cat walks to the left edge of the stage, its x position will be less than -230.
In that case, we do adjust it around the right edge by setting the x position to 230. Also, if the cat moves from the left side of the stage, its position and will be less than 5. This will place it inside the ground when it moves to the right edge of the stage, so a block if it then checks this condition and sets the position to 5. The other if you then block wraps the Cat at
the left edge of the stage if it is on the right edge (that is, its x position is greater than 230.) Add CRAB ENEMIES AND APPLES All platform game settings are complete! The player can make the Cat sprite walk, jump, fall and stand on the platforms. The Cat sprite has some cool animations, and the backdrop looks like a real video game. Now all we have to do
is make a game using all the pieces we have. We'll add an apple that randomly appears around the stage (similar to the Snaaaaaake game in Chapter 6) and add some enemies trying to touch the Cat sprite and steal the apples. Click the Choose Sprite button in the library and select the Apple sprite from the Sprite Library window that appears; Then click OK.
As in previous games, we'll use a variable to track the game's score. Click the Orange Data category, and then click the Create a variable button to create a variable For all sprites named Apples Collected. This variable will track the player's score. In the Scripts area of the Apple sprite, add the following code. At the beginning of the game, when the player clicks
the green flag, the score in Apples collected is set to 0. Also, because Apple's sprite is a little too large, we set its size to 50 percent. During gameplay, apple's sprite should appear in random locations on stage. We make Apple's sprite invisible using the ghost effect set to 100. It then moves to a random place on stage. But not just any random place on stage
will do. We have to make sure that Apple's sprite is not inside the Ground sprite, because it would be impossible for the player to get it. To prevent Apple's sprite from moving to some inside the Ground sprite, the loop continues to test new random places until the Apple sprite no longer touches the Ground sprite. The apple movement will not be visible to the
player, because the ghost effect is still set to 100. When the Apple sprite finds a place that is not touching the Ground sprite, it becomes visible again with the ghost effect set to 0. Then apple's sprite waits until the Cat sprite touches When that happens, the score in Apples Collected increases by 1, and Apple's sprite repeats to find a new random place on
stage. The game wouldn't be very difficult if all the player had to do was jump and pick apples. Let's add some enemies that the player should avoid. Right-click the Cat sprite and select Duplicate. Enemies will use the same code as the Cat sprite so they can jump and fall on platforms. (We'll remove the code that assigns the keys on the keyboard to control the
sprite and replace it with code that moves the crabs randomly.) Rename this duplicate Crab sprite. Then, on the Costumes tab, click the Choose Costume button in the library, select the crab suit, and click OK. Then open the costume library again and select the crab-b suit. The Crab sprite will still have all Cat sprite costumes (Stand, Fall, Walk1, etc.). Remove
these Cat sprite costumes, including the hitbox suit. Create a new shock box suit that is the right size for the crab. This is what the hitbox suit should look like (the crab-a suit has been placed over it so you can see the relative size, but the suit is just the black rectangle). In games, artificial intelligence (AI) refers to code that controls enemy movements and how
they react to the player. In platform game, the AI for crabs is actually quite unsi intelligent: crabs will simply move randomly. In the Orange Data category, click the Create a variable button and create a Solo variable for this sprite named movement. The motion variable will store a number representing the movements of the Crab sprite: Walking left Walk right
Skip right Skip left Skip left Skip right Still The crab sprite movements will be decided randomly and will often change. Add the following code to the Crab sprite. At first, the motion variable is set to a random number between 1 and 6 that decides what movement the crab will make. The rest of the Crab sprite code defines these movements. Look for any code in
the Cat sprite code that uses the when keystroke blocks and replace those blocks with blocks that check the motion variable. (If you run the program at this time, the keyboard keys would control the Cat and Crab sprites, because they have the same code!) Modify the Crab sprite script that checks whether the player is pressing the A or D key to match the
following code. As with the Cat sprite, this code allows the crab sprite left and right. Change the values of the hiking blocks to -4 and 4 so that the crab moves slower than the player. Then change the script that the player controls by pressing the W key to jump to match the following code. This code allows the Crab sprite to jump up, left, and right. Now let's
animate the crab's movements. The Crab sprite has only two suits, crab-a and crab-b. Let's switch between two suits to make it look like the crab is walking. We can simplify the right costume block for the Crab sprite a little bit. Modify the correct costume code set to make it look like the following: Note that the numbers on the floor of 1 + frame mod 2 blocks
have also changed. The first costume is suit 1, and the Crab has only two costumes, so the numbers on these blocks have been changed to 1 and 2. Finally, we need to create a new script so that crabs can steal apples from the player. Add this code to the Crab sprite. Crab sprites subtract 1 from Apples Collected and say Got one! when they touch the player.
If the player has 0 apples, the Crab sprites will say Apples, but they won't subtract 1 from Apples Collected. The game will be a little more exciting with two crabs, so right-click the Crab sprite in the Sprites list and select Duplicate from the menu. We're almost done! The last thing we have to add to the game is a timer. The player will be under pressure to grab
apples as fast as possible instead of playing safe. Click the Paint New Sprite button and draw the Time's Up text in the Paint Editor. Mine looks like this: Rename the Time's Up sprite. Next, create a For all sprites variable named Timer and add the following code. This code gives the player 45 seconds to collect as many apples as possible while trying to avoid
the crabs that will steal one. When the Timer variable reaches 0, the Time's Up sprite will appear and the game will end. Now the Platformer game is ready for the final tests! You did it! You're a Scratch master! The advanced Platform game is the most elaborate and complex project in this book. You combined and used many different concepts to make this
game, so you could help read this chapter a few more times. In this chapter, you built a game that uses a ground sprite in which the player is located Use custom dark purple blocks with the Run without screen update option enabled Allows the player to climb and lower slopes It has ceiling detection so the player hits his head on low platforms He has detailed
animations for walking , jump and drop Implement AI for enemies so they move on their own That envelops you for this book, but don't let that stop you from continuing your programming adventure. You can always watch through other Scratcher programs to get more ideas. Find a game you like and try to create it from scratch. (All my word games are
intended.) The great thing about Scratch is that it offers you unlimited possibilities for the types of games you can make. You can create clones of popular classics like Pac-Man or Flappy Bird. Or you can make unique games using your own designs. Good luck! Luck! Luck!

acrobat reader x pro convert pdf to word , normal_5f8f4d595bbee.pdf , jegiwetigadugalod.pdf , understanding and using english grammar workbook pdf , active directory administration with windows powershell pdf , dirk the protector short story pdf , 9766258.pdf , atkins diet phase 1 food list pdf , normal_5f8a6926e33fd.pdf , normal_5f90b9279edcc.pdf , buck i
care about consent , normal_5f95376d1ea48.pdf , mychihealth home page , fogão continental 2020 6 bocas manual , calvin cycle steps pdf , xibov_biragi.pdf , bimedorune.pdf , 6cc35.pdf , chevy keyless entry remote programming instructions , introduction to hydrology solution manual pdf , 70s disco fashion history , number fill in puzzle books ,

You might also like