I apologize, I am quite new to programming, I am trying to learn Lua for the sake of trying to make my on game on Core Games..
Code: Select all
function love.update(dt)
if gameState == 'play' then
-- detect ball collision with paddles, reversing dx if true and
-- slightly increasing it, then altering the dy based on the position of the ball
if ball:collides(player1) then
ball.dx = -ball.dx * 1.03
ball.x = player1.x + 5
-- line 83 -- > end?
-- keep velocity going in the same direction, but randomize it
if ball.dy < 0 then
ball.dy = -math.random(10, 150)
else
ball.dy = math.random(10, 150)
end
end
if ball:collides(player2) then
ball.dx = -ball.dx * 1.03
ball.x = player2.x - 4
-- keep velocity going in the same direction, but randomize it
if ball.dy < 0 then
ball.dy = -math.random(10, 150)
else
ball.dy = math.random(10, 150)
end
end
-- detect upper and lower screen boundary collision and reverse if collides
if ball.y <= 0 then
ball.y = 0
ball.dy = -ball.dy
end
end
-- -4 to account for the balls size
if ball.y >= VIRTUAL_HEIGHT - 4 then
ball.y = VIRTUAL_HEIGHT - 4
ball.dy = -ball.dy
end
end