Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

100 Neutral

About Claymz

  • Rank
  1. Claymz

    WM_KEYDOWN message pause

    Sorry, the problem was i forgot one line, right after case WM_KEYUP:there should have been switch(wParam), so it works now. Thanks for the help. And this second approach is much better when dealing with a large variety of keys, so thanks for that aswell!
  2. Claymz

    WM_KEYDOWN message pause

    Well, now ive got this: bool qDown, eDown = false; LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch( msg ) { case WM_KEYDOWN: switch(wParam) { case 'Q': qDown = true; break; case 'E': eDown = true; break; } return 0; case WM_KEYUP: { case 'Q': qDown = false; break; case 'E': eDown = false; break; } return 0; } return DefWindowProc(hWnd, msg, wParam, lParam); } while(msg.message != WM_QUIT) { if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { if(qDown) { //do sth } if(eDown) { //do sth } } Problem is, if i press 'E', itll act as if i wouldve hold it, even when i press 'Q' and then release it, it acts as if right after that i wouldve hold the 'E' key again.
  3. Claymz

    WM_KEYDOWN message pause

    And what would be the most simple solution to doing this (what function to use to get the information about certain key not pressed any more)?
  4. [color=#000000][font=verdana, arial, helvetica, sans-serif]Hi all![/font] [color=#000000][font=verdana, arial, helvetica, sans-serif]First of all, some additional info:[/font] [color=#000000][font=verdana, arial, helvetica, sans-serif]In the wParam parameter of WM_KEYDOWN message, first 15 bits have the following meaning:[/font] [color=#000000][font=verdana, arial, helvetica, sans-serif]"0-15 The repeat count for the current message. The value is the number of times the keystroke is autorepeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative."[/font] [color=#000000][font=verdana, arial, helvetica, sans-serif]So, what i want to do is, when i hold down a certain button on keyboard (or a mouse for that matter) when playing a game(for steering), i would like that this button would continuously be sending WM_KEYDOWN message, without the pause, which occurs after the first message - that is, if you hold down button, first message is sent, than for a second nothing happens, and after that, if your still holding down that same button, these type of messages are sent quick one after another. How to accomplish such a funcionality? If your not sure what i mean, you can open text editing program such as textbook and hold one specific character on the keyboard down, and you will see the short pause right after the first output of that same character, after that, it will be outputed constantly.[/font] [color=#000000][font=verdana, arial, helvetica, sans-serif]Thank you in advance![/font]
  5. Claymz

    C++ Win32 game

    Solved the velocity issue! Just needed to normalize the direction, after changing it.
  6. Claymz

    C++ Win32 game

    Hi all! Ive started making a game, similar to this one: http://www.newground...tal/view/409137, except im making it with Win32 and C++. Ive made the moving line with dots, that is, every frame a new dot is printed on screen, and because its fast, it seems like its a line. Is there any better way to do that? Also, when steering, if i hold down key 'Q' or 'E' (for left and right), how could i achieve so that there would be a max steering angle, so that if i hold one of these buttons, i would collide with my line, because now when i hold it down, i just keep getting in a more and more tight circle, like so: http://imageshack.us/photo/my-images/831/circleu.png/. Also, when using steering my velocity keeps getting lower, so im adding code for rotation aswell, if maybe something is wrong with it (im pretty sure this is also the cause of getting into smaller and smaller circle, as shown in the picture above): Rotation code: Vec2& Vec2::rotate(float t) { x = x * cosf(t) - y * sinf(t); //x represents the first component of the Vec2 direction(0.0f,-120.0f); y = y * cosf(t) + x * sinf(t); //y represents the second component of the Vec2 direction(0.0f,-120.0f); return *this; } Globals and window procedure: BackBuffer* gBackBuffer = 0; const int gClientWidth = (LONG)::GetSystemMetrics( SM_CXFULLSCREEN ); const int gClientHeight = (LONG)::GetSystemMetrics( SM_CYFULLSCREEN ); Vec2 player(500.0f,500.0f); Vec2 direction(0.0f,-120.0f); float angle = 0.0f; LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { HDC hdc = 0; switch( msg ) { case WM_CREATE: // Create the backbuffer. gBackBuffer = new BackBuffer(hWnd, gClientWidth,gClientHeight); return 0; case WM_KEYDOWN: switch(wParam) { case VK_ESCAPE: DestroyWindow(ghMainWnd); break; case 'Q': direction.rotate(-0.1f); break; case 'E': direction.rotate(0.1f); break; } return 0; case WM_DESTROY: delete gBackBuffer; PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, msg, wParam, lParam); } Message and game loop: MSG msg; ZeroMemory(&msg, sizeof(MSG)); // Get the performance timer frequency. __int64 cntsPerSec = 0; bool perfExists = QueryPerformanceFrequency((LARGE_INTEGER*)&cntsPerSec)!=0; if( !perfExists ) { MessageBox(0, "Performance timer does not exist!", 0, 0); return 0; } double timeScale = 1.0 / (double)cntsPerSec; // Get the current time. __int64 lastTime = 0; QueryPerformanceCounter((LARGE_INTEGER*)&lastTime); while(msg.message != WM_QUIT) { if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { // Get time __int64 currTime = 0; QueryPerformanceCounter((LARGE_INTEGER*)&currTime); double deltaTime = (double)(currTime - lastTime) * timeScale; // backbuffer DC HDC bbDC = gBackBuffer->getDC(); Vec2 velocity = direction*2.0f; player += deltaTime*velocity; // Paint the dot to be controlled HBRUSH oldBrush = (HBRUSH)SelectObject(bbDC, GetStockObject(BLACK_BRUSH)); Ellipse(bbDC, player.x-4, player.y-4, player.x+4, player.y+4); SelectObject(bbDC, oldBrush); gBackBuffer->present(); lastTime = currTime; } }
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!