Tutorial: Create a Brick Breaker Game in AS2 – 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 mcBg’s onRelease() function. We aren’t going to remove the text field 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.
Now, we can make the scoring happen. 10 points should be awarded to the player for destroying one brick. I’ll leave it to you to find out how to do this.
The next thing we have to do is display the current level, the score, 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. Just create a dynamic text field and update it in the onEnterFrame() function. Pretty easy, eh?
hey man i need this Action Script pm me bube-bubislaf@hotmail.com
January 11th, 2009 at 4:25 pm
woo i got to lvl 166 😛
March 8th, 2009 at 10:46 pm
Hey mate can you please send the code as an Actionscript document to me at cartilige.pyro@gmail.com please as the instructions a slightly confusing. I can even take the full document as I have Macromedia Flash 8.0
March 16th, 2009 at 10:51 am
“why is the source .fla File not working…
can you send me Action script document too plz my email is master.of.chaos@hotmail.co.uk … i get confused… and the ball I made dont even move :S”
changed on April 1st, 2009
April 1st, 2009 at 9:21 am
Can you just post the Action script here? That way you don’t have to E-mail us.
April 7th, 2009 at 10:11 am
Great tut. By the way, the .fla works, right click it then select download file as/ save as.
April 14th, 2009 at 6:09 am
This is a great tutorial to help people grasp actionscript. Although after working through this tutorial myself I did find some flaws in the game design as there is a possibilty that the ball after bounces off the bottom of the screen rebounds off of the paddle meaning you lose another life or all of your lives.
July 24th, 2009 at 1:05 pm
You should add powerups, which are randomly spawned when a brick “breaks”
August 19th, 2009 at 12:27 pm
What Flash Editor Is everyone Using I am Using Macromedia Flash MX
December 13th, 2009 at 1:38 pm
good tutorial but really? This doesn’t teach people to do things correctly… Collision detection is broken in many places; such as, the walls the paddle, the bricks… Oh yeah, that’s everything.
March 14th, 2010 at 11:19 pm
Good tutorial but really? This doesn’t teach people to do things correctly… Collision detection is broken in many places; such as, the walls the paddle, the bricks… Oh yeah, that’s everything.
March 14th, 2010 at 11:20 pm
hey man, i got completely messed up in the last tutorial, please email me the codes on each layer at rhinoforce135@gmail.com
thanks!
April 9th, 2010 at 10:00 pm
I got to level 400!!!!!!!!!!!!!!!
April 26th, 2010 at 7:18 pm
hey im making this game for my ITS class and me and my partner have changed it by putting in different bricks and adding a main menu. The only problem is on main menu we have a button called mc_startgame, but when we click on the start game button it goes to the game and then flashes to the “you lose” frame. Can you please email me at carefreelifes@hotmail.com and help me!
May 3rd, 2010 at 7:55 pm
Please mail me the full actionscript too 🙂
May 17th, 2010 at 8:56 am
a wonderful tutorial. but how to end the levels? i mean if you finished the level five (on the array function). how to declare your a winner?
June 4th, 2010 at 2:44 am