HPEN pen;
HBRUSH brush;
HBRUSH bulletBrush;
POINT playerPos = { 400, 400 };
POINT playerSize = { 50, 50 };
POINT bulletPos = {};
POINT bulletSize = { 10, 10 };
bool shot = false;
POINT playerDirection = {};
POINT bulletDirection = {};
int playerSpeed = 10;
int bulletSpeed = 30;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
{
pen = CreatePen(PS_SOLID, 10, RGB(255, 0, 255));
brush = CreateSolidBrush(RGB(255, 100, 100));
bulletBrush = CreateSolidBrush(RGB(0, 0, 0));
SetTimer(hWnd, 0, 100, nullptr);
}
break;
case WM_TIMER:
{
bulletPos.x += bulletDirection.x * bulletSpeed;
bulletPos.y += bulletDirection.y * bulletSpeed;
bulletPos.x += bulletDirection.x * bulletSpeed;
bulletPos.y += bulletDirection.y * bulletSpeed;
InvalidateRect(hWnd, nullptr, true);
}
break;
case WM_COMMAND:
{
int wmId = LOWORD(wParam);
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
SelectObject(hdc, pen);
SelectObject(hdc, brush);
int left = playerPos.x - (playerSize.x >> 1);
int right = playerPos.x + (playerSize.x >> 1);
int top = playerPos.y - (playerSize.y >> 1);
int bottom = playerPos.y + (playerSize.y >> 1);
Rectangle(hdc, left, top, right, bottom);
if (shot == true)
{
SelectObject(hdc, bulletBrush);
int bulletLeft = bulletPos.x - (bulletSize.x >> 1);
int bulletRight = bulletPos.x + (bulletSize.x >> 1);
int bulletTop = bulletPos.y - (bulletSize.y >> 1);
int bulletBottom = bulletPos.y + (bulletSize.y >> 1);
Ellipse(hdc, bulletLeft, bulletTop, bulletRight, bulletBottom);
}
EndPaint(hWnd, &ps);
}
break;
case WM_KEYDOWN:
{
switch (wParam)
{
case VK_UP:
playerDirection = { 0, -1 };
playerPos.y -= playerSpeed;
break;
case VK_DOWN:
playerDirection = { 0, +1 };
playerPos.y += playerSpeed;
break;
case VK_RIGHT:
playerDirection = { +1, 0 };
playerPos.x += playerSpeed;
break;
case VK_LEFT:
playerDirection = { -1, 0 };
playerPos.x -= playerSpeed;
break;
case ' ':
{
bulletPos = { playerPos.x, playerPos.y };
if (playerDirection.x == 0 && playerDirection.y == 0)
{
bulletDirection = { 1, 0 };
}
else
{
bulletDirection = { playerDirection.x, playerDirection.y };
}
shot = true;
}
default:
break;
}
InvalidateRect(hWnd, nullptr, true);
}
break;
case WM_DESTROY:
DeleteObject(pen);
DeleteObject(brush);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
진짜 읽기 싫다
코드 전문을 올릴거면 적어도 주석이랑 정확히 무슨 기능인지는 적어서 올리도록 하자^^
미안 나도 받은 거라서.....
gpt에 물어봐
이게 이렇게 되어 있어서 원인인줄 알았는데 확인해보니 아니고, 그래서 저게 원인일꺼 같아서 로그 찍어봤는데 아니더라... 도대체 원인이 뭘까? 이런식으로 뭔가 해보고 물어보는것도 아니고 그냥 뇌대리 맡기면 누가 해줌 ㅋㅋ
총알을 쓰고 다시 쏜다는게 무슨 말임 좀 더 풀어주셈
뭐가 사라짐?
대충 봐서는 문제 안생길거 같은데 뭐가 사라지는건데 총알이 사라지냐 플레이어가 사라지냐
한글도 못하고 코딩도 못하면 대체 뭐하는거임?
정말 멋진 코드에요