Reputation: 1
I'm having a lot of trouble getting my controls to work for my game I have tried several different ways and nothing seems to work. This is what I have currently with two different layers in visual studio. 1st- part
class Moves
{
public bool rightKeyPressed { get; set; }
public bool leftKeyPressed { get; set; }
public Moves()
{
rightKeyPressed = false;
leftKeyPressed = false;
}
public void evaluateKey(Keys key, Boolean pressed)
{
if (key == Keys.Left)
leftKeyPressed = pressed;
else if (key == Keys.Right)
rightKeyPressed = pressed;
}
}
2nd part
private void frmMain_KeyUp(object sender, KeyEventArgs e)
{
if (playing)
{
if (input.leftKeyPressed)
GameField.moveCurrentShapeLeft();
if (input.rightKeyPressed)
GameField.moveCurrentShapeRight();
this.updateGameBoard();
}
input.evaluateKey(e.KeyCode, false);
}
private void frmMain_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space && playing)
input.evaluateKey(e.KeyCode, true); e.Handled = true;
}
Upvotes: 0
Views: 73
Reputation: 495
In your frmMain_KeyDown, you are only calling input.evaluateKey() if e.KeyCode == Keys.Space. You'll never handle a left or right key that way. Remove that clause from the if.
Upvotes: 1