A pong clone, but with a twist!
Você não pode selecionar mais de 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.

117 linhas
2.6 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. if self.disabled == false then
  93. self.x = self.x + ballSpeed * self.dx * dt
  94. self.y = self.y + ballSpeed * self.dy * dt
  95. end
  96. end
  97. function eball:render(color)
  98. if color == 'black' then
  99. love.graphics.setColor(0,0,0,1)
  100. love.graphics.rectangle('fill', self.x, self.y, self.width, self.height)
  101. elseif color == 'controlled' then
  102. love.graphics.rectangle('fill', self.x, self.y, self.width, self.height)
  103. else
  104. love.graphics.setColor(1,1,1,1)
  105. love.graphics.rectangle('fill', self.x, self.y, self.width, self.height)
  106. end
  107. end