2 Quick VC++/DirectX Questions

Discussion in 'OT Technology' started by RanciD, Oct 26, 2003.

  1. RanciD

    RanciD New Member

    Joined:
    Jul 10, 2002
    Messages:
    2,271
    Likes Received:
    0
    Location:
    Boston
    Hey, I'm working on a big (for me at least) C++ project for my seminar class. It's a pretty simple game made in DirectX with Visual C++ (I'm using VC++ .NET 2002). Number one is my biggest problem, I may be able to find the answer to my second question in my book if I look harder.

    1. In my game you control using the arrow keys to move around around the screen. It works fine if you keep tapping the arrow key to move, but if you hold down one direction, say the right arrow, you'll move right once then it'll pause a second before it starts to move right until you let go. I need to get rid of that pause. It's extremely annoying. Right now my code to move the character is rather simple:

    Code:
    //HandleKeys()
    void CEngine::HandleKeys(WPARAM wParam)
    {
    	switch (wParam) {
    		case VK_UP: HandleUpArrow(); break;
    		case VK_DOWN: HandleDownArrow(); break;
    		case VK_LEFT: HandleLeftArrow(); break;
    		case VK_RIGHT: HandleRightArrow(); break;
    		case VK_ESCAPE: PostQuitMessage(WM_QUIT); break;
    	}
    }
    
    //HandleUpArrow()
    void CEngine::HandleUpArrow()
    {
    	m_Player.SetY(m_Player.GetY()-MOVEMENT);
    }
    That's from the program. It simply calls a function to handle movement in whatever direction depending on the key pressed, and the function alters the x or y value to move the character. Is there anyway to just disable the delay, or will I have to trick it somehow like checking to see if it's the first press in a direction and make it do something special? I really have no idea but something like that is sure to hurt my grade on this project. Any help with this would be appreciated!

    2. How do you get rid of the mouse cursor so it won't sit there being annoying in my full screen game?

    Thanks a lot to anyone willing to help!
     
  2. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    hmm, i remember running into a wall with this problem before in my directX class. You can check out my senior project here: http://sourceforge.net/projects/spt405/ and look through the code. I would look through it for you, but I'm kinda pressed for time as of late :)
     
  3. RanciD

    RanciD New Member

    Joined:
    Jul 10, 2002
    Messages:
    2,271
    Likes Received:
    0
    Location:
    Boston
    Thanks, I'll look through there. I have another question now..

    Is there a way to make it so I can handle diagonal movement and such that would use two keys down at the same time? Like up arrow and right arrow at the same time? Would it be like

    Code:
    if (VK_UP && VK_RIGHT)
    or something like that? I really have no idea.

    Thanks to anyone who can help. This question isn't needed but it'd certainly make my program a lot better.
     
  4. RanciD

    RanciD New Member

    Joined:
    Jul 10, 2002
    Messages:
    2,271
    Likes Received:
    0
    Location:
    Boston
    heeelp!
     
  5. panzerfaust

    panzerfaust New Member

    Joined:
    Oct 13, 2003
    Messages:
    1,604
    Likes Received:
    0
    Location:
    Far far away
    if you attach the whole project i may be able to help you
     
  6. panzerfaust

    panzerfaust New Member

    Joined:
    Oct 13, 2003
    Messages:
    1,604
    Likes Received:
    0
    Location:
    Far far away
    essentially the callback function DefWindowProc takes care of the events so what you want to do is write your own handler for example in your:
    int WINAPI WinMain(HINSTANCE hinstance,
    HINSTANCE hprevinstance,
    LPSTR lpcmdline,
    int ncmdshow)

    you can specify

    WNDCLASSEX winclass;
    winclass.lpfnWndProc = WindowProc;
    //yadi yadi yada

    where WindowProc is your event handler
    now write it:

    LRESULT CALLBACK WindowProc(HWND hwnd,
    UINT msg,
    WPARAM wparam,
    LPARAM lparam)

    and trap the events you like:

    switch(msg)
    {
    case WM_KEYDOWN:
    case whatever:
    default:

    }

    finally you want to take care of the rest of the events that we skipped so

    return (DefWindowProc(hwnd, msg, wparam, lparam));


    you could also try doing this without having to specify an event handler, ie:

    #define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
    #define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
     
  7. panzerfaust

    panzerfaust New Member

    Joined:
    Oct 13, 2003
    Messages:
    1,604
    Likes Received:
    0
    Location:
    Far far away

Share This Page