Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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