M R Sriram
March 31st, 1999, 02:34 AM
Win 32 SDK
I am trying to write a small Bricks Program.
Here the bouncing ball is in a seperate thread while the primary
thread handles the paddle movements.
The basic BallProc is somewhat like this
DWORD WINAPI BallProc(LPVOID lpThreadParam)
{
HWND hwnd = (HWND)lpThreadParam;
RECT ClientRect;
POINT PrevBallPos;
HDC hdc;
hdc = GetDC(hwnd);
GetClientRect(hwnd,&ClientRect);
BallPos.x = ClientRect.right / 2;
BallPos.y = ClientRect.bottom / 2;
BallDir.x = 1;
BallDir.y = 1;
while(!ExitBallThread)
{
BitBlt(hdc,BallPos.x,BallPos.y,BallSize,BallSize,MemBallDC,0,0,SRCCOPY);
memcpy(&PrevBallPos,&BallPos,sizeof(POINT));
BallPos.x += BallDir.x;
BallPos.y += BallDir.y;
if(BallPos.y >= ClientRect.bottom - BallSize|| BallPos.y <= ClientRect.top)
BallDir.y = -BallDir.y;
if(BallPos.x >= ClientRect.right - BallSize|| BallPos.x <= ClientRect.left)
BallDir.x = -BallDir.x;
/* Problem here */
// Sleep(1);
PatBlt(hdc,PrevBallPos.x,PrevBallPos.y,BallSize,BallSize,WHITENESS);
}
ReleaseDC(hwnd,hdc);
ExitThread(0);
}
In the above code,if i do not give the Sleep,the ball movement is extremely
fast.However if i give Sleep(1) the ball slows down a lot it is very easy to
paddle it.I want to control the movement of the ball(ie i want the ball to move much faster than what i get with
Sleep(1) but not as fast as the one without Sleep(1)).
If anyone has got any ideas pl help me.
SriramMR
I am trying to write a small Bricks Program.
Here the bouncing ball is in a seperate thread while the primary
thread handles the paddle movements.
The basic BallProc is somewhat like this
DWORD WINAPI BallProc(LPVOID lpThreadParam)
{
HWND hwnd = (HWND)lpThreadParam;
RECT ClientRect;
POINT PrevBallPos;
HDC hdc;
hdc = GetDC(hwnd);
GetClientRect(hwnd,&ClientRect);
BallPos.x = ClientRect.right / 2;
BallPos.y = ClientRect.bottom / 2;
BallDir.x = 1;
BallDir.y = 1;
while(!ExitBallThread)
{
BitBlt(hdc,BallPos.x,BallPos.y,BallSize,BallSize,MemBallDC,0,0,SRCCOPY);
memcpy(&PrevBallPos,&BallPos,sizeof(POINT));
BallPos.x += BallDir.x;
BallPos.y += BallDir.y;
if(BallPos.y >= ClientRect.bottom - BallSize|| BallPos.y <= ClientRect.top)
BallDir.y = -BallDir.y;
if(BallPos.x >= ClientRect.right - BallSize|| BallPos.x <= ClientRect.left)
BallDir.x = -BallDir.x;
/* Problem here */
// Sleep(1);
PatBlt(hdc,PrevBallPos.x,PrevBallPos.y,BallSize,BallSize,WHITENESS);
}
ReleaseDC(hwnd,hdc);
ExitThread(0);
}
In the above code,if i do not give the Sleep,the ball movement is extremely
fast.However if i give Sleep(1) the ball slows down a lot it is very easy to
paddle it.I want to control the movement of the ball(ie i want the ball to move much faster than what i get with
Sleep(1) but not as fast as the one without Sleep(1)).
If anyone has got any ideas pl help me.
SriramMR