Log In  


Hi all!

I've completed a very basic implementation of Pong.

I would like to make it nicer adding a classic mode that looks and plays as close to the original as possible.

To do so I'd need, for starters, to increase my paddles speed but when I do so the paddles end out of the screen.

I cannot understand why, this is the code causing the issue, it is very simple:

 -- check if pad goes out of the upper part of the screen
  if button_up and pad.y > game.upper_bound then
   pad.y-=1
  elseif button_up and pad.y <= game.upper_bound then
   pad.y=game.upper_bound
  end
 -- check if paddle goes out of the bottom parte of the screen
  if button_down and pad.y + pad.h < game.lower_bound then
   pad.y+=1
  elseif button_down and pad.y + pad.h > game.lower_bound then
   pad.y=game.lower_bound
  end

If instead of using 1 I use 2 or more the paddles get out of bounds (or start shaking).

In case you want to check the complete code you can find it here:
https://www.lexaloffle.com/bbs/?tid=29815



I think all you need to do is to change this,

pad.y=game.lower_bound

to this,

pad.y=game.lower_bound-pad.h

I am blind! :D

Really thanks :)



[Please log in to post a comment]