Sure I find the game very interesting and all but I could use help with debugging my game
So here is the things that work:
- Ball colliding with top and bottom
Game resetting when you loose
Moving Player 1 with W and S
Moving Player 2 with Up and Down
Fun and (very strangely) interesting
- Ball coliding with paddles is very glitchy
The paddles go off screen but I don't think that is much of an issue
I'm mostly having trouble with the greater than less than
Code: Select all
function love.load()
piy = 85
piiy = 85
ballx = 139
bally = 99
ballgox = 0
ballgoy = 0
rngi = love.math.random(0,1)
rngii = love.math.random(0,1)
if rngi == 0 then
rngi = -1
end
if rngii == 0 then
rngii = -1
end
ballgox = rngi
ballgoy = rngii
end
function love.draw()
love.graphics.rectangle("fill", 10, piy, 5, 15)
love.graphics.rectangle("fill", 265, piiy, 5, 15)
love.graphics.rectangle("fill", ballx, bally, 2, 2)
end
function love.update(dt)
ballx = ballx + ballgox -- movement --
bally = bally + ballgoy
if love.keyboard.isDown("up") then
piiy = piiy - 2
elseif love.keyboard.isDown("down") then
piiy = piiy + 2
end
if love.keyboard.isDown("w") then
piy = piy - 2
elseif love.keyboard.isDown("s") then
piy = piy + 2
end
if bally <= 0 then -- colliding with bounds --
ballgoy = 1
elseif bally >= 200 then
ballgoy = -1
end
if ballx <= 0 or ballx >= 280 then -- going off screen! --
ballx = 139
bally = 99
love.time.sleep(0.1)
end
if piy >= bally and bally >= piy + 15 then -- collisions with paddles (the broken part) --
ballgox = -1
end
if piiy >= bally and bally >= piiy + 15 then
ballgox = 1
end
end
Code: Select all
function love.conf(t)
t.window.width = 280
t.window.height = 200
t.title = "Pong?"
end
if var1 <= var2 >= var3 then
instead of
if var1 <= var2 and var2 >= var3 then
Any help with shortening the code or helping with the game collisions would be gladly appreciated!