1
\$\begingroup\$

I am teaching myself XNA and only started a few days ago. I am making a clone of Pong and have made a class for the Paddle:PaddleClass1

PaddleClass2

I am wondering how I can create 2 paddles one for each player from the one class.

Thanks,

TeaBelliedTitch

\$\endgroup\$
1
\$\begingroup\$

You need to create two different instances of the class.
I suggest you not to check for input inside your class but in your game loop, so you can handle events for both instances. Pseudocode below:

Pong::Paddle player1(texture1, bounds1);
Pong::Paddle player2(texture2, bounds2);

while(running){
  if(keyDown == W)
    player1.setYDirection(-1);
  else if(keyDown == UP)
    player2.setDirection(-1);
  else if(keyDown == S)
    player1.setYDirection(1);
  else if(keyDown == DOWN)
    player2.setDirection(1);

  player1.update();
  player2.update();
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.