在C#游戏中按下更多键

时间:2015-07-03 15:06:18

标签: c#

我创造了一个名为" Spaceship Invaders"在C#中。对于船舶运动,我写了一些代码(在KeyDown Form事件中),但效率不高。

例如:如果我同时按下向左键和向上键,并且我一直按下,KeyDown事件将按下第一个键(同时按下2个键是不可能的) 。

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;
}

其中move_UP和move_Left是变量int。

protected int move_LEFT = 40;
protected int move_UP = 40;

我该如何解决这个问题?

0 个答案:

没有答案