0

i am trying to make a breakout game where you have a paddle and ball bounces around breaking bricks.
the problem is that if ball touches the corner of player(cyan paddle). than it goes inside of player. i could not understand why. only thing it might be bc of all the dx, -dx, dy, -dy's. i am doing this so it would change ball postion. so it looks like it bounces of the player or window.

here i am check collision between ball and window. x,y,dx,dy are ball postion and speed.

public void BallWCollision()
{
    if(x <= 0){   //if ball goes right of screen 
      dx = -dx;
    }
   else if(x >= Main.WINDOW_WIDTH){  //if ball goes left of screen
    dx = -dx;
}

   if(y <= 0){    //if ball goes top of screen
     dy = -dy;
   }
   else if(y >= Main.WINDOW_HEIGHT){  //if ball goes bottom of screen
     dy = -dy;
    }
}

here i am check collision between player and ball. if ball touches playeer than change ball dy.

public void playerBallCollision(Ball b)
{
    if(player.getBounds().intersects(b.getBounds())){  //if player and ball touch each other
     b.setDy(-b.getDy());
    }
}

5d2560c01df7baef31079685ee42901f

Edited by game06

2
Contributors
1
Reply
21
Views
4 Years
Discussion Span
Last Post by JamesCherrill
0

How big are dx and dy? If, for example they ate 10, then your ball could be 9 or 10 pixels inside the player in just one clock interval.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.