From f2288ecf7166f42c7a0a72e2af300a16bdbada0d Mon Sep 17 00:00:00 2001 From: domdoc Date: Sun, 15 May 2022 11:07:07 +0200 Subject: [PATCH] Added laser HitFX --- scripts/gameplay.lua | 3 +- scripts/gameplay/hitfx.lua | 122 +++++++++++++++++++++++++++++++++---- 2 files changed, 113 insertions(+), 12 deletions(-) diff --git a/scripts/gameplay.lua b/scripts/gameplay.lua index 4e1ed12..d152053 100644 --- a/scripts/gameplay.lua +++ b/scripts/gameplay.lua @@ -65,12 +65,13 @@ function render(deltaTime) end function render_crit_base(deltaTime) + HitFX.renderLasers(deltaTime, gameplay.critLine.x, gameplay.critLine.y, -gameplay.critLine.rotation, gameplay.critLine.cursors); CritLine.renderBase(deltaTime, gameplay.critLine.x, gameplay.critLine.y, -gameplay.critLine.rotation, gameplay.critLine.cursors); Console.render(deltaTime, gameplay.critLine.x, gameplay.critLine.y, -gameplay.critLine.rotation); end function render_crit_overlay(deltaTime) - HitFX.render(deltaTime, gameplay.critLine.x, gameplay.critLine.y, -gameplay.critLine.rotation, gameplay.critLine.cursors); + HitFX.renderButtons(deltaTime, gameplay.critLine.x, gameplay.critLine.y, -gameplay.critLine.rotation); end function render_intro(deltaTime) diff --git a/scripts/gameplay/hitfx.lua b/scripts/gameplay/hitfx.lua index 5a4cc5e..a96a7ef 100644 --- a/scripts/gameplay/hitfx.lua +++ b/scripts/gameplay/hitfx.lua @@ -33,8 +33,44 @@ local Animations = { centered = true, loop = true, }), + + 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', {}), }; +---@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() + } +} + ---@class HoldStateTable ---@field Crit AnimationState ---@field Dome AnimationState @@ -58,16 +94,77 @@ local tapStates = {} local HitFX = { }; -local function setupLaneTransform(lanePosition, critCenterX, critCenterY) - local critLine = gameplay.critLine; - local x = critCenterX + (critLine.line.x2 - critLine.line.x1) * lanePosition; - local y = critCenterY + (critLine.line.y2 - critLine.line.y1) * lanePosition; - Dimensions.setUpTransforms(x, y, -critLine.rotation); +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.render(deltaTime, critCenterX, critCenterY, critRotation, cursors) +function HitFX.renderLasers(deltaTime, critCenterX, critCenterY, critRotation, cursors) + local baseHitSize = 325 * 1.25; + + -- 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 + local laserColor = {game.GetLaserColor(laser - 1)} + local x = cursors[laser - 1].pos + + Dimensions.setUpTransforms(critCenterX, critCenterY, critRotation) + + laserState.Dome:render(deltaTime, { + centered = true, + width = baseHitSize, + height = baseHitSize, + color = laserColor, + x = x, + }) + + laserState.Crit:render(deltaTime, { + centered = true, + width = baseHitSize, + height = baseHitSize, + x = x, + }) + laserState.EndInner:render(deltaTime, { + centered = true, + width = baseHitSize, + height = baseHitSize, + x = x, + }) + laserState.EndOuter:render(deltaTime, { + centered = true, + width = baseHitSize, + height = baseHitSize, + color = laserColor, + x = x, + }) + end +end + +function HitFX.renderButtons(deltaTime, critCenterX, critCenterY, critRotation) local baseHitSize = 325; + -- BT + FX for i = 1, 6 do local hitSize = baseHitSize; if (i > 4) then @@ -80,7 +177,7 @@ function HitFX.render(deltaTime, critCenterX, critCenterY, critRotation, cursors lanePosition = -track.GetCurrentLaneXPos(6) - laneWidth / 2 end - -- Holds + -- Update Holds local isHeld = gameplay.noteHeld[i] local holdStates = holdStateTables[i] local isAnimationPlaying = holdStates.Dome.running @@ -95,11 +192,13 @@ function HitFX.render(deltaTime, critCenterX, critCenterY, critRotation, cursors holdStates.Crit:stop() holdStates.Dome:stop() holdStates.Inner:stop() - + holdStates.End:restart() end - setupLaneTransform(lanePosition, critCenterX, critCenterY) + -- Render holds + setUpTransform(critCenterX, critCenterY, critRotation, lanePosition) + holdStates.Inner:render(deltaTime, { centered = true, width = hitSize, @@ -121,7 +220,7 @@ function HitFX.render(deltaTime, critCenterX, critCenterY, critRotation, cursors height = hitSize }) - -- Taps + -- Render Taps local tapState = tapStates[i] if tapState then @@ -131,8 +230,9 @@ function HitFX.render(deltaTime, critCenterX, critCenterY, critRotation, cursors height = hitSize, }); end - gfx.ResetTransform() end + + gfx.ResetTransform() end function HitFX.TriggerAnimation(name, lane)