Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning Construct 2

You're reading from  Learning Construct 2

Product type Book
Published in Dec 2014
Publisher
ISBN-13 9781784397678
Pages 234 pages
Edition 1st Edition
Languages
Author (1):
Aryadi Subagio Aryadi Subagio
Profile icon Aryadi Subagio

Chapter 3. Creating Diverse Player Experiences with a Flappy Bird Clone

Alright, here we are! In this chapter, we will make our first Construct 2 game using the game design information that we obtained from the previous chapter. We will look at a popular game that everyone knows, Flappy Bird, and try to make something similar. We will analyze what makes it good and what can we do to make it more engaging.

In this chapter, we will look at:

  • What the Flappy Bird game design looks like

  • How to make a dynamic gameplay

  • How to add modifications from the original design

  • How to add collectibles

How Flappy Bird works


Let's first take a look at how Flappy Bird works and how it ended up with its designs. The game is really simple; players control a bird that automatically falls to the ground, and to prevent this bird from falling, players need to touch the screen to make the bird flap upward. There are pipes coming from the right-hand side of the screen, and there's only a small gap left for the bird to go through.

Everything seems so simple, so how did it become so popular? The answer is through simple controls and random generation. The way to control the game is just through a one-finger tap; everything else (like the bird falling down and pipes coming from the right-hand side) is handled by the game. The other factor is random generation.

Understanding random generation

So, what is random generation and how did it make the Flappy Bird experience so engaging?

Note

Random generation is a technique used to create a game object at a random place or random interval, or the created object...

Making our own Flappy Bird game


We will make a game similar to the Flappy Bird design, but there will be differences between Flappy Bird and our game. This is because the focus of this chapter is not to directly copy the game, but to learn about the techniques used in it. I will guide you step by step in making it using Construct 2 first, before talking about random generation.

Adding the layers

First, we will prepare our game assets. Game assets are the sprites, music, sound effects, and so on that we use in our game. Basically, we can use any assets we want, but in this book, we will use a free bundle available from Scirra's website (http://www.scirra.com/freebundle.zip); this is free to use as long as it is used with Construct 2. Download it and put it where you're most likely to find it.

Start up Construct 2 and create a new empty project like I showed you in Chapter 1, Downloading and Understanding Construct 2. The first thing I do when I create a new project is to set up layers that I...

Learning random generation


I defined random generation at the beginning of this chapter and now I will discuss it in a technical fashion. We will create the obstacles at a random position on the scrolling ground. So, first we will make the ground scroll.

Making the ground scroll

To make the ground scroll, we need to first make it move in one direction at all times; to do this, we need to use a movement behavior. We'll use a behavior that is different from the 8 Direction behavior; to make an object move in one direction, we will use the Bullet behavior. Add this to the ground object, just like we added the 8 Direction behavior to the plane object. It doesn't matter to which of the two instances of the ground object you add the behavior; it will be added to all instances of this object.

Now, the ground will automatically move, so we will make it move in the direction we want it to. First, we will set the Set angle property from the Bullet behavior's property to No because the ground doesn't...

Adding collectibles


Collectibles are coins or other objects that the players can collect in the game. These collectibles often add something like scores or game coins. In our game, the collectibles will also be randomized. First, create a new star game object with a sprite from starGold in the Tappy Plane folder and put it in the Collectibles layer. Give it a Bullet behavior and put it outside the screen.

We will create new collectibles every few seconds instead of making them every time the game creates a ground object, like the rock obstacles object. To make collectibles, write the following code:

We also want to show what these collectibles collect. So, let's create a new text object; name it scores and put it in the HUD layer. Put it in the upper-left part of the screen; this is where HUDs usually are, although they can be in a variety of places. Now, when the player collects the collectibles, we want the collectibles to be destroyed and then add the score. So, create a global variable...

Summary


In this chapter, we created the design of Flappy Bird, and you learned how to create a similar game. You learned about the sprite game object in detail; you also learned about two movement behaviors and how to manipulate them in the Properties bar and in the code.

You also learned about random generation and how to utilize that technique. Moreover, you learned about object picking in the event sheet. In this chapter, you learned about movement behaviors that we can use to move objects and also learned how to use instance variables in the game.

One thing is still left to be done in our code. If you check the event sheet, you will see that we made all the other objects stop moving when the player hits a rock to make it look like the game stop. However, we haven't made the rock and other objects stop moving when the player hits the ground. Can you modify the code so that the objects stop when the player falls to the ground?

If you're confused about how to write events or what each action...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Learning Construct 2
Published in: Dec 2014 Publisher: ISBN-13: 9781784397678
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}