All pastes #367336 Raw Edit

Something

public text v1 · immutable
#367336 ·published 2007-02-22 08:41 UTC
rendered paste body
		for(i=0; i < _root.Balls.length; i++)
		{
			for(j=i+1; j < _root.Balls.length; j++)
			{		
				var dx = _root.Balls[i]._x - _root.Balls[j]._x;
				var dy = _root.Balls[i]._y - _root.Balls[j]._y;
				
				if((dx*dx + dy*dy) < ((20+20) * (20+20))) // Hit
				{
					trace('hit' + i);
					var hitangle = (Math.atan2(dx, dy)) / Math.PI * 180;
					
					var s1 = Math.sqrt(_root.Balls[i].velocity[0] * _root.Balls[i].velocity[0] + _root.Balls[i].velocity[1] * _root.Balls[i].velocity[1]);
					var s2 = Math.sqrt(_root.Balls[j].velocity[0] * _root.Balls[j].velocity[0] + _root.Balls[j].velocity[1] * _root.Balls[j].velocity[1]);
					
					if(s1 > 0)
					{
						_root.Balls[i].velocity[0] /= s1;
						_root.Balls[i].velocity[1] /= s1;
					}
						
					if(s2 > 0)
					{
						_root.Balls[j].velocity[0] /= s2;
						_root.Balls[j].velocity[1] /= s2;
					}
						
					var len = Math.sqrt(dx*dx + dy*dy);
					
					if (len > 0)
					{
						dx /= len;
						dy /= len;
					}
				}
			}
		}