padels wont stay on screen

having problems making them stay in the boundares of my screen, i also cant figure out how to get collision from my ball but ill try and figure that out myself, this on the other hand has had me stuck for the past 2 days and i really would like some help solving my problem =D



here are my current restraints for my paddles for the game pong that i am desiging in visual studio 2010.



if(leftpaddle_2y < 0)
leftpaddle_2y = 0;

if(leftpaddle_2x + 5 > 768)
leftpaddle_2x = 763;

if (rightpaddle_1y < 0)
rightpaddle_1y = 0;

now padels wont leave the top right and left corners of the screen but i cant get them to stay on the bottom right and left parts of the screen.

my variables for the paddles are as follows:

float rightpaddle_1x = 990;
float rightpaddle_1y = 20;
float leftpaddle_2x = 15;
float leftpaddle_2y = 450;
float ballrside = mballx + 40;
float position = 0;
float paddle_width = 5;
float paddle_length = 15;
float ball_width = 2.5;
float ball_length = 5;
Well that's because there doesn't appear to be a check for the bottom boundary against the y value of the paddles.

It'll depend on your window height, but it'll look something like this:

1
2
3
4
if (bottom_of_left_paddle > window_height)
{
   bottom_of_left_paddle = window_height;
}


Remember that in most 2D game coordinate systems, the y coordinates go from top to bottom.

Also, the check on the x value would appear redundant as, traditionally, pong paddles can only move up and down. The x coordinates should only really be relevant in ball collision.
Last edited on
cool thanks i fixed them now they stay on the screen =D

now all i have to do is figure out how to do collision and my game is done =D
Topic archived. No new replies allowed.