+ make the laser alerts work

This commit is contained in:
FajsiEx 2021-10-02 00:17:24 +02:00
parent 7ca8ffd561
commit 2f575c022e
2 changed files with 92 additions and 7 deletions

View File

@ -75,7 +75,7 @@ function laser_slam_hit(slamLength, startPos, endPost, index)
end end
function laser_alert(isRight) function laser_alert(isRight)
LaserAlert.show(isRight)
end end
function practice_start(mission_type, mission_threshold, mission_description) function practice_start(mission_type, mission_threshold, mission_description)

View File

@ -7,6 +7,9 @@ local rightAlertBaseImage = gfx.CreateSkinImage("gameplay/laser_alert/right/base
local rightAlertTopImage = gfx.CreateSkinImage("gameplay/laser_alert/right/top.png", 0) local rightAlertTopImage = gfx.CreateSkinImage("gameplay/laser_alert/right/top.png", 0)
local rightAlertTextImage = gfx.CreateSkinImage("gameplay/laser_alert/right/text.png", 0) local rightAlertTextImage = gfx.CreateSkinImage("gameplay/laser_alert/right/text.png", 0)
local TRANSITION_ALERT_ENTER_THRESHOLD = 0.075;
local TRANSITION_ALERT_LEAVE_THRESHOLD = 0.925;
local LEFT_ALERT_X_POS = 0 local LEFT_ALERT_X_POS = 0
local RIGHT_ALERT_X_POS = 1080 - 450*0.5 local RIGHT_ALERT_X_POS = 1080 - 450*0.5
@ -14,6 +17,14 @@ local ALERT_Y_POS = 1115
local test = -2*3.14; local test = -2*3.14;
local transitionLeftScale = 1;
local transitionLeftOffsetX = 0;
local transitionLeftOpacity = 0;
local transitionRightScale = 1;
local transitionRightOffsetX = 0;
local transitionRightOpacity = 0;
local renderLeftAlert = function () local renderLeftAlert = function ()
-- gfx.Translate(LEFT_ALERT_X_POS, ALERT_Y_POS); -- gfx.Translate(LEFT_ALERT_X_POS, ALERT_Y_POS);
-- -- gfx.SkewX(-1*3.14) -- -- gfx.SkewX(-1*3.14)
@ -21,7 +32,7 @@ local renderLeftAlert = function ()
gfx.BeginPath(); gfx.BeginPath();
gfx.ImageRect( gfx.ImageRect(
LEFT_ALERT_X_POS+450*0.5, (LEFT_ALERT_X_POS+450*0.5) + transitionLeftOffsetX,
ALERT_Y_POS+450*0.5, ALERT_Y_POS+450*0.5,
450*0.5, 450*0.5,
450*0.5, 450*0.5,
@ -32,7 +43,7 @@ local renderLeftAlert = function ()
gfx.BeginPath(); gfx.BeginPath();
gfx.ImageRect( gfx.ImageRect(
LEFT_ALERT_X_POS+450*0.5, (LEFT_ALERT_X_POS+450*0.5) + transitionLeftOffsetX,
ALERT_Y_POS+450*0.5, ALERT_Y_POS+450*0.5,
450*0.5, 450*0.5,
450*0.5, 450*0.5,
@ -48,7 +59,7 @@ local renderLeftAlert = function ()
450*0.5, 450*0.5,
450*0.5, 450*0.5,
leftAlertTextImage, leftAlertTextImage,
1, transitionLeftOpacity,
0 0
); );
@ -57,7 +68,7 @@ end
local renderRightAlert = function () local renderRightAlert = function ()
gfx.BeginPath(); gfx.BeginPath();
gfx.ImageRect( gfx.ImageRect(
RIGHT_ALERT_X_POS, RIGHT_ALERT_X_POS + transitionRightOffsetX,
ALERT_Y_POS, ALERT_Y_POS,
450*0.5, 450*0.5,
450*0.5, 450*0.5,
@ -68,7 +79,7 @@ local renderRightAlert = function ()
gfx.BeginPath(); gfx.BeginPath();
gfx.ImageRect( gfx.ImageRect(
RIGHT_ALERT_X_POS, RIGHT_ALERT_X_POS + transitionRightOffsetX,
ALERT_Y_POS, ALERT_Y_POS,
450*0.5, 450*0.5,
450*0.5, 450*0.5,
@ -84,17 +95,91 @@ local renderRightAlert = function ()
450*0.5, 450*0.5,
450*0.5, 450*0.5,
rightAlertTextImage, rightAlertTextImage,
1, transitionRightOpacity,
0 0
); );
end end
local showLaserAlert = function(isRight)
if (isRight) then
if (transitionRightScale < 1) then
transitionRightScale = TRANSITION_ALERT_ENTER_THRESHOLD -- If the laser alert is already in progress, just reset its duration
else
transitionRightScale = 0;
end
else
if (transitionLeftScale < 1) then
transitionLeftScale = TRANSITION_ALERT_ENTER_THRESHOLD -- If the laser alert is already in progress, just reset its duration
else
transitionLeftScale = 0;
end
end
end
local tickTransitions = function (deltaTime)
local showScale = 0;
-- Left
if transitionLeftScale < 1 then
transitionLeftScale = transitionLeftScale + deltaTime / 3 -- transition should last for that time in seconds
else
transitionLeftScale = 1
end
showScale = 0;
if transitionLeftScale < TRANSITION_ALERT_ENTER_THRESHOLD then
showScale = transitionLeftScale/TRANSITION_ALERT_ENTER_THRESHOLD; -- 0-0.1
elseif transitionLeftScale > TRANSITION_ALERT_LEAVE_THRESHOLD and transitionLeftScale < 1 then
showScale = 1-((transitionLeftScale-TRANSITION_ALERT_LEAVE_THRESHOLD)/(1-TRANSITION_ALERT_LEAVE_THRESHOLD));
elseif transitionLeftScale >= 1 then
showScale = 0;
else
showScale = 1;
end
transitionLeftOffsetX = -450*0.5*(1-showScale);
transitionLeftOpacity = math.max(0, showScale-0.5)/0.5;
-- Right
if transitionRightScale < 1 then
transitionRightScale = transitionRightScale + deltaTime / 3 -- transition should last for that time in seconds
else
transitionRightScale = 1
end
showScale = 0;
if transitionRightScale < TRANSITION_ALERT_ENTER_THRESHOLD then
showScale = transitionRightScale/TRANSITION_ALERT_ENTER_THRESHOLD; -- 0-0.1
elseif transitionRightScale > TRANSITION_ALERT_LEAVE_THRESHOLD and transitionRightScale < 1 then
showScale = 1-((transitionRightScale-TRANSITION_ALERT_LEAVE_THRESHOLD)/(1-TRANSITION_ALERT_LEAVE_THRESHOLD));
elseif transitionRightScale >= 1 then
showScale = 0;
else
showScale = 1;
end
transitionRightOffsetX = 450*0.5*(1-showScale);
transitionRightOpacity = math.max(0, showScale-0.5)/0.5;
end
local render = function (deltaTime) local render = function (deltaTime)
tickTransitions(deltaTime);
gfx.Save();
renderLeftAlert(); renderLeftAlert();
renderRightAlert(); renderRightAlert();
test = test + deltaTime; test = test + deltaTime;
gfx.Restore();
gfx.BeginPath();
gfx.FontSize(18)
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_TOP)
gfx.Text('T_L: ' .. transitionLeftScale .. ' // T_R: ' .. transitionRightScale, 500, 500);
end end
return { return {
show=showLaserAlert,
render=render render=render
} }