You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.3 KiB

  1. ship = Class{}
  2. function ship:init()
  3. self.y = 0
  4. self.direction = love.math.random(0, 2)
  5. if self.direction == 0 then
  6. self.y = VIRTUAL_HEIGHT + 100
  7. self.image = love.graphics.newImage('img/SPC/blue_0' .. love.math.random(1,6) .. '.png')
  8. self.scroll = -1 * love.math.random(80, 120) - background_scroll_speed
  9. else
  10. self.y = -100
  11. self.image = love.graphics.newImage('img/SPC/red_0' .. love.math.random(1,6) .. '.png')
  12. self.scroll = love.math.random(80, 120) - background_scroll_speed
  13. end
  14. self.x = love.math.random(40, VIRTUAL_WIDTH - 40)
  15. self.width = self.image:getWidth()
  16. self.height = self.image:getHeight()
  17. self.destroyed = false
  18. self.deathCounter = 0
  19. self.deathNumber = 1
  20. end
  21. function ship:update(dt)
  22. --print("Width " .. self.width .. " Height: " .. self.height)
  23. if self.destroyed then
  24. self:deathanimation(dt)
  25. end
  26. self.y = self.y + self.scroll * dt
  27. --print("traveling at " .. self.y .. " " .. self.x)
  28. for i, ball in pairs(ball) do
  29. print("BALL IS AT: " .. ball.x .. " " .. ball.y)
  30. print("I AM AT " .. self.x .. " " .. self.y)
  31. if self:collides(ball) then
  32. print("KABOOM")
  33. self.destroyed = true
  34. end
  35. end
  36. end
  37. function ship:deathanimation(dt)
  38. self.deathCounter = self.deathCounter + dt
  39. if self.deathCounter > 0.1 and self.deathNumber < 12 then
  40. self.image = love.graphics.newImage('img/SPC/Explosion/explosion-' .. self.deathNumber .. '.png')
  41. self.deathCounter = 0
  42. self.deathNumber = self.deathNumber + 1
  43. end
  44. end
  45. function ship:collides(object)
  46. if (object.y > self.y and object.y < self.y + self.height and
  47. object.x > self.x and
  48. object.x < self.x + self.width ) then
  49. print("!!!!!!!!!!!!!" .. object.y .. " > " .. self.y .. " and " .. object.y .. " < " .. self.y + self.height .. " " .. object.x .. " > " .. self.x .. " and " .. object.x .. " < " .. self.x + self.width)
  50. return true
  51. else
  52. return false
  53. end
  54. print("Shit detection")
  55. end
  56. function ship:render()
  57. if self.direction ~= 0 then
  58. love.graphics.draw(self.image, self.x, self.y + self.height, 0, 1, -1)
  59. else
  60. love.graphics.draw(self.image, self.x, self.y)
  61. end
  62. end