All pastes #367360 Raw Edit

Untitled

public text v1 · immutable
#367360 ·published 2007-02-22 09:11 UTC
rendered paste body
				var dijx = _root.Balls[i]._x - _root.Balls[j]._x;
				var dijy = _root.Balls[i]._y - _root.Balls[j]._y;
				
				var djix = _root.Balls[j]._x - _root.Balls[i]._x;
				var djiy = _root.Balls[j]._y - _root.Balls[i]._y;
				
				if((dijx*dijx + dijy*dijy) < ((20+20) * (20+20))) // Hit
				{
					trace('hit' + i);
					var hitangle = (Math.atan2(dijx, dijy)) / 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 dijl = Math.sqrt(dijx*dijx + dijy*dijy);
					var djil = Math.sqrt(djix*djix + djiy*djiy);
					
					if (dijl > 0)
					{
						dijx /= dijl;
						dijy /= dijl;
					}
					
					if(djil > 0)
					{
						djiy /= djil;
						djiy /= djil;
					}