rsi/utils.lua

18 lines
1.0 KiB
Lua
Raw Normal View History

2023-08-27 12:32:38 +00:00
utils={}
function utils.accuracy(beatDivisions, time)
local ticksToPrevDiv=(game.ticker.ticks-1)%beatDivisions
local ticksToNextDiv=beatDivisions-ticksToPrevDiv
local prevDivTime=game.ticker.lastTickTime-ticksToPrevDiv*game.ticker.tickTime
local nextDivTime=game.ticker.lastTickTime+ticksToNextDiv*game.ticker.tickTime
local closest=math.min(math.abs(time-prevDivTime), math.abs(time-nextDivTime))
local halfDivision=beatDivisions/2*game.ticker.tickTime
-- print(math.abs(time-nextDivTime),"to next beat, ",math.abs(time-prevDivTime)," to previous beat. Half division is ",halfDivision,". Closest is ",closest,". The current time is ",time,", and the next division is at ", nextDivTime,", last tick happened at ",game.ticker.lastTickTime," and is tick number ",game.ticker.ticks)
return (halfDivision-closest)/halfDivision -- Math is hard
2023-08-27 23:00:22 +00:00
end
local volumeScale=0.0029
function utils.setSourcePosition(source, x, y)
source:setPosition(x,8,0)
source:setVolume(volumeScale*game.field.height-volumeScale*math.abs(player.y-y))
2023-08-27 12:32:38 +00:00
end