map.lua 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. Map = class()
  2. local g = love.graphics
  3. Map.width, Map.height = 1067, 600
  4. Map.depth = -100
  5. function Map:init()
  6. self.groundHeight = 132
  7. self.spiritAlpha = 0
  8. if ctx.view then
  9. ctx.view.xmax = self.width
  10. ctx.view.ymax = self.height
  11. ctx.view.x = self.width / 2 - ctx.view.width / 2
  12. end
  13. self.background = {
  14. depth = 10,
  15. draw = function()
  16. local alpha = 255 * self.spiritAlpha
  17. local p = ctx.player
  18. alpha = lume.lerp(alpha, (1 - (p.healthDisplay / p.maxHealth)) * 255, .9)
  19. g.setColor(255, 255, 255)
  20. local image = data.media.graphics.map[ctx.biome .. 'Background']
  21. local image = data.media.graphics.map[ctx.biome]
  22. local scale = self.height / image:getHeight()
  23. g.draw(image, 0 * scale, 0 * scale, 0, scale, scale)
  24. g.setColor(255, 255, 255, alpha)
  25. local image = data.media.graphics.map[ctx.biome .. 'BackgroundSpirit']
  26. local image = data.media.graphics.map[ctx.biome .. 'Spirit']
  27. local scale = self.height / image:getHeight()
  28. g.draw(image, 0 * scale, 0 * scale, 0, scale, scale)
  29. end
  30. }
  31. self.foreground = {
  32. depth = -50,
  33. draw = function()
  34. if ctx.biome == 'forest' then
  35. local image = data.media.graphics.map.forestForeground
  36. local scale = self.height / data.media.graphics.map[ctx.biome]:getHeight()
  37. g.setColor(255, 255, 255)
  38. g.draw(image, 0, self.height - image:getHeight() * scale, 0, scale, scale)
  39. end
  40. local image = data.media.graphics.map.grass
  41. local scale = self.height / data.media.graphics.map[ctx.biome]:getHeight()
  42. local shearx = math.sin(tick / 100) * math.cos(tick / 60) ^ 2 * .08
  43. g.setColor(0, 0, 0, 80)
  44. g.draw(image, self.width / 2 - 10, self.height, 0, scale * 1, scale * 1.2, image:getWidth() / 2, image:getHeight(), shearx / 2)
  45. g.setColor(200, 200, 200, 255)
  46. g.draw(image, self.width / 2, self.height, 0, scale, scale, image:getWidth() / 2, image:getHeight(), shearx)
  47. local alpha = self.spiritAlpha * 255
  48. local p = ctx.player
  49. alpha = lume.lerp(alpha, (1 - (p.healthDisplay / p.maxHealth)) * 255, .5)
  50. g.setColor(200, 200, 200, alpha)
  51. g.draw(data.media.graphics.map.spiritGrass, self.width / 2, self.height, 0, scale, scale, image:getWidth() / 2, image:getHeight(), shearx)
  52. end
  53. }
  54. ctx.event:emit('view.register', {object = self.background})
  55. ctx.event:emit('view.register', {object = self.foreground})
  56. end
  57. function Map:update()
  58. self.spiritAlpha = lume.lerp(self.spiritAlpha, ctx.player.dead and 1 or 0, .6 * ls.tickrate)
  59. if love.math.random() < 4 * ls.tickrate then
  60. ctx.particles:emit('firefly' .. love.math.random(1, 3), ctx.map.width / 2, ctx.map.height / 2, 1)
  61. end
  62. end