Results 1 to 8 of 8

Thread: xangle <> 0

  1. #1

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

    xangle <> 0

    Hi!
    How do I prevent my xangle variable from equaling 0.....

    Here is some of my code:

    PHP Code:
    int Game_Main(void *parms)
    {

    // check of user is trying to exit
    if (KEY_DOWN(VK_ESCAPE))
        
    PostMessage(main_window_handleWM_DESTROY,0,0);
    // Move paddle left
    if (KEY_DOWN(VK_LEFT)) {
        
    lkpress true;
        if (
    paddle.>5) {
            
    paddle.paddle.-4;
            
    Move_BOB(&paddle);
        }
    } else if(
    KEY_DOWN(VK_RIGHT)) {        // Move paddle right
        
    rkpress true;
        if(
    paddle.paddle.width  SCREEN_WIDTH) {
            
    paddle.paddle.+4;
            
    Move_BOB(&paddle);
            
        }
    }

    // start the timing clock
    Start_Clock();

    // clear the drawing surface
    DD_Fill_Surface(lpddsback0);

    Draw_BOB(&paddle,lpddsback);
    Draw_BOB(&ball,lpddsback);
    for (
    int draw 0draw<28draw++)
    Draw_BOB(&box[draw],lpddsback);

    ball.xv xangle;
    ball.yv yangle;
    Move_BOB(&ball);

    //the ball is going outside the screen
    if(ball.<= 0) {
        
    lasthit LAST_HIT_LEFT;
        
    xangle = -xangle;
    }
    if( 
    ball.>= SCREEN_WIDTH ball.width ){
        
    lasthit LAST_HIT_RIGHT;
        
    xangle = -xangle;
    }

    // the ball is going outside the screen
    if(ball.<= 0) {
        
    lasthit LAST_HIT_TOP;
        
            
    yangle = -yangle;
        
        if(
    xangle <0){
            
    xangle xangle;
        }
        if(
    xangle 0){
            
    xangle = -xangle;
        }
    }

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

        
    if(ball.== paddle.&& ball.== paddle.height){
            if(
    lkpress){
                if(
    xangle 0){
                    
    xangle = -3.5;
                    
    lkpress =false;
                }
                else if(
    xangle <0){
                    
    xangle 3.5;
                    
    lkpress false;
                }
            }
        }
            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){
                
                if(
    xangle <0){
                
    xangle = -2;
                }
                else if(
    xangle >0){
                    
    xangle 2;
                }
            }
            
            if(
    ball.== paddle.paddle.width  && ball.== paddle.height){
            if(
    rkpress){
                if(
    xangle 0){
                    
    xangle = -3.5;
                    
    rkpress false;
                }
                else if(
    xangle >0){
                    
    xangle 3.5;
                    
    rkpress false;
                }
            }
        }
            

    }






    // flip the surfaces
    DD_Flip();


    // sync to 10ish fps
    Wait_Clock(10);

    // Perform collision detection with the blocks
    for(counter 0counter<28counter++)
    if(
    Collision_BOBS(&ball,&box[counter])){
        if(
    xangle 0){
            
    xangle xangle;
            
            
        }
        if(
    xangle 0){
            
    xangle = -xangle;
            
        }
        if(
    xangle ==0){
            if(
    lasthit == LAST_HIT_LEFT){
                
    xangle=+rand()%2;
            }
            if(
    lasthit == LAST_HIT_RIGHT){
                
    xangle=-rand()%-2;
            }
        }

        if(
    yangle 0){
            
    yangle = -yangle;
        }
        if(
    yangle 0){
            
    yangle yangle;
        }
    }
        
    // return success
    return(1);

    // end Game_Main 
    Last edited by CyberCarsten; Nov 13th, 2002 at 04:19 PM.
    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
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    if(xangle ==0){
    if(lasthit == LAST_HIT_LEFT){
    xangle=+rand()%2;
    }
    if(lasthit == LAST_HIT_RIGHT){
    xangle=-rand()%-2;
    }
    }
    I don't know what your program does, but this doesn't prevent it...
    yangle = yangle
    things like this doesn't do anything either...
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    xangle=-rand()%-2
    Now this really confuses me. What sense does it make to calculate modulo a negative number?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Addicted Member HairyDave's Avatar
    Join Date
    Aug 2002
    Location
    Er...I can't remember.
    Posts
    196
    I take it that if xangle == 0 - you want to change it to be non-zero..?

    If this is the case you need to not use the rand() functions - it could return you zero - which would put you in the same situation. You're getting something like rand() % 2 - which could give you 0 or 1 (I think thats how mod works in C).

    As kedaman says - the xangle = xangle etc lines could just be omitted - it's unnecessary.

    Other than that - theres too much code for me to wade through to find anything else - and I should be working . (Sorry, but it's true).

    HD

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    (I think thats how mod works in C).
    Not only in C but everywhere. Modulo is a basic algebraic operation. It means "do an integer division and return the remainder". Which can be anything from 0 to divisor-1.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    Addicted Member HairyDave's Avatar
    Join Date
    Aug 2002
    Location
    Er...I can't remember.
    Posts
    196
    Unfortunately while the theory is true - implementations of mod can vary (or so I was told by my Cryptography lecturer at University a couple of years ago).

    Apparently while the modulo theory says 0 - (n-1), the implementations of it can mean 1 - n.

    Newer languages have a consistent implementation, but some systems differ.

    If this is wrong I would be happy to go back to university to complain to the lecturer )

    HD

  7. #7
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Originally posted by HairyDave
    Apparently while the modulo theory says 0 - (n-1), the implementations of it can mean 1 - n.
    This is dead wrong, and makes no sense. It essentially says that for any division, you cannot have a remainder of 0, but you can have a remainder of n, which, of course is incorrect. If there are implementations of that operation that behave like that... well, its just wrong.

    Z.

  8. #8
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    Code:
    if(xangle > 0){
            xangle = -xangle;
            if(xangle< 0)
                 xangle=0;
    }
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

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