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.

92 lines
2.3 KiB

  1. paddle = Class{}
  2. function paddle:init(x, y, width, height, player)
  3. self.RED = 255
  4. self.GREEN = 255
  5. self.BLUE = 255
  6. self.x = x
  7. self.y = y
  8. self.width = width
  9. self.height = height
  10. self.dy = 0
  11. self.xy = x
  12. self.yx = y
  13. self.velocity = 0
  14. self.shadowbonus = 0
  15. self.player = player
  16. self.goal = -1
  17. end
  18. function paddle:update(dt)
  19. if self.goal ~= -1 then
  20. if self.y+self.height/2 - self.goal > 10 then
  21. self.dy = -paddle_SPEED
  22. elseif self.goal - (self.y+self.height/2) > 10 then
  23. self.dy = paddle_SPEED
  24. else
  25. self.dy = 0
  26. end
  27. end
  28. --love.window.setTitle(tostring(player1.velocity * dt) .. " " .. tostring(player1.dy) .. " " .. tostring(dt) )
  29. if areanuclear == 0 then
  30. self.RED = 1
  31. self.GREEN = 1
  32. self.BLUE = 1
  33. else
  34. self.RED = 0
  35. self.GREEN = 0
  36. self.BLUE = 0
  37. end
  38. if ((self.player == 1 and timeIsSlow2) or self.player == 2 and timeIsSlow) then
  39. self.dy = self.dy / 2
  40. end
  41. if (self.dy == 0) then
  42. self.velocity = self.velocity - (self.velocity - self.velocity / (1.4))*dt*20
  43. if (self.velocity*dt < 0.5 and self.velocity*dt > -0.5) then
  44. self.velocity = 0
  45. end
  46. else
  47. self.velocity = self.velocity + self.dy*7*dt
  48. end
  49. if (self.velocity < 0) then
  50. if (self.y > 0) then
  51. self.y = self.y + self.velocity * dt
  52. else
  53. self.velocity = 0
  54. end
  55. elseif (self.velocity > 0) then
  56. if (self.y < VIRTUAL_HEIGHT - 80) then
  57. self.y = self.y + self.velocity * dt
  58. else
  59. self.velocity = 0
  60. end
  61. else
  62. self.velocity = 0
  63. end
  64. if ((timeIsSlow == false and self.player == 1) or (timeIsSlow2 == false and self.player == 2)) then
  65. if (math.abs(self.yx - self.y) < 11) then
  66. self.yx = self.y
  67. end
  68. if (self.yx < self.y) then
  69. self.yx = self.yx + math.abs(paddle_SPEED/1.7) * 7 * dt
  70. elseif (self.yx > self.y) then
  71. self.yx = self.yx - math.abs(paddle_SPEED/1.7) * 7 * dt
  72. end
  73. end
  74. end
  75. function paddle:render()
  76. love.graphics.setColor(self.RED, self.GREEN, self.BLUE, 60/255)
  77. love.graphics.rectangle('fill', self.xy, self.yx, self.width, self.height, 20, 20)
  78. love.graphics.setColor(self.RED, self.GREEN, self.BLUE, 255)
  79. love.graphics.rectangle('fill', self.x, self.y, self.width, self.height, 20, 20)
  80. love.graphics.setColor(255, 255, 255, 255)
  81. end