Advertisement

Pong and DirectX9

Started by May 24, 2023 01:33 AM
16 comments, last by Geri 1 year, 5 months ago

I am trying to move a pong paddle but I can't seem to get it to move.

float x = 0.0f, y = 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)
		{
			y--;
		}
		if (wParam == VK_DOWN)
		{
			y++;
		}
	}
	break;
	}
	return DefWindowProc(hWnd, message, wParam, lParam);
}

void init_graphics(void)
{
	// create the vertices using the CUSTOMVERTEX struct
	CUSTOMVERTEX vertices[] =
	{
		{ 0.0f, 250.0f+y, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },
		{ 25.0f, 250.0f+y, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },
		{ 0.0f, 350.0f+y, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },
		{ 25.0f, 350.0f+y, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },

		{ 775.0f, 250.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
		{ 800.0f, 250.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
		{ 775.0f, 350.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
		{ 800.0f, 350.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },

		{ 395.0f, 295.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },
		{ 405.0f, 295.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },
		{ 395.0f, 305.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },
		{ 405.0f, 305.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(255, 255, 255), },
	};
  

How did you make Breakout without having a moving paddle?

https://www.gamedev.net/forums/topic/640150-finshed-breakout-game/5042282/?page=1

ED: Nevermind, that used a different input system. But still, you've used DX9 several times with input. I just can't be arsed to search…

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

Advertisement

y++ moves 1 pixel for every key-press? If so, maybe hit the key several hundred times for visible movement?

well I tried but it still does not work

Where are you calling init_graphics? Looks like, based on the name, that you're initializing your vertices once with the initial x/y values of 0.0f. When you're updating the x/y values, via the WM_KEYDOWN event, are you updating the vertices again? If not, then it's still initialized with the initial x/y values and not the updated values, so nothing is going to change visually.

how does one update x/y vertices using wm_

AtomicWinter said:
When you're updating the x/y values, via the WM_KEYDOWN event, are you updating the vertices again?

keydown

Advertisement

You should look at matrices, more specifically transforms. See the following: https://learn.microsoft.com/en-us/windows/win32/direct3d9/transforms

I took a class in linear algebra in 2018 but I dont know how to apply to transforms to my code.

pbivens67 said:
I took a class in linear algebra in 2018 but I dont know how to apply to transforms to my code.

I don't know why you would make that statement instead of just going ahead and learning it.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

well, I read the article, but I am unsure of how to work it into my code.

This topic is closed to new replies.

Advertisement