I am learning DX9 and C++. I am making a pong game using Direct3D. I am trying to move the player paddle using the move_player variable in WMKEYDOWN and wParam==VKUP. I think I am having a scoping problem. Here is some of my code.
float move_player = 0.0f;
// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
case WM_KEYDOWN:
{
if (wParam == VK_UP)
{
move_player -= 50.0f;
break;
}
else if (wParam == VK_DOWN)
{
move_player++;
break;
}
break;
}
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
void init_graphics(void)
{
// create the vertices using the CUSTOMVERTEX struct
CUSTOMVERTEX vertices[] =
{
{ 0.0f, 250.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },
{ 30.0f, 250.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },
{ 0.0f, 350.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },
{ 30.0f, 350.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },
{ 770.0f, 250.0f + move_player, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
{ 800.0f, 250.0f + move_player, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
{ 770.0f, 350.0f + move_player, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
{ 800.0f, 350.0f + move_player, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
{ 390.0f, 290.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },
{ 410.0f, 290.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },
{ 390.0f, 310.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },
{ 410.0f, 310.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },
};
// create a vertex buffer interface called v_buffer
d3ddev->CreateVertexBuffer(12 * sizeof(CUSTOMVERTEX),
0,
CUSTOMFVF,
D3DPOOL_MANAGED,
&v_buffer,
NULL);
VOID* pVoid; // a void pointer
// lock v_buffer and load the vertices into it
v_buffer->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, vertices, sizeof(vertices));
v_buffer->Unlock();
}