Meny of you have probably played Filler.

The idea is to fill 80% of the stage with a limited amount of orbs.
And another orb can’t hit your orb when it’s still growing.
So in this tutorial I will be showing you how to make the orbs.
The only thing you need in the library is a perfect circle movieclip with the linkage identifier of Filler.
This is the code:
-
FillersonStage = 0;
-
gravity = .1;//You might want to increase the gravity a little… Meybe .3?
-
delay = 10;
-
_root.onMouseDown = function() {
-
FillersonStage++;
-
this.attachMovie("Filler", "Filler_"+FillersonStage, _root.getNextHighestDepth(), {_width:20, _height:20, _x:_xmouse, _y:_ymouse});
-
this["Filler_"+FillersonStage].growing = true;
-
this["Filler_"+FillersonStage].vy = 0;
-
this["Filler_"+FillersonStage].vx = 0;
-
this["Filler_"+FillersonStage].rad = this["Filler_"+FillersonStage]._width/2;
-
this["Filler_"+FillersonStage].m = this._height;
-
this["Filler_"+FillersonStage].onEnterFrame = function() {
-
for (i=0; i<FillersonStage+1; i++) {
-
if(_root["Filler_"+i] != this){
-
for(x=0; x<25;x++){
-
checkColl(this, _root["Filler_"+i]);//Checks hit test between balls —- See function down —
-
}
-
}
-
}
-
this._y += this.vy;//Adds vy to filler._y
-
this._x += this.vx;//Adds vx to filler._x
-
this.vx *= .99;//Adds friction — shouldnt be over 1
-
-
if (this._y+this.rad>400) {//If filler hits the bottom border
-
this._y = 400-this.rad;//Sets the fillers y
-
if (this.vy>2 or this.vy<-2 and this.growing == false) {//Checks if the fillers vy is great enough to bounce and if it is not beeing dragged
-
this.vy *= -.5;//Reverses the fillers vy
-
} else {
-
this.vy = 0;//Else if its vy is not great enough or it is beeing dragged vy = 0;
-
}
-
}
-
-
if(this._x-this.rad<0){
-
this._x = 0+this.rad;
-
this.vx *= -.3;
-
}
-
if(this._x+this.rad>550){
-
this._x = 550-this.rad;
-
this.vx *= -.3;
-
}
-
-
-
if (this.growing) {//If the filler is beeing dragged
-
-
//////////////////////THIS PART MAKES THE FILLER FOLLOW THE MOUSE/////////
-
var dist_x = _xmouse-this._x;
-
var dist_y = _ymouse-this._y;
-
var distance = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
-
angle = Math.atan2(dist_y, dist_x);
-
var speed = distance/delay;
-
this.vx = speed*Math.cos(angle);
-
this.vy = speed*Math.sin(angle);
-
//////////////////////THIS PART MAKES THE FILLER FOLLOW THE MOUSE/////////
-
-
-
this._width += 2.5;//Ads 2.5 to the fillers width and hight
-
this._height += 2.5;
-
this.rad = this._width/2;//Sets the radius of the filler — Need for hit test
-
this.m = this._height;//Sets the diameter of the filler — Need for hit test
-
} else {//Else
-
this.vy += gravity;//Adds gravity
-
}
-
};
-
};
-
_root.onMouseUp = function() {
-
this["Filler_"+FillersonStage].growing = false;//Stops the dragging
-
};
-
-
-
/*
-
//
-
//The following function was made my Noddybear
-
//from Emanuele Feronatos Forum.
-
//
-
//
-
//Forum : http://www.triquitips.com
-
//
-
//Noddybear’s website: http://www.noddybear.co.nr/
-
//
-
//
-
//You are free to use it
-
//
-
//
-
//For this function to work your circles will need to have 4 variables
-
//citrcle._x += vx
-
//citrcle._y += vy
-
//rad = cirlce._height/2
-
//m = cirlce._height
-
//
-
//In this code the circles already have these variables.
-
//
-
*/
-
function checkColl(b1, b2) {//This function checks the colison of the fillers.
-
var dx = b2._x-b1._x;
-
var dy = b2._y-b1._y;
-
var dist = Math.sqrt(dx*dx+dy*dy);//Gets the distance between 2 circles
-
if (dist<b1.rad+b2.rad and b1.growing == false and b2.growing == false) {//If the circles are touching, bounce away.
-
var angle = Math.atan2(dy, dx);
-
cosa = Math.cos(angle);
-
sina = Math.sin(angle);
-
vx1p = cosa*b1.vx+sina*b1.vy;
-
vy1p = cosa*b1.vy-sina*b1.vx;
-
vx2p = cosa*b2.vx+sina*b2.vy;
-
vy2p = cosa*b2.vy-sina*b2.vx;
-
P = vx1p*b1.m+vx2p*b2.m;
-
V = vx1p-vx2p;
-
vx1p = (P-b2.m*V)/(b1.m+b2.m);
-
vx2p = V+vx1p;
-
b1.vx = cosa*vx1p-sina*vy1p;//Bounces the balls away
-
b1.vy = cosa*vy1p+sina*vx1p;//Bounces the balls away
-
b2.vx = cosa*vx2p-sina*vy2p;//Bounces the balls away
-
b2.vy = cosa*vy2p+sina*vx2p;//Bounces the balls away
-
diff = ((b1.rad+b2.rad)-dist)/2;
-
cosd = cosa*diff;
-
sind = sina*diff;
-
b1._x -= cosd;
-
b1._y -= sind;
-
b2._x += cosd;
-
b2._y += sind;
-
}else{
-
if (dist<b1.rad+b2.rad){
-
if(b1.growing == true){
-
b1.removeMovieClip();
-
}
-
if(b2.growing == true){
-
b2.removeMovieClip();
-
}
-
}
-
-
}
-
}
-
It might be a little hard to read it in the browser, so you might just want to copy it right into flash and look at it there!
You should get something like this:
Notice that when too meny orbs are creating it will start to lag.
This is because of the for loops in the hit test between orbs.
If this disturbs you can remove 1 of the for loops, but remember that in Filler only about 80%
of the stage has to be filled. I might still fix this in future parts!
In the next part I will be showing you how to count how meny % of the stage has been filled and how to create the “Bad” orbs!
You can download the FLA file here!
by Nice, on September 5 2008 @ 2:45 pm
Nice this is realy good part two part two!