//Sonic Lost World Bounce Attack. made by MotdSpork. Boing!
addHook("MobjThinker", function(sonic)
	if (sonic and sonic.skin == "blueshoessonic") 
	and sonic.player.playerstate == PST_LIVE 
	and not (sonic.player.powers[pw_super]) 
		if sonic.player.bounceattack == nil 
			sonic.player.bounceattack = 0 
		end
		if sonic.player.bouncenumber == nil 
			sonic.player.bouncenumber = 0 
			sonic.player.justchangedbouncenumber = 0 
		end
		if P_IsObjectOnGround(sonic)
		and sonic.player.bounceattack == 0 
			sonic.player.bouncenumber = 0 
		end
		if sonic.player.usedown == nil 
		or not (sonic.player.cmd.buttons & BT_USE) 
			sonic.player.usedown = 0 
			sonic.player.justchangedbouncenumber = 0 
		end
		if P_IsObjectOnGround(sonic) 
		and (sonic.player.cmd.buttons & BT_USE) 
			sonic.player.usedown = 1 
		end
		if sonic.player.pflags & PF_JUMPED 
		and not (P_IsObjectOnGround(sonic)) 
		and sonic.player.cmd.buttons & BT_USE 
		and sonic.player.bounceattack == 0 
		and sonic.player.usedown == 0 
		and not (sonic.player.exiting) 
		and sonic.health 
		and not (P_PlayerInPain(sonic.player)) 
			sonic.player.bounceattack = 1 
			P_SetObjectMomZ(sonic, -45*FRACUNIT) 

			sonic.player.pflags = $1|PF_THOKKED 
		end

		if (sonic.eflags & MFE_JUSTHITFLOOR)
		and not (sonic.player.pflags & PF_SPINNING) 
		and not (sonic.player.pflags & PF_STARTDASH)
		and not (sonic.tracer and sonic.tracer.type == MT_TUBEWAYPOINT)
		and sonic.player.bounceattack == 1 
		and sonic.health 
		and not (P_PlayerInPain(sonic.player)) 
			if sonic.player.bouncenumber == 0 
			and sonic.player.justchangedbouncenumber == 0 
				sonic.player.justchangedbouncenumber = 1 
				sonic.player.bouncenumber = 1 
				sonic.player.pflags = $1|PF_JUMPED 
				P_SetObjectMomZ(sonic, 12*FRACUNIT)
				if not (sonic.player.panim == PA_ROLL)
					sonic.state = S_PLAY_ROLL 
				end
			end
			if sonic.player.bouncenumber == 1 
			and sonic.player.justchangedbouncenumber == 0 
			and not (P_PlayerInPain(sonic.player)) 
				sonic.player.justchangedbouncenumber = 1 
				sonic.player.bouncenumber = 1 
				sonic.player.pflags = $1|PF_JUMPED 
				P_SetObjectMomZ(sonic, 13*FRACUNIT)
				if not (sonic.player.panim == PA_ROLL) 
					sonic.state = S_PLAY_ROLL 
				end
			end
			if sonic.player.bouncenumber == 2 
			and sonic.player.justchangedbouncenumber == 0 
			and not (P_PlayerInPain(sonic.player)) 
				sonic.player.justchangedbouncenumber = 1 
				sonic.player.bouncenumber = 0 
				sonic.state = S_PLAY_SPRING 
				P_SetObjectMomZ(sonic, 17*FRACUNIT) 
				sonic.player.pflags = $1 & ~PF_JUMPED 
			end
			sonic.player.bounceattack = 0 
			sonic.player.usedown = 1 

			S_StartSound(sonic, sfx_thok) 	
			
		end
		
		
		if sonic.player.bounceattack == 1
		and sonic.health 
		and not (P_PlayerInPain(sonic.player)) 
			P_SpawnThokMobj(sonic.player) 
			if not (sonic.player.panim == PA_ROLL) 
				sonic.state = S_PLAY_ROLL 
			end
			if (sonic.momz > (9000*P_MobjFlip(sonic))) 
				P_SetObjectMomZ(sonic, FixedMul(-55*FRACUNIT, sonic.scale)) 
			end
		else 
			sonic.player.bounceattack = 0 
		end
		if sonic.player.bounceattack == 1 
			sonic.player.pflags = $1 & ~PF_SPINNING 
		end
		if not (sonic.player.pflags & PF_JUMPED) 
			sonic.player.bounceattack = 0 
		end
		
		if sonic.eflags & MFE_GOOWATER 
		or sonic.player.powers[pw_carry] 
		
			sonic.player.bounceattack = 0 
		end
		if not (sonic.player.pflags & PF_JUMPED) 
			sonic.player.bounceattack = 0 
		end
	end
end, MT_PLAYER)


