Reader small image

You're reading from  Learning Construct 2

Product typeBook
Published inDec 2014
Reading LevelIntermediate
Publisher
ISBN-139781784397678
Edition1st Edition
Languages
Right arrow
Author (1)
Aryadi Subagio
Aryadi Subagio
author image
Aryadi Subagio

Aryadi Subagio is the second among seven brothers. He has loved video games ever since he was little, and he wanted to make his own game in his teenage years. This led him to pursue a Diploma in Computer Programming after he graduated from high school, where he spent years learning about software development techniques. He learned about game development from online sites, because at that time, there was no book on game development in Indonesia. After graduating, he immediately jumped into the world of game development. During this time, he made a few shooting games for the Flash Platform. After a year, he decided to gain more experience by working in a game studio; this is when he joined Esabra Studio. After working at Esabra Studio, he worked at Enthrean Guardian, a game studio based in Semarang. He has now quit working and is trying to set up his own studio. Aryadi has a passion for sharing his knowledge. He has written a lot of blog posts about game development on Indonesian and English sites. He also shares his knowledge on his own personal blog at http://daggio21.blogspot.com/.
Read more about Aryadi Subagio

Right arrow

Chapter 4. Making a Breakout Clone

We created our first game in the previous chapter. If you still remember what we did there, we used instance variables to do two things: flap the plane and make the ground scroll. We used only Boolean type instance variables to do what we want, while there are still two other variable types.

These other types can be used to manipulate the state of an object; if you ever see Mario becoming big after eating a mushroom or becoming invincible after getting a star, then you've seen the example of changing the state of an object. We will create something similar in this chapter.

In this chapter, we will cover the following topics:

  • More ways to use instance variables

  • What a constant variable is

  • What an expression is and how to use it

  • How to make an object bounce off other objects

  • What sub-events are

Creating the design


Just like the previous chapter, we will start this chapter by making a design of the game we want to make. You probably would have guessed by reading the chapter title that we are going to make a breakout clone. Breakout is a game where you move a paddle in the bottom part of the screen to bounce a ball up to destroy blocks. However, some blocks will be able to add some variation to the gameplay. Let's start with the following criteria:

  • Elevator pitch: An elevator pitch is the description of your game as you would explain it to someone in an elevator, short and concise. This game is a game where players move a paddle to bounce balls off to destroy blocks. Some of the blocks will have special effects to change the balls or the paddle.

  • Theme: The theme for this game is puzzle.

  • Genre: The genre for the game is puzzle game.

  • Challenges: These are used to destroy all of the blocks in a level.

  • Rewards: Players are given scores depending on what blocks are destroyed and how long they...

Setting up our layout


Now, we will set up our layout for the game. Unlike the previous chapter where I explained how to add game objects in detail, in this chapter, I will only tell you to add objects when I want you to add them to the layout. I'll only give more details when I'm explaining something new. You can download the sample code from the book's website.

We will use the sprites from the freebundle.zip file, which we downloaded earlier. However, this time, we will use the sprites present in the Puzzle assets folder under the Sprites folder. Open up Construct 2 and create a new empty project. Just like we did the last time, we will add layers to this layout, but now, we will create only three of them:

  • HUD

  • Main

  • Background

Keep HUD as the top layer and Background as the bottom one.

Add a sprite game object to the Main layer and use the paddleBlue sprite from the Puzzle assets folder; this is going to be our paddle. Then, add another sprite object that will be our ball; use ballBlue as the...

Understanding constant variables


Now, we will start changing the game state. We will do this by utilizing two kinds of variables: instance variables and global variables. We'll make several global variables that will be checked later with an instance variable. However, we will change the global variable to a special type of variable: constant variable.

Note

So, what are constant variables? They are variables, global or local, whose values do not change after they are declared. Both the text and number type variables can become constant variables. To make a constant variable, just select the Constant checkbox when creating a new global variable. Constant variables in the event sheet are indicated by their names, which appear capitalized.

Let's try it now. Go to the event sheet and create a few variables needed to create the blocks' special effect. As you remember, the default value for the blocks' effect instance variable is 0; so we'll make a value of zero when the block has no special effect...

Ending a game


We have done a lot of things in this chapter, and I have explained many things. I am afraid this chapter is a bit hard to understand. Don't give up, and don't stop because we are nearing the end of the chapter. Now that we have added our state-change feature, it is time to apply a losing condition to the game. There are two losing conditions in this game: when the player loses all lives and when the time runs out. To do this, we'll give default values to the global variables related to the losing conditions. We'll give three lives and start the time countdown at 60 at the start of the level, like this:

Then, we'll represent these values on screen like we did in our first game. So, we'll create two new Text objects to be put on the HUD layer, name them txtTime and txtLife, and make their values show gameTime and life instance variables as follows:

To show that the player has lost, we will display GAME OVER text in large when one of the losing conditions is met. So, create another...

Summary


In this chapter, you learned about a new object, the tiled background, and how to use it. You learned about a new Solid behavior and how to use it to bounce off objects. You also learned about expressions, how to use them, and how to compare them like instance variables. You learned about constant variables and how to use them to change the state of an object. Moreover, you also learned about sub-events for the first time.

In our next chapter, I will introduce you to the Physics object and a few things you can make with it.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Learning Construct 2
Published in: Dec 2014Publisher: 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.
undefined
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

Author (1)

author image
Aryadi Subagio

Aryadi Subagio is the second among seven brothers. He has loved video games ever since he was little, and he wanted to make his own game in his teenage years. This led him to pursue a Diploma in Computer Programming after he graduated from high school, where he spent years learning about software development techniques. He learned about game development from online sites, because at that time, there was no book on game development in Indonesia. After graduating, he immediately jumped into the world of game development. During this time, he made a few shooting games for the Flash Platform. After a year, he decided to gain more experience by working in a game studio; this is when he joined Esabra Studio. After working at Esabra Studio, he worked at Enthrean Guardian, a game studio based in Semarang. He has now quit working and is trying to set up his own studio. Aryadi has a passion for sharing his knowledge. He has written a lot of blog posts about game development on Indonesian and English sites. He also shares his knowledge on his own personal blog at http://daggio21.blogspot.com/.
Read more about Aryadi Subagio