主题:一个关于KEYDOWN消息的问题
我做了一个关于"撑30秒就是男人的游戏",但是在用KEYDOWN消息响应的时候,移动会很迟钝,核心代码在下面,请大家帮一帮我,谢谢!
核心代码:
void CYuanView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
switch(nChar)
{
case VK_UP:
c=1;
break;
case VK_RIGHT:
d=1;
break;
case VK_DOWN:
e=1;
break;
case VK_LEFT:
f=1;
break;
}
if(c==1&&d==0&&e==0&&f==0)x=1;
if(c==1&&d==1&&e==0&&f==0)x=2;
if(c==0&&d==1&&e==0&&f==0)x=3;
if(c==0&&d==1&&e==1&&f==0)x=4;
if(c==0&&d==0&&e==1&&f==0)x=5;
if(c==0&&d==0&&e==1&&f==1)x=6;
if(c==0&&d==0&&e==0&&f==1)x=7;
if(c==1&&d==0&&e==0&&f==1)x=8;
switch(x)
{
case 1:
m_pt.y=m_pt.y-10;
break;
case 2:
m_pt.y=m_pt.y-10;
m_pt.x=m_pt.x+10;
break;
case 3:
m_pt.x=m_pt.x+10;
break;
case 4:
m_pt.y=m_pt.y+10;
m_pt.x=m_pt.x+10;
break;
case 5:
m_pt.y=m_pt.y+10;
break;
case 6:
m_pt.y=m_pt.y+10;
m_pt.x=m_pt.x-10;
break;
case 7:
m_pt.x=m_pt.x-10;
break;
case 8:
m_pt.y=m_pt.y-10;
m_pt.x=m_pt.x-10;
break;
}
Invalidate();
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CYuanView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
switch(nChar)
{
case VK_UP:
c=0;
break;
case VK_RIGHT:
d=0;
break;
case VK_DOWN:
e=0;
break;
case VK_LEFT:
f=0;
break;
}
CView::OnKeyUp(nChar, nRepCnt, nFlags);
}
核心代码:
void CYuanView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
switch(nChar)
{
case VK_UP:
c=1;
break;
case VK_RIGHT:
d=1;
break;
case VK_DOWN:
e=1;
break;
case VK_LEFT:
f=1;
break;
}
if(c==1&&d==0&&e==0&&f==0)x=1;
if(c==1&&d==1&&e==0&&f==0)x=2;
if(c==0&&d==1&&e==0&&f==0)x=3;
if(c==0&&d==1&&e==1&&f==0)x=4;
if(c==0&&d==0&&e==1&&f==0)x=5;
if(c==0&&d==0&&e==1&&f==1)x=6;
if(c==0&&d==0&&e==0&&f==1)x=7;
if(c==1&&d==0&&e==0&&f==1)x=8;
switch(x)
{
case 1:
m_pt.y=m_pt.y-10;
break;
case 2:
m_pt.y=m_pt.y-10;
m_pt.x=m_pt.x+10;
break;
case 3:
m_pt.x=m_pt.x+10;
break;
case 4:
m_pt.y=m_pt.y+10;
m_pt.x=m_pt.x+10;
break;
case 5:
m_pt.y=m_pt.y+10;
break;
case 6:
m_pt.y=m_pt.y+10;
m_pt.x=m_pt.x-10;
break;
case 7:
m_pt.x=m_pt.x-10;
break;
case 8:
m_pt.y=m_pt.y-10;
m_pt.x=m_pt.x-10;
break;
}
Invalidate();
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CYuanView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
switch(nChar)
{
case VK_UP:
c=0;
break;
case VK_RIGHT:
d=0;
break;
case VK_DOWN:
e=0;
break;
case VK_LEFT:
f=0;
break;
}
CView::OnKeyUp(nChar, nRepCnt, nFlags);
}