I made a game named "Spaceship Invaders" in C#. For the ship movements, i wrote some code (at KeyDown
Form event) but, it not so efficient.
For example: If I press Left key and Up key, at the same time, and I keep pressing, the KeyDown event will take the first key pressed(it's impossible to press 2 keys at the same time).
switch (e.KeyCode)
{
case Keys.Left:
if(SHIP.Location.X - move_LEFT >= 0)
SHIP.Location = new Point(SHIP.Location.X - move_LEFT, SHIP.Location.Y);
if (using_mouse)
Cursor.Position = SHIP.Location;
break;
case Keys.Up:
if(SHIP.Location.Y - move_UP >= 0)
SHIP.Location = new Point(SHIP.Location.X, SHIP.Location.Y - move_UP);
if (using_mouse)
Cursor.Position = SHIP.Location;
break;
}
Where move_UP and move_Left are variables int.
protected int move_LEFT = 40;
protected int move_UP = 40;
How can i fix this?