Bubble Chaos: a complete flash game in only 131 lines
- May 12, 2007 by Emanuele Feronato
- Filed under Flash | 4 Comments
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | 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.
They can be easily customized to meet the unique requirements of your project.
4 Responses
Leave a Reply
- Una guida completa al gioco del poker online e una selezione dei migliori casino online.
- casino online
- migliori casino online
- BlackJack online
- casinò online
- Giochi casino






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.