-- effect designed by Martini, adapted by Krys to use generic DEFAULT_SPRITES and annotated with comments

local splash -- group for splash bubble particles

-- splash bubble particle init function
local function splashfx(mesh) -- mesh index is passed to function

local part = createSpritePart (splash) -- create particle of splash bubble group
	
	part.emitterIndex = getLaraIndex()  -- get Lara's tomb4 index
	part.emitterNode = mesh -- attach particle to specified mesh
	
	part.spriteIndex = 13 -- bubble sprite
	
	part.lifeSpan = 50
			
	part.fadeIn = 1
	part.fadeOut= 20
	
	part.sizeStart = 10 + randomFloat (-10, 20)
	part.sizeEnd   = part.sizeStart
	
	part.colStart.r = 80
	part.colStart.g = 80
	part.colStart.b = 80
	part.colEnd.r = 128
	part.colEnd.g = 128
	part.colEnd.b = 128
	
	part.vel.y = randomFloat (1, 2)
	part.vel.x = randomFloat (-8, 8)
	part.vel.z = randomFloat (-8, 8)
	
	part.accel.x = -part.vel.x / part.lifeSpan
	part.accel.y = -part.sizeStart * 0.01
	part.accel.z = -part.vel.z / part.lifeSpan
	
	part.pos.x = randomFloat (-32, 32)
	part.pos.z = randomFloat (-32, 32)
	part.pos.y = randomFloat (-15, 15)
	
end

local bubble -- group for bubble particles
local bubbleTimer = 0

-- bubble particle init function
local function bubblefx(mesh) -- mesh index is passed to function

	local part = createSpritePart (bubble)
	
	part.emitterIndex = getLaraIndex()  -- get Lara's tomb4 index
	part.emitterNode = mesh -- attach particle to specified mesh
	
	part.spriteIndex = 13 -- bubble sprite
	
	part.lifeSpan  = 45
	
	part.fadeIn = 5
	part.fadeOut= 20
	
	part.sizeStart = 10 + randomFloat (-10, 20)
	part.sizeEnd   = part.sizeStart
	
	part.colStart.r = 80
	part.colStart.g = 80
	part.colStart.b = 80
	part.colEnd.r = 128
	part.colEnd.g = 128
	part.colEnd.b = 128
	
	part.vel.y = randomFloat (1, 2)
	part.vel.x = randomFloat (-8, 8)
	part.vel.z = randomFloat (-8, 8)
	
	part.accel.x = -part.vel.x / part.lifeSpan
	part.accel.y = -part.sizeStart * 0.01
	part.accel.z = -part.vel.z / part.lifeSpan
	
	part.pos.x = randomFloat (-32, 32)
	part.pos.z = randomFloat (-32, 32)
	part.pos.y = randomFloat (-15, 15)
	
end

-- this is the main function responsible to attaching particles during specific Lara swim animations
local function swimEffects()
	
	-- check if Lara is performing a particular animation and attach effects accordingly
	
	if Lara.animNumber == 109 then -- underwater idle to swim
		bubblefx(3) -- attach bubble to left foot (mesh = 3)
		bubblefx(6) -- attach bubble to right foot (mesh = 6)
		bubblefx(10) -- attach bubble to right hand (mesh = 10)
		bubblefx(13) -- attach bubble to left hand (mesh = 13)
	end
	
	-- etc for other swim animations
	
	
	if Lara.animNumber == 112 then
		local count = 6		
		for i = 1, count do
			splashfx(3)
			splashfx(6)
			splashfx(10)
			splashfx(13)
		end
	end

	if Lara.animNumber == 152 then
		local count = 6		
		for i = 1, count do
			splashfx(3)
			splashfx(6)
			splashfx(10)
			splashfx(13)
		end
	end

	if Lara.animNumber == 154 then
		local count = 6		
		for i = 1, count do
			splashfx(3)
			splashfx(6)
			splashfx(10)
			splashfx(13)
		end
	end

	if Lara.animNumber == 192 then
		splashfx(3)
		splashfx(3)
		splashfx(6)
		splashfx(6)
		splashfx(10)
		splashfx(10)
		splashfx(13)
		splashfx(13)
	end

	if Lara.animNumber == 115 then
		bubblefx(3)
		bubblefx(6)
		bubblefx(10)
		bubblefx(13)
	end

	if Lara.animNumber == 116 then -- surface swim forward
		bubblefx(3)
		bubblefx(6)	
	end
	
	if Lara.animNumber == 129 then
		bubblefx(3)
		bubblefx(6)
		bubblefx(10)
		bubblefx(13)
	end

	if Lara.animNumber == 141 then -- surface swim backward
		bubblefx(3)
		bubblefx(6)
		bubblefx(10)
		bubblefx(13)	
	end
	
	if Lara.animNumber == 143 then -- surface swim left
		bubblefx(3)
		bubblefx(6)
	end
	
	if Lara.animNumber == 144 then -- surface swim right
		bubblefx(3)
		bubblefx(6)
	end

	if Lara.animNumber == 86 then -- underwater swim loop
		bubblefx(3)
		bubblefx(6)
		bubblefx(10)
		bubblefx(13)
	end
	
	if Lara.animNumber == 203 then -- underwater roll start
		bubblefx(3)
		bubblefx(6)
		bubblefx(10)
		bubblefx(13)
	end
	
	if Lara.animNumber == 205 then -- underwater roll end
		bubblefx(3)
		bubblefx(6)
		bubblefx(10)
		bubblefx(13)	
	end

	if Lara.animNumber == 497 then -- underwater kick part 1
		bubblefx(3)
		bubblefx(6)
		bubblefx(10)
		bubblefx(13)
	end

	if Lara.animNumber == 498 then -- underwater kick part 2
		bubblefx(3)
		bubblefx(6)
		bubblefx(10)
		bubblefx(13)	
	end

	if Lara.animNumber == 499 then -- underwater kick part 3
		bubblefx(3)
		bubblefx(6)
		bubblefx(10)
		bubblefx(13)	
	end

end

-- particle group creation

splash = createGroup(swimEffects, nil) -- all swim effects are managed by splash group init function swimEffects()

bubble = createGroup(nil, nil) -- bubble group with no init function