Tutorial: Create a Brick Breaker Game in AS2 – Part 6


Written By MrSun at 8:05 am - Saturday, January 10th, 2009
Categories: Beginner Tutorials, Flash

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.
Make sure that these properties are what you have

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?

The Final Product

Source .fla File

16 Comments

Bube:

hey man i need this Action Script pm me bube-bubislaf@hotmail.com


Russ:

woo i got to lvl 166 😛


cartilige:

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


me too:

“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


Me First:

Can you just post the Action script here? That way you don’t have to E-mail us.


Zuhair:

Great tut. By the way, the .fla works, right click it then select download file as/ save as.


elion:

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.


Dave::

You should add powerups, which are randomly spawned when a brick “breaks”


NewbieProgrammer:

What Flash Editor Is everyone Using I am Using Macromedia Flash MX


Anonymous:

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.


Fright01:

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.


rhinoforce135:

hey man, i got completely messed up in the last tutorial, please email me the codes on each layer at rhinoforce135@gmail.com

thanks!


Ben:

I got to level 400!!!!!!!!!!!!!!!


Ben:

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!


Lahulia:

Please mail me the full actionscript too 🙂


arwin:

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?


«
»