local I=.5 local x=game:GetService("\080\108\097\121\101\114\115")local u=game:GetService("\082\117\110\083\101\114\118\105\099\101")local U=game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")local k=require(((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\080\114\111\106\101\099\116")):WaitForChild("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101"))local R=k:GetResource("\069\120\116\101\114\110\097\108\085\116\105\108\046\078\101\120\117\115\073\110\115\116\097\110\099\101\046\078\101\120\117\115\079\098\106\101\099\116")local p=k:GetResource("\071\097\109\101\068\097\116\097\046\073\116\101\109\046\066\108\111\120\107\105\110\115")local z=k:GetResource("\085\073\046\073\116\101\109\073\099\111\110")local n=R:Extend()n:SetClassName("\073\116\101\109\065\119\097\114\100\065\110\105\109\097\116\105\111\110")function n.__new(R,I,u,U,k)R:InitializeSuper()R.Frame=I R.StartPosition=u R.EndFrame=U R.AnimationTime=k local p=Instance.new("\083\099\114\101\101\110\071\117\105")p.DisplayOrder=100 p.Parent=x.LocalPlayer:WaitForChild("\080\108\097\121\101\114\071\117\105")R.ScreenGui=p end function n.DisplayItemAwardFromPosition(I,u)local U=Instance.new("\070\114\097\109\101")U.BackgroundTransparency=1 local k=z.new()k:SetParent(U)k:SetItem(I);(coroutine.wrap(function()local I=(((((x.LocalPlayer:WaitForChild("\080\108\097\121\101\114\071\117\105")):WaitForChild("\066\111\116\116\111\109\066\097\114\071\117\105")):WaitForChild("\066\111\116\116\111\109\070\114\097\109\101")):WaitForChild("\077\101\110\117\066\111\116\116\111\109\066\097\114\066\097\099\107\103\114\111\117\110\100")):WaitForChild("\073\110\118\101\110\116\111\114\121")):WaitForChild("\084\101\120\116\066\117\116\116\111\110")local R=n.new(U,u,I,.5)R:Play()k:Destroy()end))()end function n.DisplayItemAwardFromFrame(I,x)local u=x.AbsolutePosition+x.AbsoluteSize/2 n.DisplayItemAwardFromPosition(I,UDim2.new(0,u.X,0,u.Y))end function n.DisplayBloxkinAwardFromPosition(I,u)local U=Instance.new("\070\114\097\109\101")U.BackgroundTransparency=1 local k=Instance.new("\073\109\097\103\101\076\097\098\101\108")k.BackgroundTransparency=1 k.AnchorPoint=Vector2.new(.5,.5)k.Size=UDim2.new(1,0,2,0)k.Position=UDim2.new(.5,0,.5,0)k.Image=p[I].UnlockedImage k.Parent=U;(coroutine.wrap(function()local I=(((((x.LocalPlayer:WaitForChild("\080\108\097\121\101\114\071\117\105")):WaitForChild("\066\111\116\116\111\109\066\097\114\071\117\105")):WaitForChild("\066\111\116\116\111\109\070\114\097\109\101")):WaitForChild("\077\101\110\117\066\111\116\116\111\109\066\097\114\066\097\099\107\103\114\111\117\110\100")):WaitForChild("\067\111\108\108\101\099\116\097\098\108\101\115")):WaitForChild("\084\101\120\116\066\117\116\116\111\110")local k=n.new(U,u,I,.5)k:Play()end))()end function n.DisplayBloxkinAwardFromFrame(I,x)local u=x.AbsolutePosition+x.AbsoluteSize/2 n.DisplayBloxkinAwardFromPosition(I,UDim2.new(0,u.X,0,u.Y))end function n.Play(I)I.Frame.Size=UDim2.new(.075,0,.075,0)I.Frame.AnchorPoint=Vector2.new(.5,.5)I.Frame.SizeConstraint=Enum.SizeConstraint.RelativeYY I.Frame.Parent=I.ScreenGui local x=tick()while tick()-x<I.AnimationTime do I:SetFramePosition((tick()-x)/I.AnimationTime)u.RenderStepped:Wait()end I:SetFramePosition(1)I.Frame:Destroy()local k=I.EndFrame.AbsolutePosition+I.EndFrame.AbsoluteSize/2 local R=Instance.new("\070\114\097\109\101")R.AnchorPoint=Vector2.new(.5,.5)R.BackgroundColor3=Color3.new(1,1,1)R.BorderSizePixel=0 R.Size=UDim2.new(0,0,0,0)R.SizeConstraint="\082\101\108\097\116\105\118\101\089\089"R.Position=UDim2.new(0,k.X,0,k.Y)R.Parent=I.ScreenGui local p=Instance.new("\085\073\067\111\114\110\101\114")p.CornerRadius=UDim.new(.5,0)p.Parent=R;(U:Create(R,TweenInfo.new(.25),{BackgroundTransparency=1,Size=UDim2.new(.1,0,.1,0)})):Play()wait(.25)I.ScreenGui:Destroy()end function n.SetFramePosition(u,x)local U=u.EndFrame.AbsolutePosition+u.EndFrame.AbsoluteSize/2 local k=Vector2.new(u.StartPosition.X.Scale*u.ScreenGui.AbsoluteSize.X+u.StartPosition.X.Offset,u.StartPosition.Y.Scale*u.ScreenGui.AbsoluteSize.Y+u.StartPosition.Y.Offset)local R=U-k local p=u.AnimationTime*x local z=math.min(U.Y,k.Y)-u.ScreenGui.AbsoluteSize.Y*I local n=z-k.Y local J=math.atan2(n,R.X/2)local a=R.X/u.AnimationTime local l=a/math.cos(J)local m=math.sin(J)*l local Q=(2*(R.Y-m*u.AnimationTime))/u.AnimationTime^2 local V=m*p+(.5*Q)*p^2 u.Frame.Position=UDim2.new(0,k.X+R.X*x,0,k.Y+V)end return n
--[[
TheNexusAvenger

Animation for an item being awarded.
"Inpired" from Lego Universe's animation.
--]]

