This site requires JavaScript, please enable it in your browser!
Greenfoot back
_kr_696
_kr_696 wrote ...

2020/2/3

Ping Pong Game

_kr_696 _kr_696

2020/2/3

#
Need help making boundaries in pong. I'm really new to coding.
RufusH123 RufusH123

2020/2/3

#
Hello, there are many ways of doing this but one of the ways that i think is just more straight forward is to use a1x2 + b1x + c1= 0 and a2x2 + b2x + c2 = 0 formulas to find out where there is a collision, then from there you can bounce the ball away from the boundary. I don't really know much on this subject myself so you can visit this website to see more about the line intersection formula
danpost danpost

2020/2/4

#
_kr_696 wrote...
Need help making boundaries in pong. I'm really new to coding.
A simple breakdown of pong ball boundary codes would be like:
if (isAtEdge())
{
    if (getX() == 0) player2scores(); // left edge
    else if (getX() == getWorld().getWidth()-1) player1scores(); // right edge
    else negateVerticalSpeed(); // top and bottom edges
}
You need to login to post a reply.