Hey,
This may be a bit advanced for my skills but, if any of you are part of the good old Sassilization community you'd have seen the coin animation when you bought an items or gave some dough, it was so sophisticated I loved it!
for those who have no clue [url]https://www.youtube.com/watch?v=5sVRY4DCX5M[/url] At arround 0:21 you'll see it
I was just wondering how you'd go about creating that, if anyone could point me in the right direction it would be great, thanks guys!<3
If I had to guess the quick and dirty way they could have done it would be a gif that is overlayed on top of the screen. Besides that I suppose you individually create each coin and then just give it a random arc to follow until it hits the bottom of the screen (I'm not entirely convinced that this is efficient at all).
The code is open source. It's done by simulating gravity on textures. Quite simple to reproduce; I am sure you can find a copy on facepunch.
This is the code for it:
[lua]
MONEY = {}
MONEY.coins = {}
MONEY.coinage = surface.GetTextureID( "sassilization/coinage" )
MONEY.cps = 6 --Coins per Second
MONEY.timeleft = CurTime()
MONEY.tex = surface.GetTextureID("coded/dbox")
MONEY.w = 128
MONEY.h = 64
MONEY.velx = 0
MONEY.vely = 0
MONEY.x = 0-MONEY.w
MONEY.y = ScrH()-MONEY.h*1.5
local HUDCoin_b = 0
local HUDCoin_c = 0
local HUDCoin_d = 0
local HUDCoin_i = 1
local HUDCoins = {}
local tink = 0
local function PlayTink()
tink = tink + 1
if tink > 4 then tink = 0 end
surface.PlaySound( "sassilization/ting"..(tink > 0 and tink or "")..".wav" )
end
function GM:AddCoin()
local coin = {}
coin.recv = SysTime()
coin.income = true
coin.velx = math.random( -5, -2 )*0.01
coin.vely = 0
coin.x = ScrW() + 200
coin.y = ScrH() - (MONEY.h * 1.5) + MONEY.h * 0.5 + math.random( -64, 64 ) - 16
local diff = LocalPlayer():GetMoney() - MONEY.amount + HUDCoin_b
coin.value = diff > 100 and math.min( math.Round( math.sqrt( diff ) * 0.5 ), diff ) or math.min( 1, diff )
HUDCoin_b = HUDCoin_b + coin.value
table.insert( HUDCoins, coin )
HUDCoin_c = HUDCoin_c + 1
HUDCoin_i = HUDCoin_i + 1
end
function GM:RemoveCoin()
local coin = {}
coin.recv = SysTime()
coin.outcome = true
coin.velx = math.random( -75, 75 )
coin.vely = math.random( 50, 100 ) - 500
coin.x = MONEY.x + MONEY.w * 0.5 - 16
coin.y = MONEY.y + MONEY.h * 0.1
PlayTink()
local diff = MONEY.amount - LocalPlayer():GetMoney()
MONEY.amount = MONEY.amount - math.min( math.Round( math.sqrt( diff ) * 0.5 ), diff + HUDCoin_b )
table.insert( HUDCoins, coin )
HUDCoin_d = HUDCoin_d + 1
HUDCoin_i = HUDCoin_i + 1
end
local function DrawCoin( self, k, v, i )
local x = v.x
local y = v.y
v.w = v.w or math.random( 24, 32 )
local w,h = v.w, v.w
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetTexture( MONEY.coinage )
surface.DrawTexturedRect( x, y, w, h )
local spd = RealFrameTime()
v.y = v.y + v.vely * spd
v.x = v.x + v.velx * spd
if v.income then
local ideal_y = ScrH() - MONEY.h * 1.5 + h * 0.5
local ideal_x = -v.w
ideal_x = -v.w
local dist = ideal_y - v.y
v.vely = v.vely + dist * spd * 1
if (math.abs(dist) < 2 && math.abs(v.vely) < 0.1) then v.vely = 0 end
local dist = ideal_x - v.x
v.velx = v.velx + dist * spd * 1
if (math.abs(dist) < 2 && math.abs(v.velx) < 0.1) then v.velx = 0 end
elseif v.outcome then
v.vely = v.vely + spd * 500
end
end
function GM:PaintCoins()
if !MONEY.amount then return end
local pl = LocalPlayer()
if( !IsValid(pl) ) then return end
local profile = pl.profile
if( !profile ) then return end
local ft = FrameTime()
if (MONEY.amount + HUDCoin_b) < profile:GetMoney() then
for i=1, math.min( 1, math.Round( MONEY.cps * ft * 64 ) ) do
if (pl:GetMoney() - MONEY.amount + HUDCoin_b) > 0 then
self:AddCoin()
else break end
end
elseif MONEY.amount > pl:GetMoney() then
if MONEY.x > MONEY.w*-0.5 then
for i=1, math.min( 1, math.Round( MONEY.cps * ft * 64 ) ) do
if (MONEY.amount - pl:GetMoney()) > 0 then
self:RemoveCoin()
else break end
end
else
MONEY.timeleft = CurTime() + 2
end
end
if ( !HUDCoins ) then return end
local i = 0
for k, v in pairs( HUDCoins ) do
if ( v != 0 ) then
i = i + 1
DrawCoin( self, k, v, i)
end
end
for k, v in pairs( HUDCoins ) do
if ( v != 0 && (v.x < -v.w || v.y > ScrH() + v.w) ) then
if v.income then
PlayTink()
local value = pl:GetMoney() - MONEY.amount
value = math.min( v.value, value )
MONEY.amount = MONEY.amount + value
HUDCoin_b = HUDCoin_b - value
HUDCoin_c = HUDCoin_c - 1
elseif v.outcome then
HUDCoin_d = HUDCoin_d - 1
end
HUDCoins[ k ] = 0
if (HUDCoin_c == 0 and HUDCoin_d == 0) then HUDCoins = {} HUDCoin_b = 0 end
end
end
end
function GM:DoughPaint()
if !(IsValid( LocalPlayer() )) then return end
local v = MONEY
if HUDCoin_c > 0 || HUDCoin_d > 0 then
v.timeleft = CurTime() + 2
end
local x = v.x
local y = v.y
local w = v.w
local h = v.h
surface.SetDrawColor( 255, 255, 255, 120 )
surface.SetTexture( v.tex )
surface.DrawTexturedRect( x, y, w, h )
if v.amount then
draw.DrawText( math.Round(v.amount), "default", x+w*0.8+1, y+h*0.5+1, Color(0,0,0,255),2)
draw.DrawText( math.Round(v.amount), "default", x+w*0.8, y+h*0.5, Color(255,255,255,255),2)
end
local ideal_y = ScrH()-v.h*1.5
local ideal_x = -v.w
local timeleft = v.timeleft - CurTime()
if timeleft <= 0 then
ideal_x = -v.w
else
ideal_x = 0
end
local spd = FrameTime() * 8
v.y = v.y + v.vely * spd
v.x = v.x + v.velx * spd
local dist = ideal_y - v.y
v.vely = v.vely + dist * spd * 1
if (math.abs(dist) < 2 && math.abs(v.vely) < 0.1) then v.vely = 0 end
local dist = ideal_x - v.x
v.velx = v.velx + dist * spd * 1
if (math.abs(dist) < 2 && math.abs(v.velx) < 0.1) then v.velx = 0 end
v.velx = v.velx * (0.95 - RealFrameTime() * 5 )
v.vely = v.vely * (0.95 - RealFrameTime() * 5 )
if v.x > 0 then
v.x = 0
v.velx = 0
end
end
[/lua]
[QUOTE=ChewGum;48463294]This is the code for it:
[lua]
MONEY = {}
MONEY.coins = {}
MONEY.coinage = surface.GetTextureID( "sassilization/coinage" )
MONEY.cps = 6 --Coins per Second
MONEY.timeleft = CurTime()
MONEY.tex = surface.GetTextureID("coded/dbox")
MONEY.w = 128
MONEY.h = 64
MONEY.velx = 0
MONEY.vely = 0
MONEY.x = 0-MONEY.w
MONEY.y = ScrH()-MONEY.h*1.5
local HUDCoin_b = 0
local HUDCoin_c = 0
local HUDCoin_d = 0
local HUDCoin_i = 1
local HUDCoins = {}
local tink = 0
local function PlayTink()
tink = tink + 1
if tink > 4 then tink = 0 end
surface.PlaySound( "sassilization/ting"..(tink > 0 and tink or "")..".wav" )
end
function GM:AddCoin()
local coin = {}
coin.recv = SysTime()
coin.income = true
coin.velx = math.random( -5, -2 )*0.01
coin.vely = 0
coin.x = ScrW() + 200
coin.y = ScrH() - (MONEY.h * 1.5) + MONEY.h * 0.5 + math.random( -64, 64 ) - 16
local diff = LocalPlayer():GetMoney() - MONEY.amount + HUDCoin_b
coin.value = diff > 100 and math.min( math.Round( math.sqrt( diff ) * 0.5 ), diff ) or math.min( 1, diff )
HUDCoin_b = HUDCoin_b + coin.value
table.insert( HUDCoins, coin )
HUDCoin_c = HUDCoin_c + 1
HUDCoin_i = HUDCoin_i + 1
end
function GM:RemoveCoin()
local coin = {}
coin.recv = SysTime()
coin.outcome = true
coin.velx = math.random( -75, 75 )
coin.vely = math.random( 50, 100 ) - 500
coin.x = MONEY.x + MONEY.w * 0.5 - 16
coin.y = MONEY.y + MONEY.h * 0.1
PlayTink()
local diff = MONEY.amount - LocalPlayer():GetMoney()
MONEY.amount = MONEY.amount - math.min( math.Round( math.sqrt( diff ) * 0.5 ), diff + HUDCoin_b )
table.insert( HUDCoins, coin )
HUDCoin_d = HUDCoin_d + 1
HUDCoin_i = HUDCoin_i + 1
end
local function DrawCoin( self, k, v, i )
local x = v.x
local y = v.y
v.w = v.w or math.random( 24, 32 )
local w,h = v.w, v.w
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetTexture( MONEY.coinage )
surface.DrawTexturedRect( x, y, w, h )
local spd = RealFrameTime()
v.y = v.y + v.vely * spd
v.x = v.x + v.velx * spd
if v.income then
local ideal_y = ScrH() - MONEY.h * 1.5 + h * 0.5
local ideal_x = -v.w
ideal_x = -v.w
local dist = ideal_y - v.y
v.vely = v.vely + dist * spd * 1
if (math.abs(dist) < 2 && math.abs(v.vely) < 0.1) then v.vely = 0 end
local dist = ideal_x - v.x
v.velx = v.velx + dist * spd * 1
if (math.abs(dist) < 2 && math.abs(v.velx) < 0.1) then v.velx = 0 end
elseif v.outcome then
v.vely = v.vely + spd * 500
end
end
function GM:PaintCoins()
if !MONEY.amount then return end
local pl = LocalPlayer()
if( !IsValid(pl) ) then return end
local profile = pl.profile
if( !profile ) then return end
local ft = FrameTime()
if (MONEY.amount + HUDCoin_b) < profile:GetMoney() then
for i=1, math.min( 1, math.Round( MONEY.cps * ft * 64 ) ) do
if (pl:GetMoney() - MONEY.amount + HUDCoin_b) > 0 then
self:AddCoin()
else break end
end
elseif MONEY.amount > pl:GetMoney() then
if MONEY.x > MONEY.w*-0.5 then
for i=1, math.min( 1, math.Round( MONEY.cps * ft * 64 ) ) do
if (MONEY.amount - pl:GetMoney()) > 0 then
self:RemoveCoin()
else break end
end
else
MONEY.timeleft = CurTime() + 2
end
end
if ( !HUDCoins ) then return end
local i = 0
for k, v in pairs( HUDCoins ) do
if ( v != 0 ) then
i = i + 1
DrawCoin( self, k, v, i)
end
end
for k, v in pairs( HUDCoins ) do
if ( v != 0 && (v.x < -v.w || v.y > ScrH() + v.w) ) then
if v.income then
PlayTink()
local value = pl:GetMoney() - MONEY.amount
value = math.min( v.value, value )
MONEY.amount = MONEY.amount + value
HUDCoin_b = HUDCoin_b - value
HUDCoin_c = HUDCoin_c - 1
elseif v.outcome then
HUDCoin_d = HUDCoin_d - 1
end
HUDCoins[ k ] = 0
if (HUDCoin_c == 0 and HUDCoin_d == 0) then HUDCoins = {} HUDCoin_b = 0 end
end
end
end
function GM:DoughPaint()
if !(IsValid( LocalPlayer() )) then return end
local v = MONEY
if HUDCoin_c > 0 || HUDCoin_d > 0 then
v.timeleft = CurTime() + 2
end
local x = v.x
local y = v.y
local w = v.w
local h = v.h
surface.SetDrawColor( 255, 255, 255, 120 )
surface.SetTexture( v.tex )
surface.DrawTexturedRect( x, y, w, h )
if v.amount then
draw.DrawText( math.Round(v.amount), "default", x+w*0.8+1, y+h*0.5+1, Color(0,0,0,255),2)
draw.DrawText( math.Round(v.amount), "default", x+w*0.8, y+h*0.5, Color(255,255,255,255),2)
end
local ideal_y = ScrH()-v.h*1.5
local ideal_x = -v.w
local timeleft = v.timeleft - CurTime()
if timeleft <= 0 then
ideal_x = -v.w
else
ideal_x = 0
end
local spd = FrameTime() * 8
v.y = v.y + v.vely * spd
v.x = v.x + v.velx * spd
local dist = ideal_y - v.y
v.vely = v.vely + dist * spd * 1
if (math.abs(dist) < 2 && math.abs(v.vely) < 0.1) then v.vely = 0 end
local dist = ideal_x - v.x
v.velx = v.velx + dist * spd * 1
if (math.abs(dist) < 2 && math.abs(v.velx) < 0.1) then v.velx = 0 end
v.velx = v.velx * (0.95 - RealFrameTime() * 5 )
v.vely = v.vely * (0.95 - RealFrameTime() * 5 )
if v.x > 0 then
v.x = 0
v.velx = 0
end
end
[/lua][/QUOTE]
Firstly, thanks <3 and secondly
If you don't mind me asking, how do you find this? cheers!
They released all their gamemodes here: [url]http://facepunch.com/showthread.php?t=1280533[/url]
[QUOTE=Pawsative;48486555]They released all their gamemodes here: [url]http://facepunch.com/showthread.php?t=1280533[/url][/QUOTE]
Yeah but it didn't include any lua files like the one Chewgum provided
[QUOTE=UnknownSir;48488904]Yeah but it didn't include any lua files like the one Chewgum provided[/QUOTE]
Hmmm yes it does. It the largest file (other than loading store items) the client has.
Sorry, you need to Log In to post a reply to this thread.