Krisc | Hey, I have been working on my game and ran into a road block... My DirectInput works, but it is erroneous...the problem is when I move my ship left (Key.LeftArrow) and then fire the weapon (Key.SpaceBar) the ship decides to stop all together and the weapon fires. I was wondering how I make DirectInput work in a way so that I can hit many keys at once and have them all register and make it so the ship moves and fires the weapon at the same time. Here is the code for detecting key hits...if you would like to see my DirectInput class just ask and I'll put it up...Thanks!
By the way, I know the code is in C# but it is very simple to read...
myInput is my DirectInput class and
myInput.checkKey(Key k) just returns a true if k is pressed and false if it isn't.
[code]
private void checkKeys()
{
if(myInput.InputCount <= 0)
{
if(bMenu)
{
if(myInput.checkKey(DI.Key.Escape))
{
bMenu = !bMenu;
myInput.InputCount = 50;
}
else if(myInput.checkKey(DI.Key.Pause))
app.Dispose();
}
else
{
if(myInput.checkKey(DI.Key.LeftArrow))
myPlayer.MoveLeft();
else if(myInput.checkKey(DI.Key.RightArrow))
myPlayer.MoveRight();
else if(myInput.checkKey(DI.Key.UpArrow))
myPlayer.MoveUp();
else if(myInput.checkKey(DI.Key.DownArrow))
myPlayer.MoveDown();
else if(myInput.checkKey(DI.Key.Escape))
{
bMenu = !bMenu;
myInput.InputCount = 50;
}
else if(myInput.checkKey(DI.Key.Pause))
app.Dispose();
else
myPlayer.ReturnToCenter();
if(myInput.checkKey(DI.Key.Space))
{
//tW.Fire(512,500);
myPlayer.Fire();
myInput.InputCount = 50;
}
}
}
}
[/code]
Again much thanks if you can help my fix this.
EDIT: Hmm...the code tag doesn't recognize tabs. I am sorry for that. Ok, well basically what InputCount does is it makes sure that there are pauses before certain key presses, so the weapon doesn't fire off all 10 rounds in a second for instance. Well I made a separate counter for the weapon and it was fixed...but I still think the way I am going about getting input is wrong. Any advice or insight would be greatly appreciated! Thanks. |