if (GetAsyncKeyState('W') & 0x8000)
{
g_tPlayer.x += fSpeed * cosf(g_fPlayerAngle);
g_tPlayer.y += fSpeed * sinf(g_fPlayerAngle);
}
if (GetAsyncKeyState('S') & 0x8000)
{
g_tPlayer.x -= fSpeed * cosf(g_fPlayerAngle);
g_tPlayer.y -= fSpeed * sinf(g_fPlayerAngle);
}
if (GetAsyncKeyState('A') & 0x8000)
{
g_fPlayerAngle -= PI * g_fDeltaTime * fTimeScale;
}
if (GetAsyncKeyState('D') & 0x8000)
{
g_fPlayerAngle += PI * g_fDeltaTime * fTimeScale;
}
위 코드는 A,D 키를 통해 각도를 설정하고 W,S키를 통해 각도대로 이동한다. g_fPlayerAngle에 각도를 저장하고
cos(각도)는 x좌표 , sin(각도)는 y좌표를 의미하기 때문에 각도대로 이동하기 위해 x에 cos(각도)만큼, y에 sin(각도)만큼 증감시킨다.
tBullet.tSphere.x = g_tGunPos.x + cosf(fAngle) * 25.f;
tBullet.tSphere.y = g_tGunPos.y + sinf(fAngle) * 25.f;
총알의 최초 위치를 설정하는 코드인데 cos(fAngle), sin(fAngle)에 25.f를 곱하면 g_tGunPos에서 fAngle각도로 25.f 만큼 떨어져 있는 곳에 최초 위치하게 된다.
'WinAPI' 카테고리의 다른 글
| [WinAPI] Pivot (0) | 2022.01.20 |
|---|---|
| [WinAPI] 더블 버퍼링 (0) | 2022.01.20 |
| [WinAPI] 델타 타임 (0) | 2022.01.16 |
| [WinAPI] PeekMessage와 윈도우 창 크기 설정 (0) | 2022.01.15 |
| [WinAPI] 도형 그리기, 마우스 좌표 (0) | 2022.01.15 |