ページ 11

キーの入力を反転するようなもの

Posted: 2014年12月26日(金) 17:17
by Rittai_3D

コード:

// 下位4ビットは移動キーに割り当てる。

const Button	BUTTON_UP    = 0x00001;
const Button	BUTTON_LEFT  = 0x00002;
const Button	BUTTON_DOWN  = 0x00004;
const Button	BUTTON_RIGHT = 0x00008;

const Button	BUTTON_SHOT = 0x00010;
const Button	BUTTON_BOMB = 0x00020;
const Button	BUTTON_SLOW = 0x00040;

コード:

typedef unsigned int Button;
Button GetTurnedKeyState()
{
	auto dirKey = m_InputState & 0x0f;
	auto tmp = ( dirKey & 0x03 ) << 2;
	auto turnedDirKey = ( dirKey >> 2 ) | tmp;

	return turnedDirKey;
}

コード:

void sampleFunc( bool turn )
{
	if( turn ) {
		auto anotherKey = m_InputState - ( m_InputState & 0x0f );
		m_InputState = GetTurnedKeyState() | anotherKey;
	}
}
BUTTON_~はゲーム内でのキーとして使う。理想の仮想キーコード。
sampleFunc()の anotherKey は方向キー以外のキー入力。