Bubble Chaos: a complete flash game in only 131 lines
Filed Under Flash •
Last minute edit: I open this quick note just to say I am pleased that Bubble Chaos, with its only 131 lines of coding, got a "Decent Score" in NewGrounds portal

Time to introduce Bubble Chaos, a complete flash game in only 131 lines of actionscript... brackets included of course!
Let's examine the features of this game:
Splash screen
Option to enter the name, that will remain during all game session (for future highscores implementation)
Infinite levels of increasing difficulty
(pretty) Complex score system
Decent action
The aim of the game is simple: destroy all bubbles with your cannon. You can shot only one missile at time. You get more points if you destroy the bubbles in their numerical order and if you destroy them when they are close to the top of the screen.
As you can see, the game is not-so-simple despite of its only 131 lines of code
Here it is the actionscript, only in the first frame:
-
game_playing = 0;
-
shot_sound = new Sound();
-
shot_sound.attachSound("shoot_sound");
-
pop_sound = new Sound();
-
pop_sound.attachSound("ppop_sound");
-
title_screen();
-
function title_screen() {
-
attachMovie("main_menu", "main_menu", 1);
-
if (_root.plname) {
-
main_menu.player_name.text = _root.plname;
-
}
-
main_menu.play_button.onPress = function() {
-
_root.plname = main_menu.player_name.text;
-
removeMovieClip(main_menu);
-
game_init();
-
};
-
}
-
function game_init() {
-
game_playing = 1;
-
level = 1;
-
game_over = 0;
-
firing = 0;
-
score = 0;
-
Mouse.hide();
-
_root.createEmptyMovieClip("game_scene", 1);
-
game_scene.attachMovie("back", "back", 2);
-
game_scene.attachMovie("hero", "hero", 3, {_y:400});
-
game_scene.hero.onEnterFrame = function() {
-
(_xmouse<40) ? this._x=40 : (_xmouse>460) ? this._x=460 : this._x=_xmouse;
-
if (slow_enemy>1) {
-
slow_enemy -= 0.1;
-
}
-
};
-
game_scene.attachMovie("crosshair", "crosshair", 4);
-
game_scene.crosshair.onEnterFrame = function() {
-
this._x = game_scene.hero._x;
-
this._y = _ymouse;
-
};
-
game_scene.attachMovie("points", "points", 10003);
-
game_scene.points.my_score.text = 0;
-
enterlevel(1);
-
}
-
function enterlevel() {
-
combo = 0;
-
kills = 0;
-
slow_enemy = 1;
-
for (x=1; x<=_root.level+2; x++) {
-
enemy = game_scene.attachMovie("alien", "alien_"+game_scene.getNextHighestDepth(), game_scene.getNextHighestDepth(), {_x:50+Math.random()*400, _y:50+Math.random()*200});
-
enemy.enemynum.text = x;
-
enemy.points = x;
-
dir = Math.random()*360;
-
enemy.speedx = Math.cos(dir*Math.PI/180)*x/2;
-
enemy.speedy = Math.sin(dir*Math.PI/180)*x/2;
-
enemy.onEnterFrame = function() {
-
this._x += (this.speedx/slow_enemy);
-
this._y += (this.speedy/slow_enemy);
-
if (((this._x-25<0) and (this.speedx<0)) or ((this._x+25>500) and (this.speedx>0))) {
-
this.speedx *= -1;
-
}
-
if (((this._y-25<0) and (this.speedy<0)) or ((this._y+25>400) and (this.speedy>0))) {
-
this.speedy *= -1;
-
}
-
dist_x = this._x-_root.game_scene.hero._x;
-
dist_y = this._y-_root.game_scene.hero._y;
-
abs_dist = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
-
if (abs_dist<65) {
-
pop_sound.start();
-
removeMovieClip(this);
-
removeMovieClip(game_scene.crosshair);
-
removeMovieClip(game_scene.hero);
-
Mouse.show();
-
game_over = 1;
-
game_scene.attachMovie("play_again", "play_again", game_scene.getNextHighestDepth());
-
game_scene.play_again._x = 250;
-
game_scene.play_again._y = 300;
-
game_scene.play_again.onRelease = function() {
-
removeMovieClip(game_scene);
-
title_screen();
-
};
-
}
-
bullet_dist_x = this._x-game_scene.fire._x;
-
bullet_dist_y = this._y-game_scene.fire._y;
-
bullet_abs_dist = Math.sqrt(bullet_dist_x*bullet_dist_x+bullet_dist_y*bullet_dist_y);
-
if (bullet_abs_dist<28) {
-
if (this.points == combo) {
-
combo_bonus += this.points*100;
-
} else {
-
combo_bonus = 0;
-
}
-
combo = this.points+1;
-
height_bonus = (this.points*100)*(Math.ceil((400-this._y)/40)-1);
-
score += ((this.points*100)+height_bonus+combo_bonus);
-
game_scene.points.my_score.text = score;
-
earned = game_scene.attachMovie("disp_score", "disp_score_"+game_scene.getNextHighestDepth(), game_scene.getNextHighestDepth(), {_x:this._x, _y:this._y});
-
earned.disp.text = "Bubble score: "+(this.points*100)+"\nHeight bonus: "+height_bonus+"\nCombo bonus: "+combo_bonus;
-
earned.rem = 0;
-
earned.onEnterFrame = function() {
-
this._y -= 0.5;
-
this.rem++;
-
if (this.rem>100) {
-
removeMovieClip(this);
-
}
-
};
-
pop_sound.start();
-
removeMovieClip(this);
-
removeMovieClip(_root.game_scene.fire);
-
firing = 0;
-
kills++;
-
slow_enemy = 3;
-
if (kills == _root.level+2) {
-
_root.level++;
-
enterlevel(_root.level);
-
}
-
}
-
};
-
}
-
}
-
function onMouseDown() {
-
if ((!firing) and (!game_over) and (game_playing)) {
-
firing = 1;
-
shot_sound.start();
-
game_scene.attachMovie("fire", "fire", 1000, {_x:_xmouse, _y:357});
-
game_scene.fire.onEnterFrame = function() {
-
this._y -= 5;
-
if (this._y<0) {
-
removeMovieClip(this);
-
firing = 0;
-
}
-
};
-
}
-
}
and here it is the linkage reference table for you to understand how did I call objects

A detailed tutorial will follow in the next days, meanwhile I am providing the source code.
Tell me what do you think about this post. I'll write better and better entries.
They can be easily customized to meet the unique requirements of your project.
4 Responses to “Bubble Chaos: a complete flash game in only 131 lines”
Leave a Reply


wow really good clear explanation 10/10 as always!
Cool man!
owow. another amazing tut by emanuele. Well done. Im going to edit this abit and post the result xD Thanks.
~Callum
wow really nice game, you should make the balls react when they hit each other. that would be really cool.