diff --git a/main.lua b/main.lua index 10e3b12..d377299 100644 --- a/main.lua +++ b/main.lua @@ -30,7 +30,7 @@ function love.load() require "scene" require "game.vctrl" -- VCTRL - scene = config.firstTime and InputConfigScene() or TitleScene() + SCENE = config.firstTime and InputConfigScene() or TitleScene() love.mouse.setVisible(false) love.window.setMode(love.graphics.getWidth(), love.graphics.getHeight(), {resizable = true}); @@ -77,7 +77,7 @@ function love.draw() love.graphics.clear() love.graphics.push() - scene:render() + SCENE:render() VCTRL.draw() -- -- Grid system @@ -129,20 +129,20 @@ function love.keypressed(key, scancode) if scancode == "f4" then config["fullscreen"] = not config["fullscreen"] love.window.setFullscreen(config["fullscreen"]) - elseif scancode == "f2" and scene.title ~= "Input Config" and scene.title ~= "Game" then - scene = InputConfigScene() + elseif scancode == "f2" and SCENE.title ~= "Input Config" and SCENE.title ~= "Game" then + SCENE = InputConfigScene() -- function keys are reserved elseif string.match(scancode, "^f[1-9]$") or string.match(scancode, "^f1[0-2]+$") then return -- escape is reserved for menu_back elseif scancode == "escape" or scancode == "acback" then - scene:onInputPress({input="menu_back", type="key", key=key, scancode=scancode}) + SCENE:onInputPress({input="menu_back", type="key", key=key, scancode=scancode}) -- pass any other key to the scene, with its configured mapping else if config.input and config.input.keys then input_pressed = config.input.keys[scancode] end - scene:onInputPress({input=input_pressed, type="key", key=key, scancode=scancode}) + SCENE:onInputPress({input=input_pressed, type="key", key=key, scancode=scancode}) end LastPressedKey = input_pressed or scancode @@ -153,7 +153,7 @@ function love.keyreleased(key, scancode) -- escape is reserved for menu_back if scancode == "escape" or scancode == 'acback' then - scene:onInputRelease({input="menu_back", type="key", key=key, scancode=scancode}) + SCENE:onInputRelease({input="menu_back", type="key", key=key, scancode=scancode}) -- function keys are reserved elseif string.match(scancode, "^f[1-9]$") or string.match(scancode, "^f1[0-2]+$") then return @@ -162,7 +162,7 @@ function love.keyreleased(key, scancode) if config.input and config.input.keys then input_released = config.input.keys[scancode] end - scene:onInputRelease({input=input_released, type="key", key=key, scancode=scancode}) + SCENE:onInputRelease({input=input_released, type="key", key=key, scancode=scancode}) end LastReleasedKey = input_released or scancode @@ -178,7 +178,7 @@ function love.joystickpressed(joystick, button) then input_pressed = config.input.joysticks[joystick:getName()].buttons[button] end - scene:onInputPress({input=input_pressed, type="joybutton", name=joystick:getName(), button=button}) + SCENE:onInputPress({input=input_pressed, type="joybutton", name=joystick:getName(), button=button}) end function love.joystickreleased(joystick, button) @@ -191,7 +191,7 @@ function love.joystickreleased(joystick, button) then input_released = config.input.joysticks[joystick:getName()].buttons[button] end - scene:onInputRelease({input=input_released, type="joybutton", name=joystick:getName(), button=button}) + SCENE:onInputRelease({input=input_released, type="joybutton", name=joystick:getName(), button=button}) end function love.joystickaxis(joystick, axis, value) @@ -212,10 +212,10 @@ function love.joystickaxis(joystick, axis, value) negative_released = config.input.joysticks[joystick:getName()].axes[axis].negative end if math.abs(value) >= 1 then - scene:onInputPress({input=input_pressed, type="joyaxis", name=joystick:getName(), axis=axis, value=value}) + SCENE:onInputPress({input=input_pressed, type="joyaxis", name=joystick:getName(), axis=axis, value=value}) else - scene:onInputRelease({input=positive_released, type="joyaxis", name=joystick:getName(), axis=axis, value=value}) - scene:onInputRelease({input=negative_released, type="joyaxis", name=joystick:getName(), axis=axis, value=value}) + SCENE:onInputRelease({input=positive_released, type="joyaxis", name=joystick:getName(), axis=axis, value=value}) + SCENE:onInputRelease({input=negative_released, type="joyaxis", name=joystick:getName(), axis=axis, value=value}) end end @@ -247,20 +247,20 @@ function love.joystickhat(joystick, hat, direction) local char = direction:sub(i, i) local _, count = last_hat_direction:gsub(char, char) if count == 0 then - scene:onInputPress({input=config.input.joysticks[joystick:getName()].hats[hat][char], type="joyhat", name=joystick:getName(), hat=hat, direction=char}) + SCENE:onInputPress({input=config.input.joysticks[joystick:getName()].hats[hat][char], type="joyhat", name=joystick:getName(), hat=hat, direction=char}) end end for i = 1, #last_hat_direction do local char = last_hat_direction:sub(i, i) local _, count = direction:gsub(char, char) if count == 0 then - scene:onInputRelease({input=config.input.joysticks[joystick:getName()].hats[hat][char], type="joyhat", name=joystick:getName(), hat=hat, direction=char}) + SCENE:onInputRelease({input=config.input.joysticks[joystick:getName()].hats[hat][char], type="joyhat", name=joystick:getName(), hat=hat, direction=char}) end end last_hat_direction = direction elseif has_hat then for i, direction in ipairs{"d", "l", "ld", "lu", "r", "rd", "ru", "u"} do - scene:onInputRelease({input=config.input.joysticks[joystick:getName()].hats[hat][direction], type="joyhat", name=joystick:getName(), hat=hat, direction=direction}) + SCENE:onInputRelease({input=config.input.joysticks[joystick:getName()].hats[hat][direction], type="joyhat", name=joystick:getName(), hat=hat, direction=direction}) end last_hat_direction = "" elseif direction ~= "c" then @@ -268,20 +268,20 @@ function love.joystickhat(joystick, hat, direction) local char = direction:sub(i, i) local _, count = last_hat_direction:gsub(char, char) if count == 0 then - scene:onInputPress({input=directions[char], type="joyhat", name=joystick:getName(), hat=hat, direction=char}) + SCENE:onInputPress({input=directions[char], type="joyhat", name=joystick:getName(), hat=hat, direction=char}) end end for i = 1, #last_hat_direction do local char = last_hat_direction:sub(i, i) local _, count = direction:gsub(char, char) if count == 0 then - scene:onInputRelease({input=directions[char], type="joyhat", name=joystick:getName(), hat=hat, direction=char}) + SCENE:onInputRelease({input=directions[char], type="joyhat", name=joystick:getName(), hat=hat, direction=char}) end end last_hat_direction = direction else for i, direction in ipairs{"d", "l", "ld", "lu", "r", "rd", "ru", "u"} do - scene:onInputRelease({input=nil, type="joyhat", name=joystick:getName(), hat=hat, direction=direction}) + SCENE:onInputRelease({input=nil, type="joyhat", name=joystick:getName(), hat=hat, direction=direction}) end last_hat_direction = "" end @@ -315,8 +315,8 @@ function love.run() end end - if scene and scene.update and love.timer then - scene:update() + if SCENE and SCENE.update and love.timer then + SCENE:update() local frame_duration = 1.0 / TARGET_FPS if time_accumulator < frame_duration then diff --git a/scene.lua b/scene.lua index b6ae4bb..f2eeae2 100644 --- a/scene.lua +++ b/scene.lua @@ -1,12 +1,12 @@ local Object = require "libs.classic" -Scene = Object:extend() +SCENE = Object:extend() -function Scene:new() end -function Scene:update() end -function Scene:render() end -function Scene:onInputPress() end -function Scene:onInputRelease() end +function SCENE:new() end +function SCENE:update() end +function SCENE:render() end +function SCENE:onInputPress() end +function SCENE:onInputRelease() end ExitScene = require "scene.exit" GameScene = require "scene.game" diff --git a/scene/exit.lua b/scene/exit.lua index bd1fd16..095e8f1 100644 --- a/scene/exit.lua +++ b/scene/exit.lua @@ -1,4 +1,4 @@ -local ExitScene = Scene:extend() +local ExitScene = SCENE:extend() require 'load.save' ExitScene.title = "Exit Game" diff --git a/scene/fullscreen.lua b/scene/fullscreen.lua index 0dc9b78..c36972d 100644 --- a/scene/fullscreen.lua +++ b/scene/fullscreen.lua @@ -1,4 +1,4 @@ -local FullscreenScene = Scene:extend() +local FullscreenScene = SCENE:extend() require 'load.save' FullscreenScene.title = "Fullscreen" @@ -10,7 +10,7 @@ function FullscreenScene:update() config["fullscreen"] = not config["fullscreen"] saveConfig() love.window.setFullscreen(config["fullscreen"]) - scene = TitleScene() + SCENE = TitleScene() end function FullscreenScene:render() diff --git a/scene/game.lua b/scene/game.lua index 5b663ff..7fe0500 100644 --- a/scene/game.lua +++ b/scene/game.lua @@ -1,4 +1,4 @@ -local GameScene = Scene:extend() +local GameScene = SCENE:extend() GameScene.title = "Game" local tas = false @@ -68,11 +68,11 @@ end function GameScene:onInputPress(e) if (self.game.game_over or self.game.completed) and (e.input == "menu_decide" or e.input == "menu_back" or e.input == "rotate_right") and self.game.game_over_frames > 50 then - scene = TitleScene() + SCENE = TitleScene() elseif tas and e.input == "menu_decide" then self:update(false, true) elseif self.game.input_playback and (e.input == "menu_back") then - scene = TitleScene() + SCENE = TitleScene() elseif self.game.input_playback and e.input == "rotate_left" then self.paused = false self:update() diff --git a/scene/input_config.lua b/scene/input_config.lua index db73477..af0bc59 100644 --- a/scene/input_config.lua +++ b/scene/input_config.lua @@ -1,4 +1,4 @@ -local ConfigScene = Scene:extend() +local ConfigScene = SCENE:extend() ConfigScene.title = "Input Config" @@ -39,13 +39,13 @@ function ConfigScene:render() end function ConfigScene:changeOption(rel) - local len = table.getn(menu_screens) + local len = #menu_screens self.menu_state = (self.menu_state + len + rel - 1) % len + 1 end function ConfigScene:onInputPress(e) if e.input == "menu_decide" or e.input == "rotate_left" or e.scancode == "return" then - scene = menu_screens[self.menu_state]() + SCENE = menu_screens[self.menu_state]() elseif e.input == "up" or e.scancode == "up" then self:changeOption(-1) elseif e.input == "down" or e.scancode == "down" then @@ -53,7 +53,7 @@ function ConfigScene:onInputPress(e) elseif config.input and ( e.input == "menu_back" or e.input == "rotate_right" or e.scancode == "backspace" or e.scancode == "delete" ) then - scene = TitleScene() + SCENE = TitleScene() end end diff --git a/scene/key_config.lua b/scene/key_config.lua index ed3714c..e1f1cbc 100644 --- a/scene/key_config.lua +++ b/scene/key_config.lua @@ -1,4 +1,4 @@ -local KeyConfigScene = Scene:extend() +local KeyConfigScene = SCENE:extend() KeyConfigScene.title = "Key Config" @@ -58,7 +58,7 @@ function KeyConfigScene:render() drawText(self.set_inputs[input], 240, 50 + i * 20, 300, "left") end end - if self.input_state > table.getn(configurable_inputs) then + if self.input_state > #configurable_inputs then drawText("Press enter to confirm, delete/backspace to retry" .. (config.input and ", escape to cancel" or ""),0,0,1000) else drawText("Press key input for " .. input_names[configurable_inputs[self.input_state]] .. ", tab to skip, escape to cancel",0,0,1000) @@ -70,12 +70,12 @@ function KeyConfigScene:onInputPress(e) if e.type == "key" then -- function keys, escape, and tab are reserved and can't be remapped if e.scancode == "escape" then - scene = InputConfigScene() - elseif self.input_state > table.getn(configurable_inputs) then + SCENE = InputConfigScene() + elseif self.input_state > #configurable_inputs then if e.scancode == "return" then config.input.keys = self.new_input saveConfig() - scene = config.firstTime and TitleScene() or InputConfigScene() + SCENE = config.firstTime and TitleScene() or InputConfigScene() config.firstTime = false elseif e.scancode == "delete" or e.scancode == "backspace" then -- retry diff --git a/scene/music_toggle.lua b/scene/music_toggle.lua index 33163df..7ef0227 100644 --- a/scene/music_toggle.lua +++ b/scene/music_toggle.lua @@ -1,4 +1,4 @@ -local MusicToggleScene = Scene:extend() +local MusicToggleScene = SCENE:extend() require 'load.save' MusicToggleScene.title = "Play music during game:" @@ -9,7 +9,7 @@ end function MusicToggleScene:update() config["music"] = not config["music"] saveConfig() - scene = TitleScene() + SCENE = TitleScene() end function MusicToggleScene:render() diff --git a/scene/name_entry.lua b/scene/name_entry.lua index ec8a2c1..d5babaf 100644 --- a/scene/name_entry.lua +++ b/scene/name_entry.lua @@ -1,4 +1,4 @@ -local NameEntryScene = Scene:extend() +local NameEntryScene = SCENE:extend() local Grid = require 'game.grid' local bitser = require 'libs.bitser' require 'load.save' @@ -117,7 +117,7 @@ function NameEntryScene:onInputPress(e) if self.entry_pos == 4 then config['last_entry'] = name:upper() saveConfig() - scene = GameScene(name:lower()) + SCENE = GameScene(name:lower()) else if self.entry_pos == 3 then name = string.lower(self.name_entry[1]..self.name_entry[2]..self.name_entry[3]) @@ -146,7 +146,7 @@ function NameEntryScene:onInputPress(e) self.delete_confirm = false self.delete_input_count = 0 if self.entry_pos == 1 then - scene = TitleScene() + SCENE = TitleScene() else self.name_entry[self.entry_pos] = 'A' self.name_entry[self.entry_pos-1] = 'A' diff --git a/scene/replay.lua b/scene/replay.lua index 84d2083..26e7264 100644 --- a/scene/replay.lua +++ b/scene/replay.lua @@ -1,5 +1,5 @@ require 'funcs' -local ReplaySelectScene = Scene:extend() +local ReplaySelectScene = SCENE:extend() ReplaySelectScene.title = "Replay" @@ -77,7 +77,7 @@ function ReplaySelectScene:render() end function ReplaySelectScene:changeOption(rel) - local len = table.getn(self.replays) + local len = #self.replays self.replay_select = self.replay_select + rel if self.replay_select + ((self.page-1) * self.page_flip) > len then self.page = 1 @@ -107,7 +107,7 @@ function ReplaySelectScene:onInputPress(e) selected_replay_text = self.replay_text[self.replay_select + ((self.page-1) * self.page_flip)] if e.input == "menu_decide" or e.input == "rotate_left" or e.scancode == "return" then if self.replays[1] == nil then - scene = TitleScene() + SCENE = TitleScene() --if not self.dialog then -- self.dialog_select = 1 -- self.dialog = true @@ -130,19 +130,19 @@ function ReplaySelectScene:onInputPress(e) end player_name = line_components[1] player_grade = string.gsub(line_components[2], " ", "") - scene = GameScene(player_name, selected_replay, player_grade) + SCENE = GameScene(player_name, selected_replay, player_grade) end elseif e.input == "up" or e.scancode == "up" then - if self.replays[1] == nil then scene = TitleScene() end + if self.replays[1] == nil then SCENE = TitleScene() end if not self.dialog then self:changeOption(-1) else self:changeDialog(-1) end elseif e.input == "down" or e.scancode == "down" then - if self.replays[1] == nil then scene = TitleScene() end + if self.replays[1] == nil then SCENE = TitleScene() end if not self.dialog then self:changeOption(1) else self:changeDialog(1) end elseif e.input == "menu_back" or e.input == "rotate_right" or e.scancode == "backspace" or e.scancode == "delete" then - if self.replays[1] == nil then scene = TitleScene() end - if not self.dialog then scene = TitleScene() + if self.replays[1] == nil then SCENE = TitleScene() end + if not self.dialog then SCENE = TitleScene() else self.dialog = false end end end diff --git a/scene/stick_config.lua b/scene/stick_config.lua index a548603..1d14e3e 100644 --- a/scene/stick_config.lua +++ b/scene/stick_config.lua @@ -1,4 +1,4 @@ -local StickConfigScene = Scene:extend() +local StickConfigScene = SCENE:extend() StickConfigScene.title = "Controller Config" @@ -58,7 +58,7 @@ function StickConfigScene:render() drawText(self.set_inputs[input], 240, 50 + i * 20, 300, "left") end end - if self.input_state > table.getn(configurable_inputs) then + if self.input_state > #configurable_inputs then drawText("Press enter to confirm, delete/backspace to retry" .. (config.input and ", escape to cancel" or ""), 0, 0, 1000) else drawText("Press joystick input for " .. input_names[configurable_inputs[self.input_state]] .. ", tab to skip, escape to cancel", 0, 0, 1000) @@ -77,15 +77,15 @@ function StickConfigScene:onInputPress(e) if e.type == "key" then -- function keys, escape, and tab are reserved and can't be remapped if e.scancode == "escape" then - scene = InputConfigScene() - elseif self.input_state > table.getn(configurable_inputs) then + SCENE = InputConfigScene() + elseif self.input_state > #configurable_inputs then if e.scancode == "return" then -- save new input, then load next scene local had_config = config.input ~= nil if not config.input then config.input = {} end config.input.joysticks = self.new_input saveConfig() - scene = had_config and InputConfigScene() or TitleScene() + SCENE = had_config and InputConfigScene() or TitleScene() elseif e.scancode == "delete" or e.scancode == "backspace" then -- retry self.input_state = 1 @@ -97,7 +97,7 @@ function StickConfigScene:onInputPress(e) self.input_state = self.input_state + 1 end elseif string.sub(e.type, 1, 3) == "joy" then - if self.input_state <= table.getn(configurable_inputs) then + if self.input_state <= #configurable_inputs then if e.type == "joybutton" then addJoystick(self.new_input, e.name) if not self.new_input[e.name].buttons then diff --git a/scene/title.lua b/scene/title.lua index 82d5e09..fa616cd 100644 --- a/scene/title.lua +++ b/scene/title.lua @@ -1,4 +1,4 @@ -local TitleScene = Scene:extend() +local TitleScene = SCENE:extend() require 'load.save' require 'funcs' @@ -83,13 +83,13 @@ function TitleScene:render() end function TitleScene:changeOption(rel) - local len = table.getn(main_menu_screens) + local len = #main_menu_screens self.main_menu_state = (self.main_menu_state + len + rel - 1) % len + 1 end function TitleScene:onInputPress(e) if e.input == "menu_decide" or e.input == "rotate_left" or e.scancode == "return" then - scene = main_menu_screens[self.main_menu_state]() + SCENE = main_menu_screens[self.main_menu_state]() elseif e.input == "up" or e.scancode == "up" then self:changeOption(-1) elseif e.input == "down" or e.scancode == "down" then diff --git a/scene/training.lua b/scene/training.lua index 08bf6ef..72791ea 100644 --- a/scene/training.lua +++ b/scene/training.lua @@ -1,4 +1,4 @@ -local TrainingScene = Scene:extend() +local TrainingScene = SCENE:extend() TrainingScene.title = "Max Gravity Training" @@ -46,9 +46,9 @@ end function TrainingScene:onInputPress(e) if (self.game.game_over or self.game.completed) and (e.input == "menu_decide" or e.input == "menu_back" or e.input == "rotate_right") and self.game.game_over_frames > 50 then - scene = TitleScene() + SCENE = TitleScene() elseif (e.input == "menu_back") then - scene = TitleScene() + SCENE = TitleScene() elseif e.input and string.sub(e.input, 1, 5) ~= "menu_" then self.inputs[e.input] = true end