PDA

View Full Version : Bit of help, much appreciated




Maleficum
Mar 9, 2007, 12:36 AM
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.
~
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


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());

}


//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:



slooksterPSV
Mar 13, 2007, 04:20 PM
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.