我正在制作一个类似“太空侵略者”的简单游戏,但遇到了问题。我想让用户能够自由地从左到右移动,并同时可以使用“空格键”进行开火。
我的问题是:当我按下多个键时,只有一个功能运行。
以下是我尝试过的一些方案:
Storing the keys in a
List<Keys>
(but i didnt find any good way to excute the functions and everything become messy)2.normal handling of the key_down event like this:
protected void Form1_keysDown(object obj, KeyEventArgs e) { (e.KeyData == Keys.Space) spaceShip.FireBullets(); if (e.KeyCode == Keys.Left) spaceShip.MoveLeft(); if (e.KeyCode == Keys.Right) spaceShip.MoveRight(); }