main.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. -------------------------------------------------------------------------------
  2. -- Copyright (c) 2012 - Roland Yonaba
  3. -- Version : 0.0.2
  4. -------------------------------------------------------------------------------
  5. function love.load()
  6. require 'src.lib.math'
  7. require 'src.lib.table'
  8. require 'src.lib.audio'
  9. -- Config
  10. if not love.filesystem.exists('config.lua') then
  11. -- Default config
  12. Config = {}
  13. Config.fullscreen = false
  14. Config.vsync = false
  15. Config.music_volume = 0.5
  16. Config.sound_volume = 0.5
  17. table.serialize(Config,'config.lua')
  18. else
  19. -- Loading saved config
  20. Config = table.deserialize('config.lua')
  21. end
  22. -- Setting up display
  23. if love.graphics.setMode then
  24. love.graphics.setMode(
  25. love.graphics.getWidth(), love.graphics.getHeight(),
  26. Config.fullscreen, Config.vsync, 0
  27. )
  28. else
  29. local msaa = "msaa"
  30. if love._version_major == 0 and love._version_minor < 10 then
  31. msaa = "fsaa"
  32. end
  33. love.window.setMode(
  34. love.graphics.getWidth(), love.graphics.getHeight(),
  35. {fullscreen=Config.fullscreen, vsync=Config.vsync, [msaa]=0}
  36. )
  37. end
  38. -- Libs
  39. Asset = require 'src.assets'
  40. Input = require 'src.lib.input'
  41. StateManager = require 'src.lib.gamestate'
  42. -- Gamestates
  43. StateManager.states = {}
  44. StateManager.states.menu_state = require 'src.states.menu'
  45. StateManager.states.game_state = require 'src.states.game'
  46. StateManager.states.pause_state = require 'src.states.pause'
  47. StateManager.states.game_over_state = require 'src.states.gameover'
  48. StateManager.states.options_state = require 'src.states.options'
  49. -- state switching shortcut
  50. local old_statemanager_switch = StateManager.switch
  51. function StateManager.switch(state_name,...)
  52. return old_statemanager_switch(StateManager.states[state_name],...)
  53. end
  54. -- Override Löve callbacks with gamestates callbacks
  55. StateManager.registerEvents()
  56. -- Switch to menu state
  57. StateManager.switch('menu_state')
  58. end