ExperimentalGear/scripts/gameplay/hitfx.lua

246 lines
6.6 KiB
Lua
Raw Permalink Normal View History

2022-04-27 00:12:14 +02:00
require 'common.globals'
local Dimensions = require 'common.dimensions'
2022-04-27 00:12:14 +02:00
local Animation = require 'api.animation'
local Animations = {
Crit = Animation.new('gameplay/hit_animation_frames/critical_taps', {
centered = true,
}),
Near = Animation.new('gameplay/hit_animation_frames/near_taps', {
centered = true,
}),
2022-05-14 19:35:35 +02:00
HoldCrit = Animation.new('gameplay/hit_animation_frames/hold_critical', {
centered = true,
loop = true,
}),
2022-04-27 00:12:14 +02:00
2022-05-14 19:35:35 +02:00
HoldDome = Animation.new('gameplay/hit_animation_frames/hold_dome', {
centered = true,
loop = true,
loopPoint = 10
}),
2022-04-27 00:12:14 +02:00
2022-05-14 19:35:35 +02:00
HoldEnd = Animation.new('gameplay/hit_animation_frames/hold_end', {
centered = true,
}),
HoldInner = Animation.new('gameplay/hit_animation_frames/hold_inner', {
centered = true,
loop = true,
}),
2022-05-15 11:07:07 +02:00
LaserCrit = Animation.new('gameplay/hit_animation_frames/laser_critical', {
loop = true,
}),
LaserDome = Animation.new('gameplay/hit_animation_frames/laser_dome', {
loop = true,
}),
LaserEndOuter = Animation.new('gameplay/hit_animation_frames/laser_end_outer', {}),
LaserEndLeft = Animation.new('gameplay/hit_animation_frames/laser_end_l_inner', {}),
LaserEndRight = Animation.new('gameplay/hit_animation_frames/laser_end_r_inner', {}),
2022-04-27 00:12:14 +02:00
};
2022-05-15 11:07:07 +02:00
---@class LaserStateTable
---@field Crit AnimationState
---@field Dome AnimationState
---@field EndInner AnimationState
---@field EndOuter AnimationState
---@type LaserStateTable[]
local laserStateTables = {
{
Crit = Animations.LaserCrit:createState(),
Dome = Animations.LaserDome:createState(),
EndInner = Animations.LaserEndLeft:createState(),
EndOuter = Animations.LaserEndOuter:createState()
},
{
Crit = Animations.LaserCrit:createState(),
Dome = Animations.LaserDome:createState(),
EndInner = Animations.LaserEndRight:createState(),
EndOuter = Animations.LaserEndOuter:createState()
}
}
2022-05-14 19:35:35 +02:00
---@class HoldStateTable
---@field Crit AnimationState
---@field Dome AnimationState
---@field End AnimationState
---@field Inner AnimationState
---@type HoldStateTable[]
local holdStateTables = {}
for i = 1, 6 do
holdStateTables[i] = {
Crit = Animations.HoldCrit:createState(),
Dome = Animations.HoldDome:createState(),
End = Animations.HoldEnd:createState(),
Inner = Animations.HoldInner:createState()
}
end
---@type AnimationState[]
local tapStates = {}
local HitFX = { };
2022-05-15 11:07:07 +02:00
local function setUpTransform(critCenterX, critCenterY, critRotation, xScalar)
local critLine = gameplay.critLine
local x = critCenterX + (critLine.line.x2 - critLine.line.x1) * xScalar
local y = critCenterY + (critLine.line.y2 - critLine.line.y1) * xScalar
Dimensions.setUpTransforms(x, y, critRotation)
end
function HitFX.renderLasers(deltaTime, critCenterX, critCenterY, critRotation, cursors)
2022-05-16 10:44:36 +02:00
local hitSize = 406
2022-05-15 11:07:07 +02:00
-- Lasers
for laser = 1, 2 do
-- Update
local isActive = gameplay.laserActive[laser]
local laserState = laserStateTables[laser]
local isAnimationPlaying = laserState.Dome.running
if isActive and not isAnimationPlaying then
laserState.Crit:restart()
laserState.Dome:restart()
end
if not isActive and isAnimationPlaying then
laserState.Crit:stop()
laserState.Dome:stop()
laserState.EndInner:restart()
laserState.EndOuter:restart()
end
-- Render
2022-05-31 21:30:52 +02:00
scale, _ = Dimensions.setUpTransforms(critCenterX, critCenterY, critRotation)
2022-05-15 11:07:07 +02:00
2022-05-31 21:30:52 +02:00
local laserColor = {game.GetLaserColor(laser - 1)}
local x = cursors[laser - 1].pos * (1 / scale)
2022-05-15 11:07:07 +02:00
laserState.Dome:render(deltaTime, {
centered = true,
2022-05-16 10:44:36 +02:00
width = hitSize,
height = hitSize,
2022-05-15 11:07:07 +02:00
color = laserColor,
x = x,
})
laserState.Crit:render(deltaTime, {
centered = true,
2022-05-16 10:44:36 +02:00
width = hitSize,
height = hitSize,
2022-05-15 11:07:07 +02:00
x = x,
})
laserState.EndInner:render(deltaTime, {
centered = true,
2022-05-16 10:44:36 +02:00
width = hitSize,
height = hitSize,
2022-05-15 11:07:07 +02:00
x = x,
})
laserState.EndOuter:render(deltaTime, {
centered = true,
2022-05-16 10:44:36 +02:00
width = hitSize,
height = hitSize,
2022-05-15 11:07:07 +02:00
color = laserColor,
x = x,
})
end
2022-04-27 00:12:14 +02:00
end
2022-05-15 11:07:07 +02:00
function HitFX.renderButtons(deltaTime, critCenterX, critCenterY, critRotation)
2022-05-16 10:44:36 +02:00
--local baseHitSize = 325;
local hitSize = 406
2022-04-27 00:12:14 +02:00
2022-05-15 11:07:07 +02:00
-- BT + FX
2022-04-27 00:12:14 +02:00
for i = 1, 6 do
2022-05-16 10:44:36 +02:00
--[[
2022-04-27 00:12:14 +02:00
local hitSize = baseHitSize;
if (i > 4) then
hitSize = hitSize * 1.5;
end
2022-05-16 10:44:36 +02:00
]]
2022-04-27 00:12:14 +02:00
local laneWidth = (track.GetCurrentLaneXPos(2) - track.GetCurrentLaneXPos(1)) * (i <= 4 and 1 or 2);
local lanePosition = track.GetCurrentLaneXPos(i) + laneWidth / 2
if (i == 5) then
lanePosition = -track.GetCurrentLaneXPos(6) - laneWidth / 2
end
2022-05-15 11:07:07 +02:00
-- Update Holds
2022-05-14 19:35:35 +02:00
local isHeld = gameplay.noteHeld[i]
local holdStates = holdStateTables[i]
local isAnimationPlaying = holdStates.Dome.running
if isHeld and not isAnimationPlaying then
holdStates.Crit:restart()
holdStates.Dome:restart()
holdStates.Inner:restart()
end
if not isHeld and isAnimationPlaying then
holdStates.Crit:stop()
holdStates.Dome:stop()
holdStates.Inner:stop()
2022-05-15 11:07:07 +02:00
2022-05-14 19:35:35 +02:00
holdStates.End:restart()
end
2022-05-15 11:07:07 +02:00
-- Render holds
setUpTransform(critCenterX, critCenterY, critRotation, lanePosition)
2022-05-14 19:35:35 +02:00
holdStates.Inner:render(deltaTime, {
centered = true,
width = hitSize,
height = hitSize
})
holdStates.Dome:render(deltaTime, {
centered = true,
width = hitSize,
height = hitSize
})
holdStates.Crit:render(deltaTime, {
centered = true,
width = hitSize,
height = hitSize
})
holdStates.End:render(deltaTime, {
centered = true,
width = hitSize,
height = hitSize
})
2022-05-15 11:07:07 +02:00
-- Render Taps
2022-05-14 19:35:35 +02:00
local tapState = tapStates[i]
if tapState then
tapState:render(deltaTime, {
centered = true,
width = hitSize,
height = hitSize,
});
2022-04-27 00:12:14 +02:00
end
end
2022-05-15 11:07:07 +02:00
gfx.ResetTransform()
2022-04-27 00:12:14 +02:00
end
function HitFX.TriggerAnimation(name, lane)
2022-05-14 19:35:35 +02:00
tapStates[lane] = Animations[name]:start();
2022-04-27 00:12:14 +02:00
end
return HitFX;