

--scene config vars

class MapProjectiles:
	def Init():
		self.parts = {}
		self.maxParts = 10000
		self.zeroRad = 0
	
	def AddProjRing( inX, inY, inNum ):
		if ( #self.parts < self.maxParts ) then
			r = .3
			stAng = 0.6
			endAng = PI2 * 1.000
			for i = 1, inNum:
				r = 1.3--1.2 * 3.0 * rand( .2, 2.0 )
				pct = i / inNum
				ang = stAng + endAng * pct
				xspd = r * sin( ang )
				yspd = r * cos( ang )
				radius = .05--rand( .05, .2 )
				insert( self.parts, { inX, inY, xspd, yspd, ( 1 - self.zeroRad ) * radius, 0 } )
		
		
		
	def Draw( t, dt ):
		Color( 1 )
		
		colPt = { 0, 0 }
		newPt = { 0, 0 }
		newSpd = { 0, 0 }
		
		newPt = { 0, 0 }
		newSpd = { 0, 0 }
		colPt = { 0, 0 }
		Color( .6, .6, 1, 1 )
		Tex( 'dot' )
		SetDepth( 0, 0 )
		Blend( 1 )
		remObjs = {}
		
		for i, v in pairs( self.parts ) do
			
			pos = { v[ 1 ], v[ 2 ] }
			spd = { v[ 3 ], v[ 4 ] }
			r = v[ 5 ]--.05 + .04 * sin( .1 * i )
			
			v[ 6 ] -= dt
			collides = 0
			--if ( v[ 6 ] <= .08 or !gPrecalcCol ):
			if ( true ):
				--do real collision test
				collides = MapPoint( pos, spd, r, colPt, newPt, newSpd )
				
				v[ 1 ] = newPt[ 1 ]
				v[ 2 ] = newPt[ 2 ]
				
				tanSpd = { .5 * ( spd[ 1 ] + newSpd[ 1 ] ), .5 * ( spd[ 2 ] + newSpd[ 2 ] ) }
				
				v[ 3 ] = newSpd[ 1 ]
				v[ 4 ] = newSpd[ 2 ] -- dt * 4
				if ( collides > 0 and false ):
					v[ 3 ] = v[ 3 ] * .5 + .5 * tanSpd[ 1 ]
					v[ 4 ] = v[ 4 ] * .5 + .5 * tanSpd[ 2 ]
				;
				
				
			else
				v[ 1 ] += dt * v[ 3 ]
				v[ 2 ] += dt * v[ 4 ]
			;
			
			if abs( v[ 2 ] ) > 15.0 or abs( v[ 1 ] ) > 15.0:
				--print 'out', v[ 6 ]
				insert( remObjs, 1, i )
			;
			
			
			
			
			Push()
			Move( v[ 1 ], v[ 2 ], 0 )
			Scale( r + .05 * self.zeroRad )
			Geom( 'quad' )
			
			Pop()
			
		;
		
		for i, v in ipairs( remObjs ) do
			table.remove( self.parts, v )
		end
		
		Color( 1 )
		Tex( -1 )
		
