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

P#43428 2017-08-19 13:48 ( Edited 2017-08-21 07:40)

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
P#43431 2017-08-19 14:48 ( Edited 2017-08-19 18:48)

I am blind! :D

Really thanks :)

P#43505 2017-08-21 03:40 ( Edited 2017-08-21 07:40)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-20 03:42:08 | 0.006s | Q:12