//Weak Homing from BuggiTheBug
addHook("PlayerThink", function(player)
	if player.mo.skin == "blueshoessonic"
	and player.pflags & PF_JUMPED
		player.target = P_LookForEnemies(player, true, true)
		if player.target
		and player.pflags & PF_JUMPED
			P_SpawnLockOn(player, player.target, S_LOCKON1)
		end
	end	
end)


addHook("AbilitySpecial", function(player)
	if player.mo.skin == "blueshoessonic"
		player.target = P_LookForEnemies(player, true, true)
		if not P_IsObjectOnGround(player.mo)
			if player.target
				P_HomingAttack(player.mo, player.target)
				P_SpawnThokMobj(player)
				S_StartSound(player.mo, sfx_zoom)
				player.mo.state = S_PLAY_ROLL
				player.pflags = $1 & ~PF_THOKKED
			end
			if not player.target 
			and not (player.pflags & PF_THOKKED)
				P_Thrust(player.mo, player.mo.angle, 30*FRACUNIT)
				P_SetObjectMomZ(player.mo, 7*FRACUNIT)
				P_SpawnThokMobj(player)
				S_StartSound(player.mo, sfx_thok)
				player.mo.state = S_PLAY_ROLL
				player.pflags = $|PF_THOKKED
			end	
		end
	end	
end)	

addHook("PlayerThink", function(player)
		if player.mo.skin == "blueshoessonic"
		and player.powers[pw_super]
			player.powers[pw_shield] = SH_ATTRACT
		end
	end)

//Theese next 2 codes after this are from kirb
		addHook("PlayerThink", function(player)
		if player.mo.skin == "blueshoessonic"
		and (player.mo.state == S_PLAY_SUPER_TRANS4)
		P_FlashPal(player, PAL_WHITE, 55)
		P_NukeEnemies(player.mo, player.mo, 2050*FRACUNIT)
		    P_StartQuake(20*FRACUNIT, 55)
	end
end)


addHook("ThinkFrame", function()
for player in players.iterate
	if player.mo and player.mo.skin == "blueshoessonic"
		player.stimer = $ or 0
		if player.stimer > 0 then player.stimer = ($ - 1) end
		player.tsound = $ or 0
		player.tsound = ($ + 1) % 2
		end
	end
end)


addHook("ThinkFrame", function()
  for player in players.iterate 
    if player.mo.skin == "blueshoessonic" and player.powers[pw_super] and player.stimer == 0 then
	  A_GoldMonitorSparkle(player.mo, 0, 0)
	  player.stimer = 5
	 end
   end
 end)


//This is what makes the super theme only for the characters
addHook("ThinkFrame", do
	for player in players.iterate
		if (player.mo and player.mo.valid and player.mo.skin == "sonic")
			if not player.powers[pw_extralife]
			and not (player.exiting)
			if player.powers[pw_super] then
				S_ChangeMusic("open",true,player)
			end	
		else
			P_RestoreMusic(player)
			end
		end
	end
end)


addHook("PlayerThink", function(player)
if not(player.mo.skin == "blueshoessonic") then return end
	 if player.powers[pw_super]
    player.actionspd = 130*FRACUNIT
	else
	player.actionspd = 70*FRACUNIT
  end
end)

//This is what makes sonic talk when he gets hurt.
freeslot("sfx_notget")


sfxinfo[sfx_notget].caption = "your not getting away!"

local function playerow(target, inflictor, source, damage)
	if target.skin == "blueshoessonic"
		S_StartSound(target, sfx_notget)
	end
end

addHook("MobjDamage", playerow, MT_PLAYER)





