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.

120 lines
2.8 KiB

  1. eball = Class{}
  2. function eball:init(x, y, width, height)
  3. self.x = x
  4. self.y = y
  5. self.width = width
  6. self.height = height
  7. self.dy = math.random(-1, 1)
  8. self.dx = 1
  9. self.disabled = false
  10. end
  11. function eball:collides(paddle)
  12. if paddle.player == 2 and gameMode == 'practice' then return false
  13. else
  14. if self.x > paddle.x + paddle.width or paddle.x > self.x + self.width then
  15. return false
  16. end
  17. if self.y > paddle.y + paddle.height or paddle.y > self.y + self.height then
  18. return false
  19. end
  20. return true
  21. end
  22. end
  23. function eball:reset(ballnum, player)
  24. if (gameMode == 'practice') then
  25. if (self.x < 1) then
  26. --love.window.setTitle(self.x)
  27. if not player then
  28. self.x = VIRTUAL_WIDTH /2 - 2
  29. elseif player == 1 then
  30. self.x = 50
  31. elseif player == 2 then
  32. self.x = VIRTUAL_WIDTH - 50
  33. else
  34. self.x = VIRTUAL_WIDTH /2 - 2
  35. end
  36. self.y = VIRTUAL_HEIGHT /2 - 2
  37. self.dy = math.random(-1, 1)
  38. self.dx = math.random(-1,1)
  39. else self.x = self.x self.y = self.y self.dx = -1 end
  40. else
  41. if (ballnum == 2) then
  42. self.dx = ball_DIR * -1
  43. else
  44. self.dx = ball_DIR
  45. end
  46. self.disabled = false
  47. if not player then
  48. self.x = VIRTUAL_WIDTH /2 - 2
  49. elseif player == 1 then
  50. self.x = 50
  51. elseif player == 2 then
  52. self.x = VIRTUAL_WIDTH - 50
  53. else
  54. self.x = VIRTUAL_WIDTH /2 - 2
  55. end
  56. self.y = VIRTUAL_HEIGHT /2 - 2
  57. self.dy = math.random(-1, 1)
  58. --love.window.setTitle("LMAOOOOOO")
  59. end
  60. end
  61. function eball:update(dt)
  62. if player1nukescore > 20 then
  63. potentialstrike1 = 1
  64. else
  65. potentialstrike1 = 0
  66. end
  67. if player1nukescore > 140 then
  68. player1reverbav = 1
  69. else
  70. player1reverbav = 0
  71. end
  72. if player1nukescore > 200 then
  73. potentialnuke1 = 1
  74. else
  75. potentialnuke1 = 0
  76. end
  77. if player2nukescore > 20 then
  78. potentialstrike2 = 1
  79. else
  80. potentialstrike2 = 0
  81. end
  82. if player2nukescore > 140 then
  83. player2reverbav = 1
  84. else
  85. player2reverbav = 0
  86. end
  87. if player2nukescore > 200 then
  88. potentialnuke2 = 1
  89. else
  90. potentialnuke2 = 0
  91. end
  92. --print("ATTEMP TO UPDATE BALL")
  93. if self.disabled == false then
  94. --print("BALL IS BEING AUTO-UPDATED" .. ballSpeed .. " " .. self.dx .. " " .. self.dy)
  95. self.x = self.x + ballSpeed * self.dx * dt
  96. self.y = self.y + ballSpeed * self.dy * dt
  97. end
  98. end
  99. function eball:render(color)
  100. if color == 'black' then
  101. love.graphics.setColor(0,0,0,1)
  102. love.graphics.rectangle('fill', self.x, self.y, self.width, self.height)
  103. elseif color == 'controlled' then
  104. love.graphics.rectangle('fill', self.x, self.y, self.width, self.height)
  105. else
  106. love.graphics.setColor(1,1,1,1)
  107. love.graphics.rectangle('fill', self.x, self.y, self.width, self.height)
  108. end
  109. end