Adjust Pipe Size and Location in Your Flappy Bat Game

By Derek Breen

When creating your Flappy Bat game (a different version of Flappy Bird), unless you got lucky, the size of the hole in your Pipe sprite is either too small for the bat to fly through or too large to make the game challenging. Before increasing the hole size, consider one other thing the pipe should do.

Part of the challenge from the original game comes from not knowing where the hole will be when each new pipe appears. So far, the Pipe sprite is always in the same vertical position, so the hole remains in the same spot.

Randomize vertical position

In Scratch, you can use a PICK RANDOM block inside the GO TO block so the pipe (and its hole) will appear in a different vertical position (Y) each time you run the game.

  1. Click the Pipe sprite and then click the Scripts tab.

  2. Drag a PICK RANDOM block into the Y value of the GO TO X Y block. (Notice how the round blocks can fit inside the round sockets of other blocks.)

  3. Change the values in the PICK RANDOM block to –75 and 75.

    image0.jpg

Click the Green Flag button several times and you should see the hole appear in a different position each time. You will also see the pipe is too short to span the entire Stage when shifted vertically.

image1.jpg

Increase sprite size on the Stage

To increase the size of sprites on the Stage, you can use the Grow tool.

  1. Click the Grow tool (above the Scripts, Costumes, and Sounds tab).

    image2.jpg

  2. Click ten times on the Pipe sprite on the Stage.

  3. Click the Green Flag button to test your game.

    image3.jpg

The Pipe sprite should span the entire Stage no matter where it is positioned vertically. But you still cannot flap your bat safely through the hole. If you try to click any more with the Grow tool, you will find the sprite will no longer increase in size because you reached the limit. Instead, why don’t you try shrinking the bat?

Decrease sprite size on the Stage

To decrease the size of sprites on the Stage, you can use the Shrink tool.

  1. Click the Shrink tool (above the Scripts, Costumes, and Sounds tab).

    image4.jpg

  2. Click five times on the Bat sprite on the Stage.

  3. Click the Green Flag button to test your game.

    image5.jpg

You may need to use the Shrink and Grow tools to adjust the size until it’s possible to fly through the pipe, but not too easy. Then you will be ready to add more pipes.

Include additional pipes

Since you only need to have one pipe appear on the Stage, you do not need to create additional Pipe sprites. Instead, once the player successfully flies through the hole and the first pipe reaches the other side, you can reset the position of the Pipe sprite back to the left side of the screen.

  1. Click the Pipe sprite icon beneath the Stage.

  2. Click the Scripts tab.

  3. Snap the following code blocks inside the first FOREVER block and change the values of your blocks to match the values shown.

    image6.jpg

The additional GO TO X Y block should look familiar. It has exactly the same values as the GO TO X Y block above it (right under the WHEN GREEN FLAG CLICKED block). So if the X position of the Pipe sprite is greater than 280, it resets the horizontal position to –200 and chooses another random Y position so the hole appears in a new location.

image7.jpg

You may need to adjust the X and Y values as you resize sprites on the Stage. Testing your game over and over will help you refine the sprite positions and sizes until you have just the right blend of hard and fun that will keep your players coming back for more.