main.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. moonshine = require "moonshine"
  2. require "util"
  3. require "class"
  4. require "const"
  5. require "draw"
  6. require "tile"
  7. require "grid"
  8. require "player"
  9. require "bullet"
  10. require "pattern"
  11. require "goblin"
  12. require "world"
  13. require "title"
  14. require "graphics-settings"
  15. require "audio"
  16. function love.load()
  17. loadFont()
  18. love.keyboard.setKeyRepeat(true)
  19. if love.graphics.isSupported then
  20. canvasSupported = love.graphics.isSupported("canvas")
  21. else
  22. canvasSupported = true
  23. end
  24. if canvasSupported then
  25. canvas = love.graphics.newCanvas(WWIDTH, WHEIGHT)
  26. fx = moonshine(moonshine.effects.filmgrain)
  27. for i, v in ipairs(graphicsSettings) do
  28. fx.chain(moonshine.effects[v[3]])
  29. fx.disable(v[3])
  30. end
  31. end
  32. state = "title"
  33. render()
  34. end
  35. function love.draw()
  36. if canvasSupported then
  37. fx(function()
  38. love.graphics.draw(canvas, 0, 0)
  39. end)
  40. else
  41. if state == "play" then
  42. drawText(text, world.message)
  43. else
  44. drawText(text, "")
  45. end
  46. end
  47. end
  48. function love.textinput(key)
  49. for i = 1, 1 do
  50. if state == "title" then
  51. restart()
  52. state = "play"
  53. sounds.toggle:play()
  54. elseif state == "help" then
  55. state = "play"
  56. elseif state == "graphics" then
  57. graphicsSettings.update(KEYS[key])
  58. elseif state == "play" then
  59. if world.player.dead then
  60. if KEYS[key] == ACTION.RESTART then
  61. restart()
  62. end
  63. break
  64. end
  65. if KEYS[key] == ACTION.HELP then
  66. state = "help"
  67. break
  68. end
  69. if KEYS[key] == ACTION.GRAPHICS_SETTINGS then
  70. state = "graphics"
  71. break
  72. end
  73. if KEYS[key] then
  74. world:update(KEYS[key])
  75. end
  76. end
  77. end
  78. render()
  79. end
  80. function render()
  81. text = newGrid()
  82. if state == "title" then
  83. drawTitle(TITLE, text)
  84. elseif state == "help" then
  85. drawTitle(HELP, text)
  86. elseif state == "graphics" then
  87. graphicsSettings.render(text)
  88. elseif state == "play" then
  89. world:draw(text)
  90. end
  91. if canvasSupported then
  92. love.graphics.setCanvas(canvas)
  93. love.graphics.clear()
  94. if state == "play" then
  95. drawText(text, world:getFullMessage())
  96. else
  97. drawText(text, "")
  98. end
  99. love.graphics.setCanvas()
  100. end
  101. end
  102. function restart()
  103. world = World()
  104. render()
  105. end