im making a two player game in c# Windows Forms Application and i encountered a very weird problem: Im using timers for character movement - player 1 using arrows and player 2 using WSAD .I enable timers on keydown and disable them on keyup, and the problem is when player 1 using Down and left ( diagonal - South West) and player 2 using D ( trying to move right ), player 2 cant move right and he is stuck on this place, and player 1 is moving successfully. it does not happen with any other combo of keys - only when holding Left, Down and D together. I dont think there is anything wrong with my code, but:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (!dohef)
{
if (e.KeyCode == Keys.Up)
timer1.Start();
if (e.KeyCode == Keys.Down)
timer2.Start();
if (e.KeyCode == Keys.Right)
timer3.Start();
if (e.KeyCode == Keys.Left)
timer4.Start();
if (e.KeyCode == Keys.W)
timer5.Start();
if (e.KeyCode == Keys.S)
timer6.Start();
if (e.KeyCode == Keys.D)
timer7.Start();
if (e.KeyCode == Keys.A)
timer8.Start();
}
}
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
if (!dohef)
{
if (e.KeyCode == Keys.Up)
timer1.Stop();
if (e.KeyCode == Keys.Down)
timer2.Stop();
if (e.KeyCode == Keys.Right)
timer3.Stop();
if (e.KeyCode == Keys.Left) // yahol leavi 3
timer4.Stop();
if (e.KeyCode == Keys.W)
timer5.Stop();
if (e.KeyCode == Keys.S)
timer6.Stop();
if (e.KeyCode == Keys.D) // yahol leavi 3
timer7.Stop();
if (e.KeyCode == Keys.A)
timer8.Stop();
}
}
if u look at the code, there is nothing wrong with what i did so tell me if i have to also paste the code of the timers, i didnt do it because it is very long and complicated. BTW the boolean dohef has nothing to do with that, if he was True, so player 1 could not move diagonally, but he can - only player 2 cant move when i make this key combo. Thanks in advance :)