Sorry about that. Um, I think I understand your intention.
It sounds to me much like a game of pong or similar. Lord knows what I've done with my old code. I can't be bothered even think about the physics right now, but I've thrown together some code that will throw a red dot into a parabolic arc.
In such a path, we'll have to both be able to have small increments of movement, and be able to vary them. You just have to assign the ball's velocity and position in an appropriate way for your application.
Enjoy.
#include <windows.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
char szClassName[ ] = "CodeBlocksWindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (
0,
szClassName,
"Click to release a ball",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
544,
375,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
ShowWindow (hwnd, nCmdShow);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
float ballPosX, ballPosY, ballVelocityX, ballVelocityY;
const int myTimerId = 1;
const int intervalMs = 50;
VOID CALLBACK myTimerProc(HWND hwnd,
UINT message,
UINT idTimer,
DWORD dwTime)
{
ballPosX += ballVelocityX;
ballPosY += ballVelocityY;
ballVelocityY -= 0.1;
InvalidateRect(hwnd, NULL, true);
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_DESTROY:
KillTimer(hwnd, myTimerId);
PostQuitMessage (0);
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
SetPixel(hdc, ballPosX, ballPosY, RGB(250,0,0));
SetPixel(hdc, ballPosX, ballPosY+1, RGB(250,0,0));
SetPixel(hdc, ballPosX+1, ballPosY, RGB(250,0,0));
SetPixel(hdc, ballPosX+1, ballPosY+1, RGB(250,0,0));
EndPaint(hwnd, &ps);
break;
case WM_LBUTTONUP:
ballPosX=0;
ballPosY=0;
ballVelocityX=3.2;
ballVelocityY=8.1;
KillTimer(hwnd, myTimerId);
SetTimer(hwnd, myTimerId, intervalMs, myTimerProc);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
|