Results 1 to 33 of 33

Thread: Chaning direction

  1. #1

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

    Chaning direction

    In my breakout game, I have a slight problem with the direction...
    When the ball comes towards the ball, lets say with f(x)=-2x, and the ball hits the paddle on the far most left side, I want the ball to go back in the same direction, but I have found that kinda tricky!
    Anyone know how to do this???
    I know it has something to do with inverse function....But how to express it, I dont know....
    Last edited by CyberCarsten; Oct 4th, 2003 at 05:12 AM.
    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
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Not sure exactly how you're doing the velocity of the ball, but to get it to bounce like that, just invert the horizontal element (multiply by -1).
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  3. #3

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    I do it like this:
    PHP Code:
    ball.xv 2;
    ball.yx = -6;
    Move_BOB(&ball); 
    I tried multiplying ball.xv by -1, but it didn't work....very tricky...
    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
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Could you post your move_bob code please?


    P.S. I take it ball.xv and ball.yv are the horizontal and vertical speeds of the ball respectivly.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  5. #5
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  6. #6

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Function prototype:
    PHP Code:
    int Move_BOB(BOB_PTR bob)
    {
    // this function moves the bob based on its current velocity
    // also, the function test for various motion attributes of the'
    // bob and takes the appropriate actions
       

    // is this a valid bob
    if (!bob)
       return(
    0);

    // translate the bob
    bob->x+=bob->xv;
    bob->y+=bob->yv;

    // test for wrap around
    if (bob->attr BOB_ATTR_WRAPAROUND)
       {
       
    // test x extents first
       
    if (bob->max_clip_x)
           
    bob->min_clip_x bob->width;
       else
       if (
    bob->min_clip_x-bob->width)
           
    bob->max_clip_x;
       
       
    // now y extents
       
    if (bob->max_clip_x)
           
    bob->min_clip_x bob->width;
       else
       if (
    bob->min_clip_x-bob->width)
           
    bob->max_clip_x;

       } 
    // end if
    else
    // test for bounce
    if (bob->attr BOB_ATTR_BOUNCE)
       {
       
    // test x extents first
       
    if ((bob->max_clip_x bob->width) || (bob->min_clip_x) )
           
    bob->xv = -bob->xv;

       
    // now y extents 
       
    if ((bob->max_clip_y bob->height) || (bob->min_clip_y) )
           
    bob->yv = -bob->yv;

       } 
    // end if

    // return success
    return(1);
    // end Move_BOB 
    P.S. I take it ball.xv and ball.yv are the horizontal and vertical speeds of the ball respectivly.
    Yes, they are
    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
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Is the problem that the ball is wrapping off the screen first? because this will happen if it's moving faster than its width.

    The problem may also be that the ball gets 'stuck' constantly changing it's direction, so solve this do seperate checks for the left and right edges using xv = abs(xv) and xv = -abs(xv) respectivly (assuming abs is a valid function that gets the modulus of it's parameter).




    Regarding bouncing off the players pad, check the x location of the ball, in relation to the middle of the pad, then if it's far-enough away (yet still hits the pad), then invert the x and y velocities of the ball).
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  8. #8

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Thank you for your reply
    It only bounces if the BOB (Blitter object) was created with BOB_ATTR_BOUNCE.
    &ball is not created with this parameter.....
    Where should I use the abs function??
    Last edited by CyberCarsten; Oct 4th, 2003 at 05:59 AM.
    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)

  9. #9
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Did you try changing the xv values using the abs function?

    What happens at the moment? Does the ball just continue off the edge of the screen?


    Assuming you understood what i've ment, i can't see how it wouldn't work unless there's something wrong somewhere else.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  10. #10

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    The bounce of the wall worked perfect from the beginning, also bouncing of blocks, its just when the ball hits the paddle on the far left and right side it should bounce back in the same direction that it came in with....
    I didn't quite understand where to put the abs function.....
    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)

  11. #11

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    This is the paddle code:
    PHP Code:
    // the ball has hit the paddle 
    if(Collision_BOBS(&ball,&paddle)){ 
        if(
    ball.== paddle.&& paddle.<=19) { // Hits paddle on far left
        
    xangle xangle *(-1);
        }
        
        if(
    ball.59 && paddle.<=74){ // Hits paddle on far right
        
    xangle xangle *(-1);
        }
    yangle = -yangle;

    Where I have set ball.xv and ball.yx to xangle and yangle respectivily.
    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)

  12. #12
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Try this:
    PHP Code:
    if(Collision_BOBS(&ball,&paddle)){  
        if(
    abs(ball.x-(paddle.x+paddle.width/2)) > (paddle.width/4)) { // Hits paddle on far left or the far right
            
    if(ball.x<(paddle.x+paddle.width/2) { //it hit the left
                
    xangle = -abs(xangle);
            }
            else { 
    //it hit the right
                
    xangle abs(xangle);
            }
        } 
        
    yangle = -abs(yangle); //assuming -ve velocity is up

    P.S. sorry for the late reply.
    Last edited by SLH; Oct 4th, 2003 at 06:41 AM.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  13. #13

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    No problem
    I'll try it now!
    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)

  14. #14

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Hi again
    It works when the ball hits the left side of the paddle, but when it hits the right side it either goes right trough the paddle or goes in the oppisite direction....
    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)

  15. #15
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Is the ball very wide (relative to it's velocity/the paddle?) if so then doing the following *may* fix it. If not then i'm not sure of the problem, because i'm pretty sure the code i gave should work.

    change ball.x to ball.x+ball.width/2
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  16. #16

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    The ball is 12 pixels wide....I tried the replacement, but that didn't work either.....
    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)

  17. #17
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Could you put a breakpoint in here:

    if(ball.x<(paddle.x+paddle.width/2) { //it hit the left

    and here:

    xangle = abs(xangle);

    then tell me whether the code gets to them both successfully when the ball should bounce of the right of the pad (the ball has to be in the far right quarter of the pad). I'm really stumpped here though.


    EDIT: changed the first breakpoint, i copyed the wrong one by mistake.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  18. #18

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    dont know how to do breakpoints......
    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)

  19. #19
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    In MS Visual C++ you move the cursor to the line of code, and press F9. Then run the project (F5 not ctrl-F5).


    If you want to upload your project i could have a look at it for you.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  20. #20

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Yes, i will upload it in about an hour...my pc is busy at the moment....
    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)

  21. #21
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Ok, i'll have a look at it when i have a moment.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  22. #22

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Thanks
    My girlfriend will soon be finished with my computer, so I can send it...
    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)

  23. #23

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Do you want the entire project with bitmaps, its about 12 mb, or just the source???
    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)

  24. #24
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    I'd need the bitmaps as well.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  25. #25

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Luckilly it wasn't 12 megs, counted the debug info in...
    So here it is:
    main.cpp -> main source file
    GPBUMB1-3.cpp/.h -> Game Engine

    Used DirectX SDK 6.1 - can't get it to compile with higher sdk version
    Needed to compile:
    ddraw.h
    dinput.h
    dsound.h

    ddraw.lib
    dinput.lib
    dsound.lib
    winmm.lib
    dxguid.lib
    Attached Files Attached Files
    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)

  26. #26

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Altough it can compile with a higher sdk version if direct input support is left out(has to be deleted from gpdum3.h/cpp)
    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)

  27. #27
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Ok, i've had a look at it but couldn't get it to compile. I've had a look at your code, and the only thing that *may* be the problem is with your Collision_BOBS code. I'm not too sure how it works, so it may be perfectly fine though.

    Here's code i'd use though.... (not syntactically tested)

    PHP Code:
    int Collision_BOBS(BOB_PTR bob1BOB_PTR bob2)
    {
    // are these a valid bobs
    if (!bob1 || !bob2)
       return(
    0);

    // test if rects overlap
    if (bob1-><= (bob2->x+bob2->width))
       if ((
    bob1->x+bob1->width) >= bob2->x)
          if (
    bob1-><= (bob2->y+bob2->height))
             if ((
    bob1->y+bob1->height) >= bob2->y)
                return(
    1);
    // if we got here then there's no collision
    return(0);

    // end Collision_BOBS 
    Sorry i can't be of more help. It would be useful if you could work out how to add breakpoints and tell me the results (as i can't because i can't compile the project).
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  28. #28

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Thank you for your reply and for looking at the code
    I'll try to do breakpoints today, and tell you what the outcome is.
    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)

  29. #29

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    I tried adding breakpoints to the code, but nothing happend...it just compiles and run....
    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)

  30. #30
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    How did you compile? You need to "Start Debug" (pressing F5 in MS Visual C++).

    I don't think a straight compile will stop at breakpoints. To test if the breakpoints are working just put one on a line you *know* will get excecuted.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  31. #31

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    yeah, I did that, but it just executed as usual....
    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)

  32. #32
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Sorry, but i have no idea what could be wrong. If your program doesn't stop at breakpoints then it's very hard to work out what's wrong with your code.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  33. #33

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    yeah ....damn it!
    But thank you for all of your help!
    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