Tutorial: Create a Brick Breaker Game in AS3 – Part 6
Table of Contents
Step 6: Finishing Touches
Well, we’re almost done with our game, now we just have to add some finishing touches. I won’t make a menu system like you usually should in a game before releasing it. But, this is just a tutorial, and hopefully you’ve learned something. You probably already know how to make a menu anyway. Also, I’m not going to teach you how to do some of the things that we need because hopefully you can do it yourself. If you can’t , there’s always the source file at the bottom.
Now, where were we? Oh yes. I realized that the last lesson, we were supposed to make more levels. I taught a lot of stuff, but I forgot to make more levels for you! I apologize. Anyway, here’s an example of a 5 level game (Put it on the first frame).
//The array code for lvl 1
//All of the later levels add one more row of bricks
var lvl1Code:Array = new Array(1,1,1,1,1,1,1);
var lvl2Code:Array = new Array(1,1,1,1,1,1,1,1,1,1,1,1,1,1);
var lvl3Code:Array = new Array(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
var lvl4Code:Array = new Array(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
var lvl5Code:Array = new Array(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
//The array that contains all of the level codes
var lvlArray:Array = new Array(lvl1Code, lvl2Code, lvl3Code, lvl4Code, lvl5Code);
It’ll be a pretty straightforward game. Next, I think the gamer needs to know that he has to click the screen to start, and not think the the game is frozen or something. So, just add a dynamic textfield to the middle of the stage. Give it an instance game of txtStart, and make sure it isn’t selectable.
Next, add this code at the end of the frame.
//setting the text's word
txtStart.text = "Click To Begin";
You can make the text different, but don’t be too mean. Next, we have to remove the text, which we can do in the beginCode() function. We aren’t going to remove the textfield itself because we need it again for every level.
//removing the "Click to Start" Text
txtStart.text = '';
Now, we have to reset it every level. I’m not going to tell you how to do it. I hope you’ve learned enough to be able to.
The next thing we have to do is display the current level, and how many lives the user has. This will be pretty simple as well, so I won’t really go into details about how to do it. But, I will give you some code to use below all the other.
//creating a function to update the text fields
addEventListener(Event.ENTER_FRAME, updateTextFields);
You can create your own text fields with and update them with that function. But, be sure to remove that listener if the gamer loses, or something bad will happen, something very bad…
And don’t think I forgot about scoring. Just define a variable at the top called score and have it update along with the other stats. Also, you have to make it increase in the Brick class every time the brick is hit. You might want to show the score when the player loses too. But, that’s just optional.
Well, those are all the finishing touches that I’m going to add on to my game at least. Here is the final product of all our work.