In my breakout game, I have a slight problem with the direction...
When the ball comes towards the ball, lets say with f(x)=-2x, and the ball hits the paddle on the far most left side, I want the ball to go back in the same direction, but I have found that kinda tricky!
Anyone know how to do this???
I know it has something to do with inverse function....But how to express it, I dont know....
Last edited by CyberCarsten; Oct 4th, 2003 at 05:12 AM.
192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
Posts
3,051
Not sure exactly how you're doing the velocity of the ball, but to get it to bounce like that, just invert the horizontal element (multiply by -1).
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
Posts
3,051
Could you post your move_bob code please?
P.S. I take it ball.xv and ball.yv are the horizontal and vertical speeds of the ball respectivly.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
int Move_BOB(BOB_PTR bob)
{
// this function moves the bob based on its current velocity
// also, the function test for various motion attributes of the'
// bob and takes the appropriate actions
// is this a valid bob
if (!bob)
return(0);
// translate the bob
bob->x+=bob->xv;
bob->y+=bob->yv;
// test for wrap around
if (bob->attr & BOB_ATTR_WRAPAROUND)
{
// test x extents first
if (bob->x > max_clip_x)
bob->x = min_clip_x - bob->width;
else
if (bob->x < min_clip_x-bob->width)
bob->x = max_clip_x;
// now y extents
if (bob->x > max_clip_x)
bob->x = min_clip_x - bob->width;
else
if (bob->x < min_clip_x-bob->width)
bob->x = max_clip_x;
} // end if
else
// test for bounce
if (bob->attr & BOB_ATTR_BOUNCE)
{
// test x extents first
if ((bob->x > max_clip_x - bob->width) || (bob->x < min_clip_x) )
bob->xv = -bob->xv;
// now y extents
if ((bob->y > max_clip_y - bob->height) || (bob->y < min_clip_y) )
bob->yv = -bob->yv;
} // end if
// return success
return(1);
} // end Move_BOB
P.S. I take it ball.xv and ball.yv are the horizontal and vertical speeds of the ball respectivly.
192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
Posts
3,051
Is the problem that the ball is wrapping off the screen first? because this will happen if it's moving faster than its width.
The problem may also be that the ball gets 'stuck' constantly changing it's direction, so solve this do seperate checks for the left and right edges using xv = abs(xv) and xv = -abs(xv) respectivly (assuming abs is a valid function that gets the modulus of it's parameter).
Regarding bouncing off the players pad, check the x location of the ball, in relation to the middle of the pad, then if it's far-enough away (yet still hits the pad), then invert the x and y velocities of the ball).
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Thank you for your reply
It only bounces if the BOB (Blitter object) was created with BOB_ATTR_BOUNCE.
&ball is not created with this parameter.....
Where should I use the abs function??
Last edited by CyberCarsten; Oct 4th, 2003 at 05:59 AM.
192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
Posts
3,051
Did you try changing the xv values using the abs function?
What happens at the moment? Does the ball just continue off the edge of the screen?
Assuming you understood what i've ment, i can't see how it wouldn't work unless there's something wrong somewhere else.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
The bounce of the wall worked perfect from the beginning, also bouncing of blocks, its just when the ball hits the paddle on the far left and right side it should bounce back in the same direction that it came in with....
I didn't quite understand where to put the abs function.....
// the ball has hit the paddle
if(Collision_BOBS(&ball,&paddle)){
if(ball.x == paddle.x && paddle.x <=19) { // Hits paddle on far left
xangle = xangle *(-1);
}
if(ball.x > 59 && paddle.x <=74){ // Hits paddle on far right
xangle = xangle *(-1);
}
yangle = -yangle;
}
Where I have set ball.xv and ball.yx to xangle and yangle respectivily.
192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
Posts
3,051
Try this:
PHP Code:
if(Collision_BOBS(&ball,&paddle)){
if(abs(ball.x-(paddle.x+paddle.width/2)) > (paddle.width/4)) { // Hits paddle on far left or the far right
if(ball.x<(paddle.x+paddle.width/2) { //it hit the left
xangle = -abs(xangle);
}
else { //it hit the right
xangle = abs(xangle);
}
}
yangle = -abs(yangle); //assuming -ve velocity is up
}
P.S. sorry for the late reply.
Last edited by SLH; Oct 4th, 2003 at 06:41 AM.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Hi again
It works when the ball hits the left side of the paddle, but when it hits the right side it either goes right trough the paddle or goes in the oppisite direction....
192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
Posts
3,051
Is the ball very wide (relative to it's velocity/the paddle?) if so then doing the following *may* fix it. If not then i'm not sure of the problem, because i'm pretty sure the code i gave should work.
change ball.x to ball.x+ball.width/2
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
Posts
3,051
Could you put a breakpoint in here:
if(ball.x<(paddle.x+paddle.width/2) { //it hit the left
and here:
xangle = abs(xangle);
then tell me whether the code gets to them both successfully when the ball should bounce of the right of the pad (the ball has to be in the far right quarter of the pad). I'm really stumpped here though.
EDIT: changed the first breakpoint, i copyed the wrong one by mistake.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
Posts
3,051
In MS Visual C++ you move the cursor to the line of code, and press F9. Then run the project (F5 not ctrl-F5).
If you want to upload your project i could have a look at it for you.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
Posts
3,051
Ok, i'll have a look at it when i have a moment.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
Posts
3,051
I'd need the bitmaps as well.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
Posts
3,051
Ok, i've had a look at it but couldn't get it to compile. I've had a look at your code, and the only thing that *may* be the problem is with your Collision_BOBS code. I'm not too sure how it works, so it may be perfectly fine though.
Here's code i'd use though.... (not syntactically tested)
PHP Code:
int Collision_BOBS(BOB_PTR bob1, BOB_PTR bob2)
{
// are these a valid bobs
if (!bob1 || !bob2)
return(0);
// test if rects overlap
if (bob1->x <= (bob2->x+bob2->width))
if ((bob1->x+bob1->width) >= bob2->x)
if (bob1->y <= (bob2->y+bob2->height))
if ((bob1->y+bob1->height) >= bob2->y)
return(1);
// if we got here then there's no collision
return(0);
} // end Collision_BOBS
Sorry i can't be of more help. It would be useful if you could work out how to add breakpoints and tell me the results (as i can't because i can't compile the project).
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
Posts
3,051
How did you compile? You need to "Start Debug" (pressing F5 in MS Visual C++).
I don't think a straight compile will stop at breakpoints. To test if the breakpoints are working just put one on a line you *know* will get excecuted.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
Posts
3,051
Sorry, but i have no idea what could be wrong. If your program doesn't stop at breakpoints then it's very hard to work out what's wrong with your code.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons