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

prerenderpath.lua 3.1 KiB

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