Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 DirectInput Problems...
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Krisc
Knave

69 Posts

Posted - May 30 2004 :  10:46:14 AM  Show Profile  Visit Krisc's Homepage  Send Krisc an AOL message  Click to see Krisc's MSN Messenger address  Reply with Quote
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.

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


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.

Edited by - Krisc on May 30 2004 10:51:56 AM

sdw
Warrior

USA
160 Posts

Posted - May 30 2004 :  11:18:41 AM  Show Profile  Visit sdw's Homepage  Click to see sdw's MSN Messenger address  Reply with Quote
Looks to me that it's your conditional statements. Looks like the check for movement is in the If statements and the check for firing is in an Else If statement. And you're right, it's kinda hard to see without tabs but I tried to tab them in myself with notepad. See if this will work:

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


Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.14 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.