Sign in to follow this  
savail

where to create keyboard handling in game?

Recommended Posts

Hey
I was wondering how shall I handle keyboard in my game. What should be the function? Shall I do this in LRESULT CALLBACK WndProc function? I mean the main event function that needs to be created during window creating in Widnows api...BTW I have my code separated on a few files
Or shall I create separate function for keyboard events in game?

Share this post


Link to post
Share on other sites
Depends how complex your game is. I'd say ideally you'll want to get rid of the key events as soon as possible and replace them with more game specific events. Pick them up with the win proc thing, pass them into some kind of input manager (which makes mroe sense of them, key up/key down/key still down etc). From there you can either directly convert them into game events (jump pressed, fire pressed, etc - this lets you do configurable keys in an options menu) or you can pass them on (still as keys) to a game state. The game state can then convert them ass needed - that lets you have keys do different things in different stats; you can use arrow keys for movement in a game or to navigate menus on a menu screen etc.

Share this post


Link to post
Share on other sites
Aw well, my game is going to be a bit complex I guess. Im trying to clone Little fighter 2. Did you mean something like this?
[code]LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_KEYDOWN:
switch(wParam)
{
case VK_ESCAPE:
PostQuitMessage(0);
break;
}
default:
return DefWindowProc(hWnd, Message, wParam, lParam);
}
State(Message, wParam, lParam);
return 0;
}[/code]
where State is a function that handles operations, key pushes, combos etc in certain stages in game like Menu, versus mode, character selecting etc...
But this solution doesn't fit me a bit couse I have already written code in ceratin stages of game. Im drawing in this State function and I can't draw in Wnd proc thing right?
Or you meant to make for example this function State return a structure with Message, wParam and lParam and then collect these events and handle somewhere outside the wnd while loop?
Sorry for my bad english and please try to answer as easy as you can ^^ :P I will be very very grateful

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this