A pong clone, but with a twist!
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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