Created
December 19, 2015 18:00
-
-
Save iUltimateLP/82796afec8e4decedb93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Mini game controller for The Talos Principle | |
-- by iUltimateLP | |
-- Colors we play with | |
local colors = {"Red", "Purple", "Yellow", | |
"Orange", "Lime", "Cyan", | |
"Gray", "Blue", "Pink", | |
"Black"} | |
-- Tries we have, 0 if instant death | |
local tries = 0 | |
-- Platform-change time 6, 4.5, 3.3 | |
local timesForChange = {6, 4.5, 3.3} | |
-- Time win..nextScramble | |
local timeNext = 1 | |
-- Time the disappeared platforms stay | |
local timeStayDis = 2.5 | |
-- The next Color we play with | |
local nextColor = "" | |
-- are we allowed to play | |
local bAllowPlay = false | |
-- reference to the player | |
local player = nil | |
-- current round | |
local currentRound = 1 | |
-- current Level | |
local currentLevel = 1 | |
-- rounds per level | |
local roundsPerLevel = 10 | |
-- max levels | |
local maxLevels = 3 | |
-- Get random Color platform | |
local getRandomColor = function() | |
local rnd = mthRndRangeL(1, 10) | |
local color = colors[rnd] | |
nextColor = color | |
local returnPlatforms = {} | |
for _,v in ipairs(platforms) do | |
if (string.match(v:GetName(), color)) then | |
table.insert(returnPlatforms, v) | |
end | |
end | |
return returnPlatforms | |
end | |
-- Set platforms visibility, keep some | |
local setPlatformsState = function(toKeep) | |
for _,v in ipairs(platforms) do | |
if (toKeep[1] == v or toKeep[2] == v) then | |
v:Appear() | |
else | |
v:Disappear() | |
end | |
end | |
end | |
-- Show all platforms | |
local showAllPlatforms = function() | |
for _,v in ipairs(platforms) do | |
v:Appear() | |
end | |
end | |
-- Update Values on Overlay | |
local updateGUIvals = function(x, y) | |
-- progress : CTalosProgress | |
local progress = nexGetTalosProgress(worldInfo) | |
progress:SetCode("ovLevel", x) | |
progress:SetCode("ovRound", y) | |
terminal:ClearTexts() | |
terminal:AddTerminalText("TDA_3_01_Status") | |
end | |
-- Make music heavier over time | |
local updateMusic = function(x) | |
local names = {"low", "high", "extreme"} | |
-- snd : CStreamingSound | |
local snd = LoadResource("Content/Talos/Music/bossfight_"..names[x]..".ogg") | |
worldInfo:ForceMusic("Continuous", snd) | |
end | |
-- Main game loop | |
local gameLoop = function() | |
while true do | |
updateGUIvals(currentLevel, currentRound) | |
Wait(Delay(timeNext)) | |
local nextColorPlatforms = getRandomColor() | |
worldInfo:ShowMessageToAll("Attention! The next color is "..nextColor) | |
Wait(Delay(timesForChange[currentLevel])) | |
setPlatformsState(nextColorPlatforms) | |
Wait(Delay(timeStayDis)) | |
showAllPlatforms() | |
if (currentRound == roundsPerLevel) then | |
currentRound = 1 | |
if (currentLevel == maxLevels) then | |
worldInfo:ShowMessageToAll("Congratulations! You won!") | |
terminal:EnableOverlayRendering(false) | |
worldInfo:ForceMusic("Continuous", music) | |
doorCtrl:LevelDone(maxLevels) | |
break | |
else | |
currentLevel = currentLevel + 1 | |
updateMusic(currentLevel) | |
doorCtrl:LevelDone(currentLevel-1) | |
end | |
else | |
currentRound = currentRound + 1 | |
end | |
end | |
end | |
-- Event Handler | |
RunHandled(WaitForever, | |
OnEvery(Event(worldInfo.PlayerBorn)), function(p) | |
-- p : CPlayerBornScriptEvent | |
player = p:GetBornPlayer() | |
Wait(Delay(0.5)) | |
for k,v in ipairs(doorCtrl:GetSavedLevels()) do | |
if (v == true) then | |
if (k ~= maxLevels) then | |
currentLevel = k+1 | |
else | |
currentLevel = 1 | |
print("All done, lets reset!") | |
end | |
end | |
end | |
end, | |
OnEvery(Event(startDetector.Activated)), function() | |
if (bAllowPlay == false) then | |
if (worldInfo:IsVarSet("TDA_3_01_HintGiven") == 1) then | |
bAllowPlay = true | |
print("Let the games begin.") | |
updateMusic(currentLevel) | |
terminal:EnableOverlayRendering(true) | |
gameLoop() | |
else | |
startDetector:Recharge() | |
end | |
end | |
end | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment