Advertisement

collision help

Started by November 19, 2004 06:34 PM
10 comments, last by cplus programmer 19 years, 9 months ago
I need to detect colision of a ball and a paddle for a game of pong, I have tried sooo much and it wont work, here are the dementons: paddle: 50,170 ball: 52,52 xpos,ypos: the x and y position of the paddle bxpos,bypos: the x and y of the ball | |^ |y | | | | x-> -------------------- everything I do bounces off the very top and above the paddle, or it doesnt care if the paddle is there, it will bounce, anyonw know that the if statment should be?
there are 10 types of people in this world, those who can do bianary and those who cant.
Hows about you post the code you're using so far?

Jesus saves ... the rest of you take 2d4 fire damage.

Advertisement
if (bxpos>750 && bypos <= (ypos + 171) && bypos <=ypos)
there are 10 types of people in this world, those who can do bianary and those who cant.
  if(bypos < ypos + 50 && bypos + 170 > ypos)      // collision!!1

Try that. [smile]

[Edited by - 23yrold3yrold on November 19, 2004 8:13:20 PM]

Jesus saves ... the rest of you take 2d4 fire damage.

wont collide
there are 10 types of people in this world, those who can do bianary and those who cant.
Well it bloody should. Are you checking the xposition too? Maybe we need to see more code.

EDIT: Corrected a stupid typo in my earlier code post. If you copied and pasted without reading it, shame on you and try again. [wink]

Jesus saves ... the rest of you take 2d4 fire damage.

Advertisement
here is relevant code

void pong::hit(){       if(bypos < ypos + 50 && bypos + 170 > ypos)    {        bspeed = -bspeed;        buspeed = -buspeed;    }}//init stuff    xpos=800;    ypos=150;     bxpos = 250;    bypos = 300;    bspeed = 6;    buspeed = 0;
there are 10 types of people in this world, those who can do bianary and those who cant.
How are you using it? I don't see a check for the x position. Dunno what the speeds are for either (I can assume one of them is the ball's x velocity).

Jesus saves ... the rest of you take 2d4 fire damage.

there is bspeed ans buspeed, at before it draws it goes:
bxpos +=bspeed;
bypos +=buspeed;

speed is always 6 and uspeed is 4-7, bspeed is the x speed, buspeed is the y's
there are 10 types of people in this world, those who can do bianary and those who cant.
Oh, crap. I mixed up your variable names; I thought b*pox was for the block/paddle.

  if(ypos < bypos + 50 && ypos + 170 > bypos)      // collision!!1

That might work better.

Jesus saves ... the rest of you take 2d4 fire damage.

This topic is closed to new replies.

Advertisement