A pong clone, but with a twist!
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

eball.lua 2.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. self.x = VIRTUAL_WIDTH /2 - 2
  48. self.y = VIRTUAL_HEIGHT /2 - 2
  49. self.dy = math.random(-1, 1)
  50. --love.window.setTitle("LMAOOOOOO")
  51. end
  52. end
  53. function eball:update(dt)
  54. if player1nukescore > 20 then
  55. potentialstrike1 = 1
  56. else
  57. potentialstrike1 = 0
  58. end
  59. if player1nukescore > 140 then
  60. player1reverbav = 1
  61. else
  62. player1reverbav = 0
  63. end
  64. if player1nukescore > 200 then
  65. potentialnuke1 = 1
  66. else
  67. potentialnuke1 = 0
  68. end
  69. if player2nukescore > 20 then
  70. potentialstrike2 = 1
  71. else
  72. potentialstrike2 = 0
  73. end
  74. if player2nukescore > 140 then
  75. player2reverbav = 1
  76. else
  77. player2reverbav = 0
  78. end
  79. if player2nukescore > 200 then
  80. potentialnuke2 = 1
  81. else
  82. potentialnuke2 = 0
  83. end
  84. if self.disabled == false then
  85. self.x = self.x + ballSpeed * self.dx * dt
  86. self.y = self.y + ballSpeed * self.dy * dt
  87. end
  88. end
  89. function eball:render(color)
  90. if color == 'black' then
  91. love.graphics.setColor(0,0,0,1)
  92. love.graphics.rectangle('fill', self.x, self.y, self.width, self.height)
  93. elseif color == 'controlled' then
  94. love.graphics.rectangle('fill', self.x, self.y, self.width, self.height)
  95. else
  96. love.graphics.setColor(1,1,1,1)
  97. love.graphics.rectangle('fill', self.x, self.y, self.width, self.height)
  98. end
  99. end