# Managing multiple balls collisions with Flash

The first post of the new year (you should know the new year starts on May, 27th) is made by Sunil Changrani and it’s about managing multiple balls collisions with Flash.

I already published a tutorial about Managing ball vs ball collision with Flash but this time we’ll manage any number of balls.

Sunil was just making a Flash game and he ended up getting stuck when he needed a lot of circles to collide with each other.

With some help from Tony Pa, Voidskipper and Kazama_bee, ended up making some nice perfect collisions.

In the movie there are two symbols, one empty movieclip called `blip` and a movieclip called `circle` (which has the ball)

So here it is the commented code:

```stop();
t = 0;
dx = 0;
//Creating variables
_root.attachMovie("blip","blip",_root.getNextHighestDepth(),{_x:1500, _y:200});
_root.createEmptyMovieClip("container_movie",_root.getNextHighestDepth());
//attaching the movieclips
blip.onEnterFrame = function() {
//this is the function that executes every frame
if (Math.random()*1000<100 and t<50) {
//This condition adds another circle after a certain random interval till total circles are 50

circle = container_movie.attachMovie("circle", "circle"+t, container_movie.getNextHighestDepth(), {_width:a, _height:b, _x:(20+Math.random()*300), _y:(20+Math.random()*300), _rotation:Math.random()*300});
t++;
circle.xspeed = Math.random()*9;
circle.yspeed = Math.random()*9;
//Creating the circle with random x and y speeds.
circle.onEnterFrame = function() {
this._x -= this.xspeed;
this._y -= this.yspeed;
//Motion of the circles
if (this._x<10) {
this._x = 10;
this.xspeed = -this.xspeed;
}
if (this._x>490) {
this._x = 490;
this.xspeed = -this.xspeed;
}
if (this._y<10) {
this._y = 10;
this.yspeed = -this.yspeed;
}
if (this._y>390) {
this._y = 390;
this.yspeed = -this.yspeed;
}
//Making sure the circle won't go out of the boundaries.
};
}
//From here I start checking for collisions of the circles
for (i=0; i
And this is the result: look at the balls... how interesting!

Now tell me for how long will we see games based on this engine... I have one idea... download the source code and thank all developers.
```
215 GAME PROTOTYPES EXPLAINED WITH SOURCE CODE
// 1+2=3
// 10000000
// 2 Cars
// 2048
// Avoider
// Ballz
// Block it
// Blockage
// Bloons
// Boids
// Bombuzal
// Breakout
// Bricks
// Columns
// CubesOut
// Dots
// DROP'd
// Dudeski
// Eskiv
// Filler
// Fling
// Globe
// HookPod
// Hundreds
// InkTd
// Iromeku
// Lumines
// Magick
// MagOrMin
// Maze
// Memdot
// Nano War
// Nodes
// o:anquan
// Ononmin
// Pacco
// Phyballs
// Platform
// Poker
// Pool
// Poux
// Pudi
// qomp
// Racing
// Renju
// SameGame
// Security
// Sling
// Slingy
// Sokoban
// Splitter
// Sproing
// Stack
// Stairs
// Stringy
// Sudoku
// Tetris
// Threes
// Toony
// Turn
// TwinSpin
// vvvvvv
// Wordle
// Worms
// Yanga
// Zhed
// zNumbers