I am trying to create breakout game like this below.
I like how when balls bounces on paddle you have control over where it is goings. i need help creating some thing like this

//this is my code for when ball touch the paddle(player). i have divide the paddle in to two pices. than i am check if ball is touching the paddle on left or right side. than i am checking to see which way the ball dir is. than move the ball different dir.
//bx,by,bw,bh are ball x,y postion, width, height.
//x,y, width, height are paddle variables

public void playerBallCollision(Ball b)
        double bx = b.getX();
        double by = b.getY();
        double bw = b.getRadius() * 2;
        double bh = b.getRadius() * 2;

            if(this.getBounds().intersects(b.getBounds()))  //ball is touching the paddle
                b.setDy(-b.getDy()); //change ball dy oppiste side 

                if(by+bh >= y && by <= y)  //ball is touching paddle from top
                    if(bx < (x+width/2))   //ball is touch paddle from left side
                        if(b.getDx() <= 0)      //ball is moving left 
                            b.setDx(b.getDx()); //move ball right
                        else                    //ball is moving right
                            b.setDx(-b.getDx()); //move ball left
                    if(bx > (x+width/2))  //ball is touching paddle from right side
                        if(b.getDx() <= 0)  //ball is moving left
                        else                   //ball is moving right
            }//End collision

so this code just move the ball left or right same angle. i want to make the different angles. so should i add more if statment? or just this be done in looop?

Edited by game06

5 Years
Discussion Span
Last Post by nandosss

yes you should add more decision making statements in order to make the ball go different direction. Also why dont you try to divide the pallet into more secions? it would give it more angles. Also you should change she speed of the ball depending on side of the pallet that is being hit.

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.