local splashScreen = require('titlescreen.splash'); local modeSelectScreen = require('titlescreen.mode_select'); local screens = { splash = { screen = splashScreen }, mode_select = { screen = modeSelectScreen } } local currentScreen = screens.splash; local handleScreenResponse = function (res) if (res.eventType == 'switch') then if (not screens[res.toScreen]) then game.Log('Undefined screen ' .. res.toScreen, game.LOGGER_ERROR); return; end currentScreen = screens[res.toScreen] end end function render(deltaTime) handle_controller(); local res = currentScreen.screen.render(deltaTime) if res then handleScreenResponse(res) end end function mouse_pressed(button) if true then return 0 end if (currentScreen.screen.onMousePressed) then currentScreen.screen.onMousePressed(button); end end function button_pressed(button) if (currentScreen.screen.onButtonPressed) then currentScreen.screen.onButtonPressed(button); end end function sign(x) return x > 0 and 1 or x < 0 and -1 or 0 end function roundToZero(x) if x < 0 then return math.ceil(x) elseif x > 0 then return math.floor(x) else return 0 end end function deltaKnob(delta) if math.abs(delta) > 1.5 * math.pi then return delta + 2 * math.pi * sign(delta) * -1 end return delta end local lastKnobs = nil local knobProgress = 0 function handle_controller() if (not currentScreen.screen.onKnobsChange) then return end if lastKnobs == nil then lastKnobs = {game.GetKnob(0), game.GetKnob(1)} else local newKnobs = {game.GetKnob(0), game.GetKnob(1)} knobProgress = knobProgress - deltaKnob(lastKnobs[1] - newKnobs[1]) * 1.2 knobProgress = knobProgress - deltaKnob(lastKnobs[2] - newKnobs[2]) * 1.2 lastKnobs = newKnobs if math.abs(knobProgress) > 1 then if (knobProgress < 0) then -- Negative currentScreen.screen.onKnobsChange(-1) else -- Positive currentScreen.screen.onKnobsChange(1) end knobProgress = knobProgress - roundToZero(knobProgress) end end end