Get rid of realll bad 'mode' system

This commit is contained in:
Jaidyn Ann 2021-02-06 13:17:16 -06:00
parent 0b4e6a55da
commit d51b36df51

129
main.lua
View File

@ -3,7 +3,6 @@ class = require "lib/middleclass"
wind = require "lib/windfield" wind = require "lib/windfield"
stalker = require "lib/STALKER-X" stalker = require "lib/STALKER-X"
mainmenu = 0; game = 1; gameover = 2; pause = 3; youwin = 4
startSwordLength = 40; startKnifeLength = 10 startSwordLength = 40; startKnifeLength = 10
world = wind.newWorld(0, 0, true) world = wind.newWorld(0, 0, true)
@ -26,24 +25,14 @@ end
function love.update(dt) function love.update(dt)
if(mode == mainmenu) then mainmenu_update(dt) updateFunction(dt)
elseif(mode == game) then game_update(dt)
elseif(mode == gameover) then gameover_update(dt)
elseif(mode == youwin) then youwin_update(dt)
elseif(mode == pause) then pause_update(dt)
end
camera:update(dt) camera:update(dt)
end end
function love.draw() function love.draw()
camera:attach() camera:attach()
if(mode == mainmenu) then mainmenu_draw() drawFunction()
elseif(mode == game) then game_draw()
elseif(mode == gameover) then gameover_draw()
elseif(mode == youwin) then youwin_draw()
elseif(mode == pause) then pause_draw()
end
camera:detach() camera:detach()
camera:draw() camera:draw()
end end
@ -55,40 +44,25 @@ end
function love.keypressed(key) function love.keypressed(key)
if(mode == mainmenu) then mainmenu_keypressed(key) keypressedFunction(key)
elseif(mode == game) then game_keypressed(key)
elseif(mode == gameover) then gameover_keypressed(key)
elseif(mode == youwin) then youwin_keypressed(key)
elseif(mode == pause) then pause_keypressed(key)
end
end end
function love.keyreleased (key) function love.keyreleased (key)
if(mode == mainmenu) then mainmenu_keyreleased(key) keyreleasedFunction(key)
elseif(mode == game) then game_keyreleased(key)
elseif(mode == gameover) then gameover_keyreleased(key)
elseif(mode == youwin) then youwin_keyreleased(key)
elseif(mode == pause) then pause_keyreleased(key)
end
end end
-- MENU STATE -- MENU STATE
---------------------------------------- ----------------------------------------
function mainmenu_load () function mainmenu_load ()
mode = mainmenu updateFunction = mainmenu_update
selection = 1 drawFunction = mainmenu_draw
if(bgm) then keypressedFunction = mainmenu_keypressed
bgm:stop() keyreleasedFunction = mainmenu_keyreleased
end
-- bgm = love.audio.newSource("art/music/default.mp3", "static")
-- bgm:play()
-- bgm:setLooping(true)
-- bgm:setVolume(1.5)
frontMenu = nil
frontMenu_init() selection = 1
frontMenu = makeMainMenu()
camera = stalker() camera = stalker()
end end
@ -113,8 +87,8 @@ function mainmenu_keyreleased(key)
end end
function frontMenu_init() function makeMainMenu()
frontMenu = Menu:new(100, 100, 30, 50, 3, { return Menu:new(100, 100, 30, 50, 3, {
{love.graphics.newText(a_ttf, "Local"), {love.graphics.newText(a_ttf, "Local"),
function () function ()
local lobbiest1 = LocalLobbiest:new(nil, KEYMAPS[1]) local lobbiest1 = LocalLobbiest:new(nil, KEYMAPS[1])
@ -123,86 +97,17 @@ function frontMenu_init()
end}, end},
{love.graphics.newText(a_ttf, "Quit"), {love.graphics.newText(a_ttf, "Quit"),
function () love.event.quit(0) end }}) function () love.event.quit(0) end }})
mapMenu = nil
end
-- PAUSE STATE
----------------------------------------
function pause_load()
if(bgm) then
bgm:stop()
end
mode = pause
end
function pause_update(dt)
end
function pause_draw ()
game_draw()
camera:detach()
love.graphics.draw(love.graphics.newText(r_ttf,
"paused\n[enter to continue]\n[escape to exit]"), 200, 200, 0, 3, 3)
camera:attach()
end
function pause_keypressed(key)
if (key == "return") then
if(bgm) then
bgm:play()
end
mode = game
elseif (key == "escape") then
mainmenu_load()
end
end
function pause_keyreleased(key)
end
-- GAMEOVER STATE
----------------------------------------
function gameover_load ()
mode = gameover
end
function gameover_update(dt)
end
function gameover_draw ()
game_draw()
camera:detach()
love.graphics.draw(love.graphics.newText(r_ttf,
"nice try!\n[enter to restart]\n[escape to exit]"), 200, 200, 0, 3, 3)
camera:attach()
end
function gameover_keypressed(key)
if (key == "return" or key == "space") then
camera:fade(.2, {0,0,0,1}, function() game_load() end)
elseif (key == "escape") then
mainmenu_load()
end
end
function gameover_keyreleased(key)
end end
-- GAME STATE -- GAME STATE
---------------------------------------- ----------------------------------------
function game_load(lobbiests) function game_load(lobbiests)
mode = game updateFunction = game_update
drawFunction = game_draw
keypressedFunction = game_keypressed
keyreleasedFunction = game_keyreleased
world:destroy() world:destroy()
world = wind.newWorld(0, 0, true) world = wind.newWorld(0, 0, true)
world:addCollisionClass('Fighter') world:addCollisionClass('Fighter')