local ADDITIONAL_HEIGHT_MULTIPLIER = 0.5



local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")

local ReplicatedStorageProject = require(game:GetService("ReplicatedStorage"):WaitForChild("Project"):WaitForChild("ReplicatedStorage"))

local NexusObject = ReplicatedStorageProject:GetResource("ExternalUtil.NexusInstance.NexusObject")
local Bloxkins = ReplicatedStorageProject:GetResource("GameData.Item.Bloxkins")
local ItemIcon = ReplicatedStorageProject:GetResource("UI.ItemIcon")

local ItemAwardAnimation = NexusObject:Extend()
ItemAwardAnimation:SetClassName("ItemAwardAnimation")



--[[
Creates an item award animation.
--]]
function ItemAwardAnimation:__new(Frame,StartPosition,EndFrame,AnimationTime)
    self:InitializeSuper()

    --Store the information.
    self.Frame = Frame
    self.StartPosition = StartPosition
    self.EndFrame = EndFrame
    self.AnimationTime = AnimationTime

    --Create the container.
    local ScreenGui = Instance.new("ScreenGui")
    ScreenGui.DisplayOrder = 100
    ScreenGui.Parent = Players.LocalPlayer:WaitForChild("PlayerGui")
    self.ScreenGui = ScreenGui
end

--[[
Displays an award animation for an item
from a start position.
--]]
function ItemAwardAnimation.DisplayItemAwardFromPosition(ItemName,StartPosition)
    --Create the frame.
    local Frame = Instance.new("Frame")
    Frame.BackgroundTransparency = 1
    local Icon = ItemIcon.new()
    Icon:SetParent(Frame)
    Icon:SetItem(ItemName)

    --Play the animation and clear the icon.
    coroutine.wrap(function()
        local EndFrame = Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("BottomBarGui"):WaitForChild("BottomFrame"):WaitForChild("MenuBottomBarBackground"):WaitForChild("Inventory"):WaitForChild("TextButton")
        local Animation = ItemAwardAnimation.new(Frame,StartPosition,EndFrame,0.5)
        Animation:Play()
        Icon:Destroy()
    end)()
end

--[[
Displays an award animation for an item
from a start frame.
--]]
function ItemAwardAnimation.DisplayItemAwardFromFrame(ItemName,StartFrame)
    local StartPosition = StartFrame.AbsolutePosition + (StartFrame.AbsoluteSize/2)
    ItemAwardAnimation.DisplayItemAwardFromPosition(ItemName,UDim2.new(0,StartPosition.X,0,StartPosition.Y))
end

--[[
Displays an award animation for a bloxkin
from a start position.
--]]
function ItemAwardAnimation.DisplayBloxkinAwardFromPosition(BloxkinName,StartPosition)
    --Create the frame.
    local Frame = Instance.new("Frame")
    Frame.BackgroundTransparency = 1

    local BloxkinImage = Instance.new("ImageLabel")
    BloxkinImage.BackgroundTransparency = 1
    BloxkinImage.AnchorPoint = Vector2.new(0.5,0.5)
    BloxkinImage.Size = UDim2.new(1,0,2,0)
    BloxkinImage.Position = UDim2.new(0.5,0,0.5,0)
    BloxkinImage.Image = Bloxkins[BloxkinName].UnlockedImage
    BloxkinImage.Parent = Frame

    --Play the animation.
    coroutine.wrap(function()
        local EndFrame = Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("BottomBarGui"):WaitForChild("BottomFrame"):WaitForChild("MenuBottomBarBackground"):WaitForChild("Collectables"):WaitForChild("TextButton")
        local Animation = ItemAwardAnimation.new(Frame,StartPosition,EndFrame,0.5)
        Animation:Play()
    end)()
