ExperimentalGear/scripts/gameplay/laser_alert.lua

185 lines
5.0 KiB
Lua
Raw Normal View History

2021-10-01 21:32:20 +02:00
local leftAlertBaseImage = gfx.CreateSkinImage("gameplay/laser_alert/left/base.png", 0)
local leftAlertTopImage = gfx.CreateSkinImage("gameplay/laser_alert/left/top.png", 0)
local leftAlertTextImage = gfx.CreateSkinImage("gameplay/laser_alert/left/text.png", 0)
local rightAlertBaseImage = gfx.CreateSkinImage("gameplay/laser_alert/right/base.png", 0)
local rightAlertTopImage = gfx.CreateSkinImage("gameplay/laser_alert/right/top.png", 0)
local rightAlertTextImage = gfx.CreateSkinImage("gameplay/laser_alert/right/text.png", 0)
2021-10-02 00:17:24 +02:00
local TRANSITION_ALERT_ENTER_THRESHOLD = 0.075;
local TRANSITION_ALERT_LEAVE_THRESHOLD = 0.925;
2021-10-01 21:32:20 +02:00
local LEFT_ALERT_X_POS = 0
local RIGHT_ALERT_X_POS = 1080 - 450*0.5
local ALERT_Y_POS = 1115
local test = -2*3.14;
2021-10-02 00:17:24 +02:00
local transitionLeftScale = 1;
local transitionLeftOffsetX = 0;
local transitionLeftOpacity = 0;
local transitionRightScale = 1;
local transitionRightOffsetX = 0;
local transitionRightOpacity = 0;
2021-10-01 21:32:20 +02:00
local renderLeftAlert = function ()
-- gfx.Translate(LEFT_ALERT_X_POS, ALERT_Y_POS);
-- -- gfx.SkewX(-1*3.14)
-- gfx.Scale(test, 1)
gfx.BeginPath();
gfx.ImageRect(
2021-10-02 00:17:24 +02:00
(LEFT_ALERT_X_POS+450*0.5) + transitionLeftOffsetX,
2021-10-01 21:32:20 +02:00
ALERT_Y_POS+450*0.5,
450*0.5,
450*0.5,
leftAlertBaseImage,
1,
-3.14
);
gfx.BeginPath();
gfx.ImageRect(
2021-10-02 00:17:24 +02:00
(LEFT_ALERT_X_POS+450*0.5) + transitionLeftOffsetX,
2021-10-01 21:32:20 +02:00
ALERT_Y_POS+450*0.5,
450*0.5,
450*0.5,
leftAlertTopImage,
1,
-3.14
);
gfx.BeginPath();
gfx.ImageRect(
LEFT_ALERT_X_POS,
ALERT_Y_POS,
450*0.5,
450*0.5,
leftAlertTextImage,
2021-10-02 00:17:24 +02:00
transitionLeftOpacity,
2021-10-01 21:32:20 +02:00
0
);
-- gfx.ResetTransform();
end
local renderRightAlert = function ()
gfx.BeginPath();
gfx.ImageRect(
2021-10-02 00:17:24 +02:00
RIGHT_ALERT_X_POS + transitionRightOffsetX,
2021-10-01 21:32:20 +02:00
ALERT_Y_POS,
450*0.5,
450*0.5,
rightAlertBaseImage,
1,
0
);
gfx.BeginPath();
gfx.ImageRect(
2021-10-02 00:17:24 +02:00
RIGHT_ALERT_X_POS + transitionRightOffsetX,
2021-10-01 21:32:20 +02:00
ALERT_Y_POS,
450*0.5,
450*0.5,
rightAlertTopImage,
1,
0
);
gfx.BeginPath();
gfx.ImageRect(
RIGHT_ALERT_X_POS,
ALERT_Y_POS,
450*0.5,
450*0.5,
rightAlertTextImage,
2021-10-02 00:17:24 +02:00
transitionRightOpacity,
2021-10-01 21:32:20 +02:00
0
);
end
2021-10-02 00:17:24 +02:00
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
2021-10-01 21:32:20 +02:00
local render = function (deltaTime)
2021-10-02 00:17:24 +02:00
tickTransitions(deltaTime);
gfx.Save();
2021-10-01 21:32:20 +02:00
renderLeftAlert();
renderRightAlert();
test = test + deltaTime;
2021-10-02 00:17:24 +02:00
gfx.Restore();
2021-10-03 11:02:58 +02:00
-- 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);
2021-10-01 21:32:20 +02:00
end
return {
2021-10-02 00:17:24 +02:00
show=showLaserAlert,
2021-10-01 21:32:20 +02:00
render=render
}