Leaving Cplusplus.com

Pages: 1... 678
Bwahahahahaahaahahaha.

BHX... do you realize you linked to some porn video at the end of your Nov 21 source code paste?

bwahahahahahahaha
So glad I did not click it, then o_o
I do? Really? Must have been a good one for me to include it in the source code (though I think it actually always links to a broken link). If it is the link I think it is, it was an April Fool's link that links to a porn site, but goes to a broken link and no video. Can't recall what forum I got it off of though.

@L B: The YT video shows the bug, if you manage to catch the ball (whether it be primitive or image) at the top or bottom corner of the paddle it vibrates along the height of the paddle. I've heard this is a common bug, but I take programming serious and refuse to let any bug stay in my code once I find out about it. Sadly, in 10 years I've found tons of reports of the same bug, but no solid solution for it yet that actually fixes it rather than ignores it.
Last edited on by closed account z6A9GNh0
Wow threads here change topic fast. From a sad comical sob story to a blazing argument to a lot of talk about thread death and now an actual thread that might help someone.

@Disch If I click his link, will the video start playing, or is there another link inside his paste bin link?
I just followed the link. Apparently that particular video was deleted. Still funny though.

Also yeah, what's the bug? Is it that "getting trapped in the paddle" thing?
If I remember correctly it is that paddle tapping thing. Although I though people helped him with that long time ago.
Last edited on
Took out the link. Think I used it as an April Fool's on Allegro or something and just forgot it was in my code. I'm bad about that, putting links I find interesting in my code (had on project where the last of the code was actually gamasutra article links I liked).

Yeah, the getting trapped in the paddle is the bug I have had no luck finding a solid solution for.

@Script Coder I just have that affect on people I guess.
Yeah, the getting trapped in the paddle is the bug I have had no luck finding a solid solution for.


It's pretty simple.

When the ball connects with the paddle, you negate the ball's velocity.

What's happening is the ball is connecting with the paddle deeper than it can escape... so it just keeps negating the velocity over and over, keeping it in more or less the same position.

For example:

1
2
3
4
5
6
7
8
- assuming the left paddle spans from x=0 to x=10
- assuming x velocity = -4
- assuming ball is at x=8, but is not contacting the paddle (paddle is above or below the ball)

- ball moves to x=4, and is now contacting the paddle, so velocity is inverted (now +4)
- ball moves to x=8, and is STILL contacting the paddle (Even though it is moving away
    from it), so velocity is inverted (now -4)
- rinse, repeat -- ball shakes.


There are 2 very simple fixes:

1) Either have the left paddle always push the ball right (rather than negate the velocity)

or

2) Only negate the velocity if the ball is heading towards the paddle.


Solution 1 is easier, so that's what I did here. For your Apr 4 code:

1
2
3
4
5
6
7
8
9
            if(pad1X + padW > ballX && pad1Y < ballY + BSIZE && pad1Y + padH > ballY)
            {
                xVel = std::abs(xVel);  // <- bounce ball to the right
            }
 
            if(pad2X < ballX + BSIZE && pad2Y < ballY + BSIZE && pad2Y + padH > ballY)
            {
                xVel = -std::abs(xVel);  // <- bounce ball to the left
            }


Granted I didn't test this solution because I don't have allegro installed -- but I still don't see how this could have taken 10 years to solve =x
Last edited on
I played with the code a little before I saw Disch's post and came up with this, the condition is ugly but the bug seems harder to reproduce with it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// collision detection            
            if(pad1X < ballX && pad1X + padW > ballX)
            {
                if((pad1Y > ballY && pad1Y < ballY + BSIZE) ||
                    (pad1Y + padH > ballY && pad1Y < ballY + BSIZE))
                {
                    xVel = -xVel;                
                }
            }            
            if(pad2X > ballX && pad2X < ballX + BSIZE)
            {
                if((pad2Y > ballY && pad2Y < ballY + BSIZE) ||
                    (pad2Y + padH > ballY && pad2Y < ballY + BSIZE))
                {
                    xVel = -xVel;               
                }
            }

Note: Top and bottom paddle collisions still need work.

Took maybe an hour including installing Allegro (which required compiling it) and debugging.
Last edited on
Disch wrote:
Granted I didn't test this solution because I don't have allegro installed -- but I still don't see how this could have taken 10 years to solve =x

Googling the error returned tons of sites where people had the same problem, but none of them had a solution. Also, you have to realize that I only worked on finding the solution after I was in between projects. The only solution I was given, which used abs(), but it was on the paddle and somehow just basically ignored that the ball was even connecting with the top/bottom of the paddle, but I felt like I was pulling a Kobayashi Maru if I just ignored the collision.

Disch's method worked perfectly. Thank you both for helping.

@Disch I can't believe the solution hasn't been published in 10 years after so many people having the same issue with their pong clone.
@Framework, okay, I see how you meant different things now. Still, do you not believe that, at the most primitive level, how you act/don't act on (a better way to say "manage") your feelings affects the way you feel next?, or that you can talk yourself into certain moods (e.g. indifference is very easy to get yourself into)? Even if you find that you have no control over what you feel, don't just assume that it's impossible. Like any other part of your body, your brain can (and should), to some extent, be trained

If John insults Jane which makes her feel bad, it's Jane's fault that she feels bad?
I assume it's the use of words "fault", "blame" that's the problem. If John throws a rock at Jane, it's Johns fault if she gets injured, but she could have dodged it and most insults (unless they come from close friends) are very easy to dodge.
@BHXSpector this is really the bug you couldn't solve? Simple logic oversight? I've made pong one too many times in various software and languages (even in Scheme) and that bug has always been a simple fix like Disch said :p
Why wasn't a fix or a bit of code that ignores the problem too ugly to bare? was it the principle? you wanted a code to work flawlessly?
@devonrevenge Please don't mention "ignore" and "problem" in the same sentence in the proximity of BHX.
I may not be a great programmer, but that is one thing I pride myself on, I won't leave a single bug in the code. I have to find a solution for every bug and problem.

L B wrote:
@BHXSpector this is really the bug you couldn't solve? Simple logic oversight? I've made pong one too many times in various software and languages (even in Scheme) and that bug has always been a simple fix like Disch said :p

Yeah, like I said, I Googled the problem and found site after site that had the same problem, but not a single one that showed a fix. Most of the sites had the OP saying they were just going to leave it and move on. While I moved on, I still came back to find the solution so I could say it was bug free (at least til I add a new feature that puts in new bugs) after I finished other projects.

One programmer told me it was easy too, but then couldn't figure out how to fix it either so I figured it was some out of the way bug that was being missed.

Thanks again though.
Well, at least now you can finally call it bug free thanks to Disch's fix. :)
Yep, especially since the primitive code from the 4th is the pong code for the classic collection project I'm doing. I plan to have Pong, Breakout, Space Invaders, Space Wars (old Atari game I grew up playing), and a few others. Thinking about even tackling my mom's favorite Atari game Circus Atari. It came about again because I knew the pong clone had the bug again, but also got thinking that breakout is basically pong only flipping it with one paddle and a hand full of blocks so the bug would likely rear its head in that and needed it fixed. Now that it is fixed I can get back to the collection (Clones Collection is what I'm affectionately calling it right now).
great you got pong, now do pinball, BTW what ever happened to that chess tournament?
Topic archived. No new replies allowed.
Pages: 1... 678