Sign in to follow this  
phil67rpg

4-way pong

Recommended Posts

cNoob    295
Well you could try something like this.

First you will need a few variables

int ball_x = 200; // Change this to where ever the xpos is needed
int ball_y = 200; // Change this to where ever the ypos is needed
int ball_vx = -4; // you can mess with these values
int ball_vy = -4;



Now in your main loop

ball_x += ball_vx;
ball_y += ball_yx;
// Now Draw Ball

// checking for collision with walls
// Bounces ball of the left wall
if(ball_x <= 0)
ball_xv = -ball_xv;

// bounces ball of top wall
if(ball_y <= 0)
ball_yv = -ball_yv;

// Bounces ball of the right wall
if(ball_x+ball_width >= screen_width) // substitute screen_width & ball_width valuesball_xv = -ball_xv; // with there real values

// bounces ball of bottom wall
if(ball_y+ball_height >= screen_height)//substitute screen_height & ball_height
ball_yv = -ball_yv; // with there real values



This should Draw Your ball and bounce of each side of your window.

Share this post


Link to post
Share on other sites
I am not to advanced as yet in programming(not up to graphical lvl yet), but for AI I believe you could have the paddles follow the ball with a 'rand() % 50) + 1;' to give it the chance of missing. The '50' being pixels, if the paddle was, say twenty pixels long, giving it a fifteen pixel overspill on each side.
Someone (I forgot who) once suggested to give the ball one speed (say ten pixels a second) and the paddles a slightly slower speed (say eight pixels a second) so that the computer wouldn't always have enough time to make it to the ball. I suggest you grab the top two ideas and alter them until they seem to work for four paddles. And that should do it for AI.

[edit] I wouldn't know how to implement this though; so sorry I can't be of more help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this