看了七十一雾央的博客后深有感触,决定学习一下,跟着操作,写下自己的心得。
初体验。
2015/06/14/
///by xbw
编译器 visual studio 2013 MFC应用程序
看了一下别人的意见,于是我添加了边界限制,不用多说,直接上代码,需要说明一下,
windows窗口以左上角为坐标原点,向下为y轴正方向,向右为x轴正方向;;
void CChildView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
switch (nChar)
{
case 'd': //游戏中按下的键当然应该不区分大小写了
case 'D':
if (m_heroPos.right <= 600)
{
m_heroPos.left += 10; //向右移动10个像素的单位
m_heroPos.right += 10;
} //左边和右边都要移动哦
break;
case 'a':
case 'A':
if (m_heroPos.left >= 0)
{
m_heroPos.left -= 10;
m_heroPos.right -= 10;
}
break;
case 'w':
case 'W':
if (m_heroPos.top >= 0)
{
m_heroPos.top -= 10;
m_heroPos.bottom -= 10;
}
break;
case 's':
case 'S':
if (m_heroPos.bottom <= 450)
{
m_heroPos.top += 10;
m_heroPos.bottom += 10;
}
break;
}
}