How do I move two graphic paddles(pong) at the same time using one keyboard in C#?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • endorfinState
    New Member
    • Apr 2013
    • 8

    How do I move two graphic paddles(pong) at the same time using one keyboard in C#?

    Code:
            protected override void OnKeyDown(KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Up) 
                    paddleY = paddleY - 15;
                else if (e.KeyCode == Keys.Down)
                    paddleY = paddleY + 15;
                else if (e.KeyCode == Keys.W) 
                    paddleY2 = paddleY2 - 15;
                else if (e.KeyCode == Keys.S)
                    paddleY2 = paddleY2 + 15;
               
                Invalidate();
                base.OnKeyDown(e);
            }
  • AceInfinity
    New Member
    • Apr 2013
    • 12

    #2
    Make Keys.Up, Keys.Down AND Keys.W, Keys.S their own if statements. Right now this is just one big if statement, and only one condition can be ran at a time, so how do you expect more than one paddle to move here?

    It should be... if Keys.Up {} else if Keys.Down {}, and then if Keys.W {} else if Keys.S {}.

    Comment

    Working...