Html 5 ping pong game side collision problem

Posted by Gurjit on Game Development See other posts from Game Development or by Gurjit
Published on 2014-08-22T16:07:35Z Indexed on 2014/08/22 16:37 UTC
Read the original article Hit count: 314

Filed under:
|

I am making a simple ping pong game where I am facing a side collision problem means when the ball collides with the either side of the paddle . Although I have written code for making it works but something is failing....I want plz someone to give suggestions and tell how to avoid it.

Means while trying to hit the ball with side face of the paddle poses a problem.!!

Here is the main part of the code causing problem

function checkCollision(){

    ///// This is collision detection for the upper part /////
    if( cy + radius >= paddleTop && cx + radius > paddleLeft && cy + radius >= paddleTop + 5 && cx - radius <= paddleLeft + paddleWidth ) {
        dy = -dy;
        ++hits;  /// On collision we are increasing the Score
        playSound();
    }
    else if( cy + radius >= paddleTop && cy + radius <= paddleTop + paddleHeight && cx + radius >= paddleLeft && cy - radius <= paddleLeft - (radius + 1) ) {
            dx = -dx;
    }

}

here is working fiddle for it :- http://jsfiddle.net/gurjitmehta/orzpzf69/

© Game Development or respective owner

Related posts about JavaScript

Related posts about html5