local function spring_twirl(mo)
  if not mapheaderinfo[gamemap].springspin then return end
	//assign player to a variable to make our lives a little bit easier (and our code a little bit readable)
	local player = mo.player
	//is player.twirl_angle assigned? if not, create it.
	if player.twirl_angle == nil then
		player.spring_twirl = false
		player.twirl_angle = 0	//starts at 0
	end
	//clear the spring twirl flag when we are at 0 momz
	if mo.momz == 0 and player.spring_twirl == true then
		player.spring_twirl = false
	end
	//are we currently in the spring animation?
	if player.panim == PA_SPRING and player.spring_twirl == true then
		//add to our twirl angle
		player.twirl_angle = player.twirl_angle + FixedAngle(mo.momz)
		//make our draw angle twirl angle, therefore showing us spinning when we hit a spring
		player.drawangle = player.twirl_angle
	end
end

local function vertical_spring(thing,toucher)
  if not mapheaderinfo[gamemap].springspin then return end
	//is our toucher a player?
	if toucher.type == MT_PLAYER then
		//height checks
		if toucher.z + toucher.height > thing.z and toucher.z < thing.z + thing.height + 4*FRACUNIT then
			//set spring twirl to true
			toucher.player.spring_twirl = true
			toucher.player.twirl_angle = toucher.angle
		end
		//ugh why doesn't mobjcollide take height into account
	end
end

local function diagonal_spring(thing,toucher)
  if not mapheaderinfo[gamemap].springspin then return end
	if toucher.type == MT_PLAYER then
		//height checks
		if toucher.z + toucher.height > thing.z and toucher.z < thing.z + thing.height + 4*FRACUNIT then
			//set spring twirl to false
			//this is only so that if we go from a vertical spring to a diagonal one, we don't twirl again
			//we don't have to do this for the horziontal springs since they don't put you into your spring animation
			toucher.player.spring_twirl = false
		end
	end
end

addHook("MobjThinker", spring_twirl, MT_PLAYER)

addHook("MobjCollide", vertical_spring, MT_REDSPRING)
addHook("MobjCollide", vertical_spring, MT_YELLOWSPRING)
addHook("MobjCollide", vertical_spring, MT_BLUESPRING)
addHook("MobjCollide", vertical_spring, MT_SPRINGSHELL)
addHook("MobjCollide", vertical_spring, MT_YELLOWSHELL)
addHook("MobjCollide", vertical_spring, MT_YELLOWSPRINGBALL)
addHook("MobjCollide", vertical_spring, MT_REDSPRINGBALL)

addHook("MobjCollide", diagonal_spring, MT_REDDIAG)
addHook("MobjCollide", diagonal_spring, MT_YELLOWDIAG)
addHook("MobjCollide", diagonal_spring, MT_BLUEDIAG)