25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.3 KiB

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