freeslot(
"sfx_darkt", "sfx_dark2")
addHook("PlayerThink",  function(p)
    
    if not (p.mo and p.mo.valid and p.mo.skin == "darksupersonic")
        return
    end
   
    
    if not p.powers[pw_super]
        
        if p.eggoldability != nil
            p.charability = p.eggoldability
            p.eggoldability = nil
        end
        -- Non-super people can't be super-flying
        p.eggsuperflying = false
        return
    end
   

    if not (p.powers[pw_extralife]) and p.eggmusic == 1
        S_ChangeMusic("dark2",true,p)
    end
   

    if p.mo.state == S_PLAY_RIDE or p.powers[pw_carry] == CR_ZOOMTUBE
        return
    end
   

    p.eggsuperflying = $ or false  
    p.eggflystart = $ or false 
    p.eggflyboost = $ or false  
    p.eggboostcost = 5  
    p.eggmaxvert = 22*FRACUNIT  
    p.eggoldability = $ or CA_NONE 
   
    
    if p.charability != CA_NONE
        p.charability, p.eggoldability = CA_NONE, $1
    end
   
    
    if P_IsObjectOnGround(p.mo)
        p.eggsuperflying = false
    else
    
        p.pflags = $ | PF_THOKKED
    end
   
    
    if not p.eggsuperflying
        return
    end
   
    
    p.mo.momz = $-P_GetMobjGravity(p.mo)
   
    
    if p.mo.state == S_PLAY_FALL
        p.mo.state = S_PLAY_FLOAT
    end
   
    
	p.pflags = $ & ~PF_JUMPED & ~PF_SPINNING
   
    
    if not (p.cmd.buttons & BT_JUMP)
        p.eggflystart = false
    end
	
	
	if p.eggflystart == true and p.eggflymode == 1 
		P_SetObjectMomZ(p.mo, 0*FRACUNIT)
	end
   

    if not (p.cmd.buttons & BT_USE) or not (p.cmd.buttons & BT_JUMP)
        p.eggflyboost = true
    end
   

    if (p.cmd.buttons & BT_JUMP) and not (p.cmd.buttons & BT_USE) and not p.eggflystart or (p.cmd.buttons & BT_JUMP) and not (p.cmd.buttons & BT_USE) and p.eggflymode == 2
        P_SetObjectMomZ(p.mo, 1*FRACUNIT, true) 
    end
   
    
    if (p.cmd.buttons & BT_USE) and not (p.cmd.buttons & BT_JUMP)
        P_SetObjectMomZ(p.mo, -1*FRACUNIT, true)
    end
   
    
    p.mo.momz = max(min(p.eggmaxvert, p.mo.momz), 0-p.eggmaxvert)
   
    
    if (p.cmd.buttons & BT_JUMP) and (p.cmd.buttons & BT_USE)
    and p.eggflyboost and p.rings >= p.eggboostcost
        p.rings = $ - p.eggboostcost
        P_InstaThrust(p.mo, p.mo.angle, 110*FRACUNIT)
        P_FlashPal(p, PAL_WHITE, 10)
        S_StartSound(p.mo, sfx_darkt)
        p.eggflyboost = false
    end
   

    if not (p.cmd.buttons & BT_JUMP) and not (p.cmd.buttons & BT_USE)
        p.mo.momz = abs($)>FRACUNIT and $*9/10 or 0
    end
end)
 
addHook("AbilitySpecial", function(p)
    if p.mo.skin == "darksupersonic" and p.mo and p.mo.valid
    and p.powers[pw_super] and not p.eggsuperflying
        p.eggsuperflying = true
        p.eggflystart = true
        p.mo.state = S_PLAY_FLOAT
        return true
    end
    return false
end)