我正在尝试查找将 Xbox 360 编码到我的项目中的示例或教程。到目前为止,我只使用 SDL_keysym 使用箭头键和 WASD 键来移动我的精灵。想知道我如何集成 Xbox 360(最好)或操纵杆支持。
以下是我目前使用箭头和 WASD 键移动我的 sprite Spaceship1 的代码。请原谅我,因为代码杂乱无章。
struct oSprite
{
int m_nTotalFrames;
int m_nCurrentFrame;
int m_nFrameWidth;
int m_nFrameHeight;
fVector2 m_vPosition;
SDL_Surface* m_pImage;
bool m_bIsHuman;
oControls m_oControls;
oControls m_oAltControls;
};
bool Update()
{
fVector2 vKeyPresses;
Uint8* paunKeyStates = SDL_GetKeyState(NULL);
float fMoveSpeed = 0.5f;
if(paunKeyStates[g_Spaceship1.m_oControls.m_nUpButton] || paunKeyStates[g_Spaceship1.m_oAltControls.m_nUpButton])
{
vKeyPresses.y -= fMoveSpeed;
}
if(paunKeyStates[g_Spaceship1.m_oControls.m_nDownButton] || paunKeyStates[g_Spaceship1.m_oAltControls.m_nDownButton])
{
vKeyPresses.y += fMoveSpeed;
}
if(paunKeyStates[g_Spaceship1.m_oControls.m_nLeftButton] || paunKeyStates[g_Spaceship1.m_oAltControls.m_nLeftButton])
{
vKeyPresses.x -= fMoveSpeed;
}
if(paunKeyStates[g_Spaceship1.m_oControls.m_nRightButton] || paunKeyStates[g_Spaceship1.m_oAltControls.m_nRightButton])
{
vKeyPresses.x += fMoveSpeed;
}
}