Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

118 řádky
2.9 KiB

  1. ship = Class{}
  2. function ship:init(x, y, image)
  3. self.x = x
  4. self.y = y
  5. self.ox = x
  6. self.oy = y
  7. self.dy = 0
  8. self.dx = 5
  9. self.speed = 1
  10. self.image = love.graphics.newImage(image)
  11. self.width = self.image:getWidth()
  12. self.height = self.image:getHeight()
  13. self.rotation = 1.5708
  14. self.vector = 1.5708
  15. self.color = {1,1,1,1}
  16. self.path = {}
  17. self.dottimer = 0.5
  18. self.fuel = 0
  19. end
  20. function ship:newPathDot(dotx, doty)
  21. return {
  22. x = dotx,
  23. y = doty
  24. }
  25. end
  26. function ship:update(dt)
  27. if not shipIsHit then
  28. self.dottimer = self.dottimer - dt
  29. if self.dottimer < 0 then
  30. table.insert(self.path, self:newPathDot(self.x, self.y))
  31. self.dottimer = 0.2
  32. end
  33. if love.timer.getFPS() < 20 then
  34. self.path = {}
  35. end
  36. self.x = self.x + self.dx*self.speed/2
  37. self.y = self.y + self.dy*self.speed/2
  38. if self.dx ~= 0 then
  39. self.vector = math.atan( self.dy/ self.dx)
  40. end
  41. --[[if love.keyboard.isDown('s') then
  42. self.speed = math.sqrt(self.dx^2 + self.dy^2)
  43. if self.speed > 0 then
  44. self.speed = self.speed - 0.5
  45. end
  46. self.dx = math.cos(self.vector) * self.speed
  47. self.dy = math.sin(self.vector) * self.speed
  48. end ]]--
  49. if love.keyboard.isDown('w') and self.fuel > 0 then
  50. self.fuel = self.fuel - 0.5
  51. self.speed = self.speed + 0.05
  52. end
  53. --[[
  54. if love.keyboard.isDown('left') then
  55. self.dx = self.dx - 0.5
  56. end
  57. if love.keyboard.isDown('right') then
  58. self.dx = self.dx + 0.5
  59. end
  60. if love.keyboard.isDown('up') then
  61. self.dy = self.dy - 0.5
  62. end
  63. if love.keyboard.isDown('down') then
  64. self.dy = self.dy + 0.5
  65. end
  66. ]]--
  67. --print(self.speed)
  68. --[[
  69. if love.keyboard.isDown('right') then
  70. self.rotation = self.rotation + 10
  71. elseif love.keyboard.isDown('left') then
  72. self.rotation = self.rotation - 10
  73. end]]--
  74. --print("rotation:" .. self.rotation)
  75. --print("speed:" .. self.dx .. " " .. self.dy)
  76. if self.dx < 0 then
  77. self.vector = self.vector - 3.14159
  78. end
  79. self.vector = self.vector + 1.5708
  80. end
  81. end
  82. function ship:draw()
  83. -- Draw the `self.canvas` to screen
  84. love.graphics.setColor(unpack(self.color))
  85. --print("DAW" .. camera.x)
  86. love.graphics.draw(self.image, self.x, self.y, self.vector, 1, 1, self.width/2, self.height/2)
  87. for i in ipairs(self.path) do
  88. if i > 1 then
  89. love.graphics.setColor(0.9,0.9,0.9,1)
  90. --print("DOING".. i)
  91. love.graphics.line(self.path[i].x, self.path[i].y, self.path[i-1].x, self.path[i-1].y)
  92. end
  93. end
  94. love.graphics.setColor(1,1,1,1)
  95. end
  96. function ship:reset()
  97. self.x = self.ox
  98. self.y = self.oy
  99. self.dy = 0
  100. self.dx = 5
  101. self.rotation = 1.57
  102. self.canvas = love.graphics.newCanvas(WINDOW_WIDTH, WINDOW_HEIGHT)
  103. self.vector = 1.56
  104. self.speed = 1
  105. self.path = {}
  106. self.dottimer = 0.5
  107. end