Original Post
I'm currently working on my first game with genuine DirectX enabled graphics. My Tetris type game is coming along well, but I've encountered a problem that I can't seem to correct. Button presses appear to occur extremely fast. I use the space bar to rotate the falling shape, but when I press it, I get a whirling blur as it draws out every different rotation in succession until I let off the key. The same problem occurs when I press down, or left and right. It makes it difficult to line up the pieces correctly. Does anyone have a clue what I might be doing wrong?
Here are what I believe to be the most pertinent pieces of code:
[source]
...
#define KeyDown(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KeyUp(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
...
...
MSG msg;
while(TRUE){
DWORD start = GetTickCount();
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
if(msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
RenderFrame();
#pragma region Move Block
if(KeyDown(VK_SPACE) && !fall.Move(0, 0, 1))
;// Play beep type sound uh.. uh..
if(KeyDown(VK_RIGHT) && !fall.Move(0, 1, 0))
;// Play beep type sound uh.. uh..
if(KeyDown(VK_LEFT) && !fall.Move(0, -1, 0))
;// Play beep type sound uh.. uh..
if(KeyDown(VK_DOWN) && !fall.Move(1, 0, 0))
if(fall.SetPiece())
SendMessage(hWnd, WM_DESTROY, 0, 0);
#pragma endregion
if(KeyDown(VK_ESCAPE))
SendMessage(hWnd, WM_DESTROY, 0, 0);
while((start - GetTickCount()) < 25);
}
...
[/source]
Here are what I believe to be the most pertinent pieces of code:
[source]
...
#define KeyDown(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KeyUp(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
...
...
MSG msg;
while(TRUE){
DWORD start = GetTickCount();
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
if(msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
RenderFrame();
#pragma region Move Block
if(KeyDown(VK_SPACE) && !fall.Move(0, 0, 1))
;// Play beep type sound uh.. uh..
if(KeyDown(VK_RIGHT) && !fall.Move(0, 1, 0))
;// Play beep type sound uh.. uh..
if(KeyDown(VK_LEFT) && !fall.Move(0, -1, 0))
;// Play beep type sound uh.. uh..
if(KeyDown(VK_DOWN) && !fall.Move(1, 0, 0))
if(fall.SetPiece())
SendMessage(hWnd, WM_DESTROY, 0, 0);
#pragma endregion
if(KeyDown(VK_ESCAPE))
SendMessage(hWnd, WM_DESTROY, 0, 0);
while((start - GetTickCount()) < 25);
}
...
[/source]