Results 1 to 9 of 9

Thread: paddle/breakout game

  1. #1

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544

    paddle/breakout game

    Hi!

    I'm programming a Paddle/Breakout game in C++ and I have just gotten to the ball movement...
    When the ball hits the paddle,wall or a block how should the new angle be calculated??
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Usually if it hits the left or right wall, we just inverse the xspeed (xspeed = -xspeed), and if it hits the paddle or the top wall, we inverse the yspeed (yspeed = -yspeed). If you're using angles, you simply add 90 degrees to it each time it hits a wall.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    I was using this code, so I just wanted to check...do you know why it wont run....I suspect that its the if statement that is wrong...

    PHP Code:
    if(ball.> (SCREEN_WIDTH ball.width) )

    {
    xangle = -xangle;
    ball.xv xangle;
    ball.yv yangle;
    Move_BOB(&ball);
    }

    if(
    ball.<0)
    {
        
    xangle xangle;
        
    yangle yangle;
        
    ball.xv xangle;
        
    ball.yv yangle;
        
    Move_BOB(&ball);
    }
    if (
    ball.0)
    {
        
    xangle xangle;
        
    yangle yangle;
        
    ball.xv xangle;
        
    ball.yv yangle;
        
    Move_BOB(&ball);
    }

    if(
    ball.SCREEN_HEIGHT
    {
        
    xangle = -xangle;
        
    yangle = -yangle;
        
    ball.xv xangle;
        
    ball.yv yangle;
        
    Move_BOB(&ball);

    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I've fixed your code:
    PHP Code:
    if(ball.> (SCREEN_WIDTH ball.width) || ball.0)
    {
        
    ball.xv = -ball.xv;
        
    Move_BOB(&ball);
    }

    if(
    ball.> (SCREEN_HEIGHT ball.height) || ball.0
    {
        
    ball.yv = -ball.yv;
        
    Move_BOB(&ball);

    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    I figured that out while reading your reply
    thanks!
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  6. #6

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    When I start the game the ball goes in the same direction even if I hit the ball with the corner of the paddle.....how would I make it go steeper and broader depending on how I hit the ball.....i have been trying butt off to do it but it won't work...any suggestions??
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  7. #7

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Solved it guys!
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  8. #8
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Glad you solved it. What did you end up doing?
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  9. #9

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    I did the following, but it still doesn't work perfectly...when the ball hits the paddle on the far right the ball is smashed down instead of going up....

    PHP Code:
    //the ball has gone outside the screen
    if(ball.<= ball.>= SCREEN_WIDTH ball.width ){
        
    xangle = -xangle;
    }
    // the ball has gone outside the screen
    if(ball.<= |ball.== SCREEN_HEIGHT -ball.heightpaddle.height ){
        
    yangle = -yangle;
    }

    if(
    ball.SCREEN_HEIGHT){
        
    yangle = -yangle;
    }
    // the ball has hit the paddle
    if(Collision_BOBS(&ball,&paddle)){
        
    yangle=-yangle// change direction
            
        // This collision detection determine where the ball hit the paddle and 
        // calculate a new direction

            
    if(ball.>= paddle.&& paddle.<=19){
                if(
    xangle >0){
                
    xangle 2;
                }
                else if(
    xangle <0){
                    
    xangle = -2;
                }
            
            }
            
            if(
    ball.paddle.+19 && paddle.<=38){
                if(
    xangle 0){
                
    xangle 1;
                }
                else if(
    xangle <0){
                    
    xangle = -1;
                }
            }
            if(
    ball.>= paddle.+38 && paddle.<=57){
                if(
    xangle 0){
                
    xangle 0.5;
                }
                else if(
    xangle 0){
                    
    xangle = -0.5;
                }
            }

            if(
    ball.paddle.+57 && paddle.<=76){
                if(
    xangle 0){
                
    xangle = -0.5;
                }
                else if(
    xangle 0){
                    
    xangle 0.5;
                }

            }
            if(
    ball.paddle.+76 && paddle.<=95){
                if(
    xangle <0){
                
    xangle =-1;
                }
                else if(
    xangle >0){
                    
    xangle 1;
                }

            }
            if(
    ball.paddle.+95 && paddle.<=115){
                
    yangle = -yangle;
                if(
    xangle <0){
                
    xangle = -2;
                }
                else if(
    xangle >0){
                    
    xangle 2;
                }
            }




    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width