game.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. Game = class()
  2. function Game:load()
  3. self.paused = false
  4. self.ded = false
  5. self.view = View()
  6. self.environment = Environment()
  7. self.foreground = Foreground()
  8. self.enemies = Enemies()
  9. self.minions = Minions()
  10. self.player = Player()
  11. self.shrine = Shrine()
  12. self.jujus = Jujus()
  13. self.particles = Particles()
  14. self.effects = Effects()
  15. self.effects:add(Vignette)
  16. self.effects:add(Bloom)
  17. self.effects:add(Wave)
  18. self.effects:add(DeathBlur)
  19. self.hud = Hud()
  20. self.upgrades = Upgrades
  21. self.upgrades:clear()
  22. self.target = Target()
  23. self.sound = Sound()
  24. self.sounds = {
  25. background = 'background',
  26. summon1 = 'summon1',
  27. summon2 = 'summon2',
  28. summon3 = 'summon3',
  29. spirit = 'spirit',
  30. juju1 = 'juju1',
  31. juju2 = 'juju2',
  32. juju3 = 'juju3',
  33. juju4 = 'juju4',
  34. juju5 = 'juju5',
  35. juju6 = 'juju6',
  36. juju7 = 'juju7',
  37. juju8 = 'juju8',
  38. combat = 'combat',
  39. death = 'death',
  40. menuClick = 'menuClick',
  41. youlose = 'youlose'
  42. }
  43. backgroundSound = self.sound:loop({sound = self.sounds.background})
  44. love.audio.setPosition(love.graphics.getWidth() / 2, love.graphics.getHeight() / 2, love.graphics.getHeight() / 2)
  45. love.keyboard.setKeyRepeat(false)
  46. end
  47. function Game:update()
  48. if self.hud.upgrading or self.paused or self.ded then
  49. self.player.prevx = self.player.x
  50. self.player.prevy = self.player.y
  51. if self.player.ghost then
  52. self.player.ghost.prevx = self.player.ghost.x
  53. self.player.ghost.prevy = self.player.ghost.y
  54. end
  55. self.hud:update()
  56. if self.ded then self.effects:get(DeathBlur):update() end
  57. return
  58. end
  59. self.enemies:update()
  60. self.minions:update()
  61. self.player:update()
  62. self.shrine:update()
  63. self.jujus:update()
  64. self.view:update()
  65. self.hud:update()
  66. self.effects:update()
  67. self.particles:update()
  68. self.environment:update()
  69. self.foreground:update()
  70. end
  71. function Game:unload()
  72. backgroundSound:stop()
  73. end
  74. function Game:draw()
  75. self.view:draw()
  76. end
  77. function Game:resize()
  78. self.view:resize()
  79. self.effects:resize()
  80. end
  81. function Game:keypressed(key)
  82. if not self.ded then
  83. if (key == 'p' or key == 'escape') and not self.hud.upgrading then self.paused = not self.paused
  84. elseif key == 'm' then self.sound:mute()
  85. elseif key == 'f' then love.window.setFullscreen(not love.window.getFullscreen()) end
  86. end
  87. if self.hud.upgrading or self.paused or self.ded then return self.hud:keypressed(key) end
  88. self.hud:keypressed(key)
  89. self.player:keypressed(key)
  90. end
  91. function Game:keyreleased(...)
  92. if self.hud.upgrading or self.paused or self.ded then return self.hud:keyreleased(...) end
  93. end
  94. function Game:textinput(char)
  95. self.hud:textinput(char)
  96. end
  97. function Game:mousepressed(...)
  98. if self.hud.upgrading or self.paused or self.ded then return self.hud:mousepressed(...) end
  99. end
  100. function Game:mousereleased(...)
  101. if self.hud.upgrading or self.paused or self.ded then return self.hud:mousereleased(...) end
  102. end
  103. function Game:gamepadpressed(gamepad, button)
  104. if button == 'start' or button == 'guide' then self.paused = not self.paused end
  105. if self.hud.upgrading or self.paused or self.ded then return self.hud:gamepadpressed(gamepad, button) end
  106. self.hud:gamepadpressed(gamepad, button)
  107. self.player:gamepadpressed(gamepad, button)
  108. end