ExperimentalGear/scripts/gameplay/chain.lua

102 lines
2.7 KiB
Lua
Raw Normal View History

2021-09-05 11:50:30 +02:00
local chainLabel = gfx.CreateSkinImage("gameplay/chain/label.png", 0)
2021-09-05 11:50:30 +02:00
local desw = 1080;
local desh = 1920;
local transitionShakeScale = 0;
local transitionShakePosOffset = 0;
local shakeTimer = 0;
2021-09-05 11:50:30 +02:00
function load_number_image(path)
local images = {}
for i = 0, 9 do
images[i + 1] = gfx.CreateSkinImage(string.format("%s/%d.png", path, i), 0)
end
return images
end
local chainNumbersReg = load_number_image('gameplay/chain/reg')
local chainNumbersUC = load_number_image('gameplay/chain/uc')
local chainNumbersPUC = load_number_image('gameplay/chain/puc')
2021-09-05 11:50:30 +02:00
function draw_number(x, y, alpha, num, digits, images, is_dim, scale, kern)
scale = scale or 1;
kern = kern or 1;
local tw, th = gfx.ImageSize(images[1])
tw = tw * scale;
th = th * scale;
x = x + (tw * (digits - 1)) / 2
y = y - th / 2
for i = 1, digits do
local mul = 10 ^ (i - 1)
local digit = math.floor(num / mul) % 10
local a = alpha
if is_dim and num < mul then
a = 0.4
end
gfx.BeginPath()
gfx.ImageRect(x, y, tw, th, images[digit + 1], a, 0)
x = x - (tw * kern)
end
end
local tickTransitions = function (deltaTime)
if transitionShakeScale < 1 then
transitionShakeScale = transitionShakeScale + deltaTime / 0.075 -- transition should last for that time in seconds
else
transitionShakeScale = 0
end
2021-10-28 17:51:27 +02:00
if (transitionShakeScale < 1/3) then
2021-09-05 11:50:30 +02:00
transitionShakePosOffset = 0;
2021-10-28 17:51:27 +02:00
elseif (transitionShakeScale > 2/3) then
2021-09-05 11:50:30 +02:00
transitionShakePosOffset = -1;
else
transitionShakePosOffset = 1;
end
end
local onNewCombo = function ()
shakeTimer = 0.25;
end
local render = function (deltaTime, comboState, combo, critLineCenterX, critLineCenterY)
2021-09-05 11:50:30 +02:00
tickTransitions(deltaTime)
if shakeTimer > 0 then
shakeTimer = shakeTimer - deltaTime;
else
transitionShakePosOffset = 0;
end
2021-09-05 11:50:30 +02:00
if combo == 0 then return end
local posx = desw / 2 + transitionShakePosOffset;
local posy = desh - 640 + transitionShakePosOffset;
2021-09-05 11:50:30 +02:00
local chainNumbers = chainNumbersReg --regular
if comboState == 2 then
chainNumbers = chainNumbersPUC --puc
elseif comboState == 1 then
chainNumbers = chainNumbersUC --uc
end
2021-09-05 11:50:30 +02:00
-- \_ chain _/
local tw, th
tw, th = gfx.ImageSize(chainLabel)
gfx.BeginPath()
gfx.ImageRect(posx - tw * 0.85 / 2, posy - 220, tw * 0.85, th * 0.85, chainLabel, 1, 0)
2021-09-05 11:50:30 +02:00
tw, th = gfx.ImageSize(chainNumbers[1])
posy = posy - th + 32
local comboScale = 0.45;
draw_number(posx - (tw*4*comboScale)/2+(tw*comboScale*1.5)+10, posy - th / 2, 1.0, combo, 4, chainNumbers, true, comboScale, 1.12)
end
return {
onNewCombo=onNewCombo,
2021-09-05 11:50:30 +02:00
render=render
}