seed.lua 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. local seed = lib.object.create():include(lib.entity)
  2. seed.config = {
  3. speed = 500,
  4. gravity = 800,
  5. radius = 6,
  6. shape = 'circle'
  7. }
  8. function seed:init()
  9. self.position = {
  10. x = app.context.scene.width / 2,
  11. y = app.context.scene.height / 2,
  12. }
  13. self.collisions = app.context.collision:add(self)
  14. self.vz = -100
  15. self.speed = self.config.speed
  16. self.alpha = 1
  17. end
  18. function seed:bind()
  19. self.position.z = -30
  20. return {
  21. love.update
  22. :subscribe(function()
  23. self:moveInDirection(self.direction, self.speed)
  24. self.position.z = self.position.z + self.vz * lib.tick.rate
  25. if self.position.z > 0 then
  26. self.vz = self.vz * -.75
  27. self.speed = self.speed / 2
  28. if math.abs(self.vz) < 20 then
  29. self.position.z = 0
  30. self.vz = 0
  31. self.speed = 0
  32. lib.flux.to(self, .5, { alpha = 0 })
  33. :oncomplete(function()
  34. self:unbind()
  35. app.context:removeObject(self)
  36. end)
  37. end
  38. else
  39. self.vz = self.vz + self.config.gravity * lib.tick.rate
  40. end
  41. end),
  42. self.collisions
  43. :filter(function(other) return other.isMinion or other == app.context.objects.muju end)
  44. :filter(function() return self.speed > self.config.speed / 2 end)
  45. :subscribe(function(other)
  46. other:hurt(self.owner.config.damage, self.owner)
  47. self:unbind()
  48. app.context:removeObject(self)
  49. end),
  50. love.update
  51. :filter(self:wrap(self.isEscaped))
  52. :subscribe(self:wrap(self.remove)),
  53. app.context.view.draw
  54. :subscribe(function()
  55. local image = app.art.shadow
  56. local scale = g.imageScale(image, 24)
  57. g.white(60 * self.alpha)
  58. g.draw(image, self.position.x, self.position.y, self.direction, scale, scale, image:getWidth() / 2, image:getHeight() / 2)
  59. local image = app.art.seed
  60. local scale = g.imageScale(image, 16)
  61. g.white(255 * self.alpha)
  62. g.draw(image, self.position.x, self.position.y + self.position.z / 2, self.direction, scale, scale, image:getWidth() / 2, image:getHeight() / 2)
  63. return -self.position.y
  64. end)
  65. }
  66. end
  67. return seed