function checkPowerupHit()
{
	for(var i in powerup_bodies)
	{
		var powerup = powerup_bodies[i];
		for(var k in ball_bodies)
		{
			if (powerup.used)	
				break; // In case a linked teleport is used before reaching it in the loop
				
			var ballk = ball_bodies[k];
			var vec = Vector.sub(ballk.position, powerup.position);
			if (Vector.magnitude(vec) < (powerup.circleRadius + ballk.circleRadius))
			{	// A ball touched a powerup
				if (powerup.name=="powerup_force")
				{
					var netF = 1.5; //adjust this to determine mangitude of force
					var force = Vector.create(netF*Math.sin(powerup.angle), -netF*Math.cos(powerup.angle));
					Body.applyForce(ballk, ballk.position, force);
				}
				else if (powerup.name=="powerup_teleport_blue" || powerup.name=="powerup_teleport_orange")
				{
					if (!powerup.link)
						continue;  // This teleport has not yet been linked
					Body.setPosition(ballk, powerup.link.position);
					// Remove the linked teleport
					powerup.link.used = true;
					Composite.remove(engine.world, powerup.link);
				}
				powerup.used = true; // Mark for later deletion (cannot delete in a for loop)
				Composite.remove(engine.world, powerup);
			}
		}
	}
	// Remove powerups that were used from all arrays
	avis.filter(function(e) { return !(e.body.used); });
	powerup_bodies = powerup_bodies.filter(function(e) { return !(e.used); });
	level_bodies = level_bodies.filter(function(e) { return !(e.used); });
}
//just in case make sure though. . .
just in case make sure though.
just in case make sure though .
function checkPowerupHit()
{
	for(var i in powerup_bodies)
	{
		var powerup = powerup_bodies[i];
		for(var k in ball_bodies)
		{
			if (powerup.used)	
				break; 
			var ballk = ball_bodies[k];
			var vec = Vector.sub(ballk.position, powerup.position);
			if (Vector.magnitude(vec) < (powerup.circleRadius + ballk.circleRadius))
			{	
				if (powerup.name=="powerup_force")
				{
					var netF = 1.5; 
					var force = Vector.create(netF*Math.sin(powerup.angle), -netF*Math.cos(powerup.angle));
					Body.applyForce(ballk, ballk.position, force);
				}
				else if (powerup.name=="powerup_teleport_blue" || powerup.name=="powerup_teleport_orange")
				{
					if (!powerup.link)
						continue;  
					Body.setPosition(ballk, powerup.link.position);
					powerup.link.used = true;
					Composite.remove(engine.world, powerup.link);
				}
				powerup.used = true; 
				Composite.remove(engine.world, powerup);
			}
		}
	}
	avis.filter(function(e) { return !(e.body.used); });
	powerup_bodies = powerup_bodies.filter(function(e) { return !(e.used); });
	level_bodies = level_bodies.filter(function(e) { return !(e.used); });
}
function checkPowerupHit ( ) { for ( var i in powerup_bodies ) { var powerup = powerup_bodies [ i ] ; for ( var k in ball_bodies ) { if ( powerup . used ) break ; var ballk = ball_bodies [ k ] ; var vec = Vector . sub ( ballk . position , powerup . position ) ; if ( Vector . magnitude ( vec ) < ( powerup . circleRadius + ballk . circleRadius ) ) { if ( powerup . name == "powerup_force" ) { var netF = 1.5 ; var force = Vector . create ( netF * Math . sin ( powerup . angle ) , - netF * Math . cos ( powerup . angle ) ) ; Body . applyForce ( ballk , ballk . position , force ) ; } else if ( powerup . name == "powerup_teleport_blue" || powerup . name == "powerup_teleport_orange" ) { if ( ! powerup . link ) continue ; Body . setPosition ( ballk , powerup . link . position ) ; powerup . link . used = true ; Composite . remove ( engine . world , powerup . link ) ; } powerup . used = true ; Composite . remove ( engine . world , powerup ) ; } } } avis . filter ( function ( e ) { return ! ( e . body . used ) ; } ) ; powerup_bodies = powerup_bodies . filter ( function ( e ) { return ! ( e . used ) ; } ) ; level_bodies = level_bodies . filter ( function ( e ) { return ! ( e . used ) ; } ) ; }
just in case make sure though.
just in case make sure though .
// In case a linked teleport is used before reaching it in the loop // A ball touched a powerup //adjust this to determine mangitude of force // This teleport has not yet been linked // Remove the linked teleport // Mark for later deletion (cannot delete in a for loop) // Remove powerups that were used from all arrays