All pastes #364696 Raw Edit

Something

public text v1 · immutable
#364696 ·published 2007-02-20 10:00 UTC
rendered paste body
		for(i=0; i < _root.Balls.length; i++)
		{
			for(y=i+1; y < _root.Balls.length; y++)
			{		
				var dx = _root.Balls[i]._x - _root.Balls[y]._x;
				var dy = _root.Balls[i]._y - _root.Balls[y]._y;
				
				if((dx*dx + dy*dy) < ((20*20) + (20*20))/2) // Hit
				{
					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[y].velocity[0] * _root.Balls[y].velocity[0] + _root.Balls[y].velocity[1] * _root.Balls[y].velocity[1]);
					
					if(_root.Balls[i].velocity[0] > 0)
						_root.Balls[i].velocity[0] /= s1;
					if(_root.Balls[i].velocity[1] > 0)
						_root.Balls[i].velocity[1] /= s1;
						
					if(_root.Balls[y].velocity[0] > 0)
						_root.Balls[y].velocity[0] /= s1;
					if(_root.Balls[y].velocity[1] > 0)
						_root.Balls[y].velocity[1] /= s1;
						
					var len = Math.sqrt(dx*dx + dy*dy);
					
					dx /= len;
					dy /= len;
				}
			}
		}