Bit of help, much appreciated

Discussion in 'Mac Programming' started by Maleficum, Mar 8, 2007.

  1. macrumors member

    Joined:
    Jun 29, 2006
    Location:
    In a Chair
    #1
    Okay... I am now working on a simple game of Pong. Everything is going well - the paddling, the ball moving across the screen to the other paddle - but I can not get "score" to work... I have tried a "for" loop, but when I do, the window shows up, but so does a big list of exceptions.
    ~
    Code:
     public void paint(Graphics window)
       {
             
    		ball.moveAndDraw(window);  //move the ball and redraw it
           leftPaddle.moveDownAndDraw(window);
           leftPaddle.moveUpAndDraw(window);
           rightPaddle.moveUpAndDraw(window); 
            rightPaddle.moveDownAndDraw(window);
             int score = 0; 
            int score2 = 0; 
         
    		//see if ball hits left wall or right wall
    		
    	
    		 if ( ball.getX() > 550)
    	      {
    	        ball.setXSpeed(-ball.getXSpeed());
    			ball.setYSpeed(-ball.getYSpeed());
    			
                  score = score + 1; 
    	          
    	       
    	       } 
    		  if(ball.getX()<10)
            { 
                  
             ball.setXSpeed(-ball.getXSpeed());
    			ball.setYSpeed(-ball.getYSpeed());
    	          
                score2 = score2 +1; 
    	         
    	       
             
    			
        } 
    
        
        
        
        
        
    		//see if ball hits top wall or bottom wall
          if ((ball.getY()>450) || (ball.getY()<50))
    		{
    			ball.setYSpeed(-ball.getYSpeed());
    		}
    	
         
    		//see if ball hits left paddle
          
          
             [B]if(didCollideLeft())
              { 
                   
               ball.setYSpeed(-ball.getYSpeed()); 
               ball.setXSpeed(-ball.getXSpeed());
               
               } 
               
               
               
              
    		//see if Ball hits right paddle
    		
            if(didCollideRight())
            { 
                ball.setYSpeed(-ball.getYSpeed()); 
               ball.setXSpeed(-ball.getXSpeed());
               
            }[/B]
          
            
    		//see if the paddles need to be moved
    The highlighted part is where I think the part that controls the score needs to go. All I'm needing is a simple score drawString command that will give each paddle a point after... well, you know how Pong works :p.

    Any ASAP help is greatly appreciated. Thanks SOOOOOO much. :) :apple:
     
  2. macrumors 68030

    slooksterPSV

    Joined:
    Apr 17, 2004
    Location:
    Nowheresville
    #2
    Are you using SDL, Allegro, or another API? This in C++ I assume. I just need to know what API you're using and if its a custom view (if Cocoa) or what. That would help out the most.
     

Share This Page