end

--[[
Displays an award animation for a bloxkin
from a start frame.
--]]
function ItemAwardAnimation.DisplayBloxkinAwardFromFrame(BloxkinName,StartFrame)
    local StartPosition = StartFrame.AbsolutePosition + (StartFrame.AbsoluteSize/2)
    ItemAwardAnimation.DisplayBloxkinAwardFromPosition(BloxkinName,UDim2.new(0,StartPosition.X,0,StartPosition.Y))
end

--[[
Plays the animation.
--]]
function ItemAwardAnimation:Play()
    --Finalize the frame.
    self.Frame.Size = UDim2.new(0.075,0,0.075,0)
    self.Frame.AnchorPoint = Vector2.new(0.5,0.5)
    self.Frame.SizeConstraint = Enum.SizeConstraint.RelativeYY
    self.Frame.Parent = self.ScreenGui

    --Play the tween animation.
    local StartTime = tick()
    while tick() - StartTime < self.AnimationTime do
        self:SetFramePosition((tick() - StartTime)/self.AnimationTime)
        RunService.RenderStepped:Wait()
    end
    self:SetFramePosition(1)

    --Destroy the frame and play the end animation.
    self.Frame:Destroy()
    local EndPosition = self.EndFrame.AbsolutePosition + (self.EndFrame.AbsoluteSize/2)
    local EndFrame = Instance.new("Frame")
    EndFrame.AnchorPoint = Vector2.new(0.5,0.5)
    EndFrame.BackgroundColor3 = Color3.new(1,1,1)
    EndFrame.BorderSizePixel = 0
    EndFrame.Size = UDim2.new(0,0,0,0)
    EndFrame.SizeConstraint = "RelativeYY"
    EndFrame.Position = UDim2.new(0,EndPosition.X,0,EndPosition.Y)
    EndFrame.Parent = self.ScreenGui
    
    local UICorner = Instance.new("UICorner")
    UICorner.CornerRadius = UDim.new(0.5,0)
    UICorner.Parent = EndFrame

    TweenService:Create(EndFrame,TweenInfo.new(0.25),{
        BackgroundTransparency = 1,
        Size = UDim2.new(0.1,0,0.1,0),
    }):Play()
    wait(0.25)

    --Destroy the ScreenGui.
    self.ScreenGui:Destroy()
end

--[[
Moves the frame for the current
--]]
function ItemAwardAnimation:SetFramePosition(Ratio)
    --Calculate the start and end.
    local EndPosition = self.EndFrame.AbsolutePosition + (self.EndFrame.AbsoluteSize/2)
    local StartPosition = Vector2.new((self.StartPosition.X.Scale * self.ScreenGui.AbsoluteSize.X) + self.StartPosition.X.Offset,(self.StartPosition.Y.Scale * self.ScreenGui.AbsoluteSize.Y) + self.StartPosition.Y.Offset)
    local DeltaPosition = EndPosition - StartPosition
    local Time = self.AnimationTime * Ratio

    --Calculate the arc.
    --Remember that Y is positive in the down direction.
    local TargetHeight = math.min(EndPosition.Y,StartPosition.Y) - (self.ScreenGui.AbsoluteSize.Y * ADDITIONAL_HEIGHT_MULTIPLIER)
    local HeightRelativeToStart = TargetHeight - StartPosition.Y
    local ThrowAngle = math.atan2(HeightRelativeToStart,DeltaPosition.X/2)
    local ThrowVelocityX = DeltaPosition.X/self.AnimationTime
    local ThrowVelocity = ThrowVelocityX/math.cos(ThrowAngle)
    local ThrowVelocityY = math.sin(ThrowAngle) * ThrowVelocity
    local Acceleration = (2 * (DeltaPosition.Y - (ThrowVelocityY * self.AnimationTime))) / (self.AnimationTime ^ 2)
    local StepHeight = (ThrowVelocityY * Time) + (0.5 * Acceleration * (Time ^ 2))

    --Move the frame.
    self.Frame.Position = UDim2.new(0,StartPosition.X + (DeltaPosition.X * Ratio),0,StartPosition.Y + StepHeight)
end



return ItemAwardAnimation