A pong clone, but with a twist!
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

paddle.lua 1.7 KiB

há 4 anos
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. end
  17. function paddle:update(dt)
  18. if ((self.player == 1 and timeIsSlow2) or self.player == 2 and timeIsSlow) then
  19. self.dy = self.dy / 2
  20. end
  21. if (self.dy == 0) then
  22. self.velocity = self.velocity / 1.1
  23. if (self.velocity < 1 and self.velocity > -1) then
  24. self.velocity = 0
  25. end
  26. else
  27. self.velocity = self.velocity + self.dy*dt
  28. end
  29. if (self.velocity < 0) then
  30. if (self.y > 0) then
  31. self.y = self.y + self.velocity
  32. else
  33. self.velocity = 0
  34. end
  35. elseif (self.velocity > 0) then
  36. if (self.y < VIRTUAL_HEIGHT - 80) then
  37. self.y = self.y + self.velocity
  38. else
  39. self.velocity = 0
  40. end
  41. else
  42. self.velocity = 0
  43. end
  44. if ((timeIsSlow == false and self.player == 1) or (timeIsSlow2 == false and self.player == 2)) then
  45. if (math.abs(self.yx - self.y) < 11) then
  46. self.yx = self.y
  47. end
  48. if (self.yx < self.y) then
  49. self.yx = self.yx + math.abs(paddle_SPEED/1.7)
  50. elseif (self.yx > self.y) then
  51. self.yx = self.yx - math.abs(paddle_SPEED/1.7)
  52. end
  53. end
  54. end
  55. function paddle:render()
  56. love.graphics.setColor(self.RED, self.GREEN, self.BLUE, 60/255)
  57. love.graphics.rectangle('fill', self.xy, self.yx, self.width, self.height, 20, 20)
  58. love.graphics.setColor(self.RED, self.GREEN, self.BLUE, 255)
  59. love.graphics.rectangle('fill', self.x, self.y, self.width, self.height, 20, 20)
  60. love.graphics.setColor(255, 255, 255, 255)
  61. end