rune.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. local Rune = {}
  2. Rune.name = 'Rune'
  3. Rune.code = 'rune'
  4. Rune.width = 32
  5. Rune.height = 32
  6. Rune.effects = {'refillAmmo', 'refillHealth', 'speedBoost'}
  7. Rune.collision = {}
  8. Rune.collision.shape = 'rectangle'
  9. Rune.collision.tag = 'rune'
  10. Rune.collision.with = {
  11. player = function(self, other, dx, dy)
  12. if not self.timer and not other.ghosting then
  13. self.timer = 12
  14. self[self.effect](self, other)
  15. self:setEffect()
  16. end
  17. end
  18. }
  19. function Rune:activate()
  20. self.x = self.x - (self.width / 2)
  21. self.y = self.y - (self.height / 2)
  22. ctx.event:emit('collision.attach', {object = self})
  23. self.iterations = (self.x + self.y) / 2
  24. self:setEffect()
  25. if ctx.view then ctx.view:register(self) end
  26. end
  27. function Rune:update()
  28. self.timer = timer.rot(self.timer)
  29. if self.timer == 0 then self.timer = false end
  30. end
  31. function Rune:draw()
  32. if not self.timer then
  33. if self.effect == 'refillAmmo' then love.graphics.setColor(0, 150, 0, 100)
  34. elseif self.effect == 'refillHealth' then love.graphics.setColor(150, 0, 0, 100)
  35. elseif self.effect == 'speedBoost' then love.graphics.setColor(0, 0, 150, 100) end
  36. self.shape:draw('fill')
  37. if self.effect == 'refillAmmo' then love.graphics.setColor(0, 150, 0, 255)
  38. elseif self.effect == 'refillHealth' then love.graphics.setColor(150, 0, 0, 255)
  39. elseif self.effect == 'speedBoost' then love.graphics.setColor(0, 0, 150, 255) end
  40. self.shape:draw('line')
  41. if ctx.effects and ctx.effects:get('bloom') then
  42. ctx.effects:get('bloom'):render(function()
  43. if self.effect == 'refillAmmo' then love.graphics.setColor(100, 255, 100, 255)
  44. elseif self.effect == 'refillHealth' then love.graphics.setColor(255, 100, 100, 255)
  45. elseif self.effect == 'speedBoost' then love.graphics.setColor(100, 100, 255, 255) end
  46. love.graphics.rectangle('fill', self.x - 16, self.y - 16, self.width + 32, self.height + 32)
  47. end)
  48. end
  49. end
  50. end
  51. function Rune:setEffect()
  52. local l, h = love.math.getRandomSeed()
  53. love.math.setRandomSeed(math.floor(100000000 * love.math.noise(1111111 * self.iterations)), math.floor(100000000 * love.math.noise(self.x * self.iterations, self.y - self.iterations)))
  54. self.iterations = self.iterations + 1
  55. self.effect = self.effects[love.math.random(1, #self.effects)]
  56. love.math.setRandomSeed(l, h)
  57. end
  58. function Rune:refillAmmo(player)
  59. for i = 1, 5 do
  60. if player.slots[i].type == 'weapon' then
  61. f.exe(player.slots[i].refillAmmo, player.slots[i], player)
  62. end
  63. if ctx.id == player.id then
  64. ctx.event:emit('sound.play', {sound = 'reload', x = self.x, y = self.y})
  65. ctx.event:emit('particle.create', {
  66. kind = 'arcadetext',
  67. vars = {
  68. x = player.x,
  69. y = player.y,
  70. str = '+ammo'
  71. }
  72. })
  73. end
  74. end
  75. end
  76. function Rune:refillHealth(player)
  77. player.health = math.min(player.health + (player.maxHealth / 4), player.maxHealth)
  78. if ctx.id == player.id then
  79. ctx.event:emit('sound.play', {sound = 'reload', x = self.x, y = self.y})
  80. ctx.event:emit('particle.create', {
  81. kind = 'arcadetext',
  82. vars = {
  83. x = player.x,
  84. y = player.y,
  85. str = '+health'
  86. }
  87. })
  88. end
  89. end
  90. function Rune:speedBoost(player)
  91. ctx.buffs:add(player, 'runespeedboost')
  92. if ctx.id == player.id then
  93. ctx.event:emit('sound.play', {sound = 'reload', x = self.x, y = self.y})
  94. ctx.event:emit('particle.create', {
  95. kind = 'arcadetext',
  96. vars = {
  97. x = player.x,
  98. y = player.y,
  99. str = '+speed'
  100. }
  101. })
  102. end
  103. end
  104. return Rune