+ make the laser alerts work
This commit is contained in:
parent
7ca8ffd561
commit
2f575c022e
|
@ -75,7 +75,7 @@ function laser_slam_hit(slamLength, startPos, endPost, index)
|
|||
end
|
||||
|
||||
function laser_alert(isRight)
|
||||
|
||||
LaserAlert.show(isRight)
|
||||
end
|
||||
|
||||
function practice_start(mission_type, mission_threshold, mission_description)
|
||||
|
|
|
@ -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 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 RIGHT_ALERT_X_POS = 1080 - 450*0.5
|
||||
|
||||
|
@ -14,6 +17,14 @@ local ALERT_Y_POS = 1115
|
|||
|
||||
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 ()
|
||||
-- gfx.Translate(LEFT_ALERT_X_POS, ALERT_Y_POS);
|
||||
-- -- gfx.SkewX(-1*3.14)
|
||||
|
@ -21,7 +32,7 @@ local renderLeftAlert = function ()
|
|||
|
||||
gfx.BeginPath();
|
||||
gfx.ImageRect(
|
||||
LEFT_ALERT_X_POS+450*0.5,
|
||||
(LEFT_ALERT_X_POS+450*0.5) + transitionLeftOffsetX,
|
||||
ALERT_Y_POS+450*0.5,
|
||||
450*0.5,
|
||||
450*0.5,
|
||||
|
@ -32,7 +43,7 @@ local renderLeftAlert = function ()
|
|||
|
||||
gfx.BeginPath();
|
||||
gfx.ImageRect(
|
||||
LEFT_ALERT_X_POS+450*0.5,
|
||||
(LEFT_ALERT_X_POS+450*0.5) + transitionLeftOffsetX,
|
||||
ALERT_Y_POS+450*0.5,
|
||||
450*0.5,
|
||||
450*0.5,
|
||||
|
@ -48,7 +59,7 @@ local renderLeftAlert = function ()
|
|||
450*0.5,
|
||||
450*0.5,
|
||||
leftAlertTextImage,
|
||||
1,
|
||||
transitionLeftOpacity,
|
||||
0
|
||||
);
|
||||
|
||||
|
@ -57,7 +68,7 @@ end
|
|||
local renderRightAlert = function ()
|
||||
gfx.BeginPath();
|
||||
gfx.ImageRect(
|
||||
RIGHT_ALERT_X_POS,
|
||||
RIGHT_ALERT_X_POS + transitionRightOffsetX,
|
||||
ALERT_Y_POS,
|
||||
450*0.5,
|
||||
450*0.5,
|
||||
|
@ -68,7 +79,7 @@ local renderRightAlert = function ()
|
|||
|
||||
gfx.BeginPath();
|
||||
gfx.ImageRect(
|
||||
RIGHT_ALERT_X_POS,
|
||||
RIGHT_ALERT_X_POS + transitionRightOffsetX,
|
||||
ALERT_Y_POS,
|
||||
450*0.5,
|
||||
450*0.5,
|
||||
|
@ -84,17 +95,91 @@ local renderRightAlert = function ()
|
|||
450*0.5,
|
||||
450*0.5,
|
||||
rightAlertTextImage,
|
||||
1,
|
||||
transitionRightOpacity,
|
||||
0
|
||||
);
|
||||
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)
|
||||
tickTransitions(deltaTime);
|
||||
gfx.Save();
|
||||
|
||||
renderLeftAlert();
|
||||
renderRightAlert();
|
||||
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
|
||||
|
||||
return {
|
||||
show=showLaserAlert,
|
||||
render=render
|
||||
}
|
Loading…
Reference in New Issue